akhauriyash/Code-Regression huggingface dataset:
from itertools import product


def main():
    """
    2^20 = 1,048,576
    q = 200
    200,000,000
    limit 5s ???????????????OK
    """
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())
    M = map(int, input().split())

    dp(n, A, q, M)


def combination(n, A, q, M):
    for m in M:
        if m == 0 or solve(m, A, n):
            print("yes")
        else:
            print("no")


def dp(n, A, q, M):
    M_max = 2000
    _dp = [False] * (M_max + 1)
    for a in A:
        # ?°??????????????????????????????¨????????????????????±?????????(a???2????¶?????????¨?????????)
        for i in range(M_max, 0, -1):
            if _dp[i] and i + a <= M_max:
                _dp[i + a] = True
        # ???????¨????????????¨????????°?????¨????¨±????????????????????¨??§
        _dp[a] = True

    for m in M:
        if _dp[m]:
            print("yes")
        else:
            print("no")


def solve(m, A, n):
    # for b in f1(n):
    for b in product([0, 1], repeat=n):
        s = sum(a * bit for a, bit in zip(A, b))
        if m == s:
            return True

    return False


def f1(n):
    for i in range(2 ** n):
        # 0/1???n??????????????????bit????????¨
        # 0b ?????????
        bit = bin(i)[2:]
        yield map(int, bit.zfill(n))

if __name__ == '__main__':
    main()

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

int main() {
	char c;
	cin >> c;
	c++;
	cout << c << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	LLi a, b, c, d, ma=-llimax;
	cin>> a >> b >> c >> d;

	ma=max(ma, a*c);
	ma=max(ma, a*d);
	ma=max(ma, b*c);
	ma=max(ma, b*d);

	cout<< ma <<endl;
 
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    string str;
    cin >> str;
    for(int i = 0; i < str.size(); i++)
    {
       int tem = str[i];
       tem += n;
       if(tem >90) {tem = tem % 91 + 65;}
       char ch = tem;
       cout << ch ;
    }
    cout << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n){
		int sum=0;
		rep(i,600/n)sum+=n*n*n*i*i;
		cout<<sum<<endl;
	}
}

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

char win(char t){
  if(t=='r')return 'p';
  if(t=='s')return 'r';
  if(t=='p')return 's';
  return 'a';
}

int main(){
  int n,k;
  std::cin >> n>>k;
  int r,s,p;
  std::cin >> r>>s>>p;
  string t;
  std::cin >> t;

  std::vector<char> d(n);

  ll mins=min(min(r,s),p);

  rep(i,n){
    if(i-k>=0){
      if(d[i-k]!=win(t[i]))d[i]=win(t[i]);
      else d[i]='a';
    }
    else{
      d[i]=win(t[i]);
    }
  }

  ll ans=0;
  rep(i,n){
    if(d[i]=='r')ans+=r;
    else if(d[i]=='s')ans+=s;
    else if(d[i]=='p')ans+=p;
  }

  std::cout << ans << '\n';


  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const db PI = acos(-1);

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	db a, b, h, m;
	cin >> a >> b >> h >> m;
	db ang = (h + m / 60.0) * 30 - 6 * m;
	db rad = (ang / 180.0) * PI;
	cout << setprecision(20) << sqrtl(a * a + b * b - 2 * a * b * cos(rad));
}


Measured memory_bytes: 4184
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	long a,b,d,r;
	double f;
	cin>>a>>b;
	d=a/b;
	r=a%b;
	f=(double)a/b;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
using namespace std;
bool palin(string s){
  bool P{true};
  for(size_t i=0;i<=s.length()/2;i++)
    if(s[i]!=s[s.length()-i-1])
		P=false;
  return P;
}
int main(){
  string S{};
  cin>>S;
  if(palin(S) && palin(S.substr(0,S.length()/2)) && palin(S.substr(S.length()/2+1,S.length()/2)))
	cout<<"Yes";
  else
    cout<<"No";
  return 0;  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int isPrime(LL p){
        if(p<=1) return 0;
        if(p==2 || p==3 || p==5 || p==7) return 1;
        if(p==4 || p==6 || p==8 || p==9) return 0;

        LL i;
        int ret = 1;
        for(i=2; i*i<=p; i++){
                if(p%i==0 && i!=p){
                        ret = 0;
                        break;
                }
        }
        return ret;
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long X;

	cin >> X;

	long long ans = X;
	while(true){
		if(isPrime(ans) == 1){
			break;
		}
		ans++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int X = int.Parse(str[0]);
		int Y = int.Parse(str[1]);
		string ans = "No";
		for(var i=0;i<=100;i++){
			for(var j=0;j<=100;j++){
				if(i+j==X && i*2+j*4==Y){
					ans = "Yes";
				}
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 17904
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	long long  n, d; cin >> n >> d;
	long long  ans = 0;

	for (long long  i = 1; i <= n; i++) {
		long long  x, y; cin >> x >> y;
		if (x * x + y * y <= d * d) ans++;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main()
{
    int H, W; cin >> H >> W;
    int N; cin >> N;

    vector<int> a(N);
    vector<vector<int>> map(H, vector<int>(W));

    REP(i, N) cin >> a[i];

    int h = 0;
    int w = 0;
    bool right = true;

    REP(i, N)
    {
        int color = i + 1;

        REP(j, a[i])
        {
            map[h][w] = color;

            if( right )
            {
                if( w == W - 1 )
                {
                    h++;
                    right = false;
                }
                else
                {
                    w++;
                }
            }
            else
            {
                if( w == 0 )
                {
                    h++;
                    right = true;
                }
                else
                {
                    w--;
                }
            }
        }
    }

    REP(i, H)
    {
        REP(j, W)
        {
            cout << map[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
H,W=map(int,input().split(" "))

A=[]
for i in range(H):
    a=list(map(int,input().split(" ")))
    A.append(a)

O=[]
for i in range(H):
    for j in range(W):
        if A[i][j]%2!=0:
            A[i][j]-=1
            if j!=W-1:
                ai=i
                aj=j+1
            elif i!=H-1:
                ai=i+1
                aj=j
            else:
                break
            A[ai][aj]+=1
            O.append("{} {} {} {}".format(i+1,j+1,ai+1,aj+1))
        
print(len(O))
for i in range(len(O)):
    print(O[i])

Measured memory_bytes: 16408
import Data.List (sort)

main :: IO ()
main = do
  a <- read <$> getLine :: IO Double
  b <- read <$> getLine :: IO Double
  c <- read <$> getLine :: IO Double
  d <- read <$> getLine :: IO Double
  e <- read <$> getLine :: IO Double
  let
    ts = sort . map (\i -> let c = 10 * ceiling (i / 10) in (ceiling i - c, c)) $ [a, b, c, d, e]
  print $ fst (head ts) + sum (map snd ts)


Measured memory_bytes: 508
#include <stdio.h>

int main(void)
{
  int n,x,t,ans;
  scanf("%d %d %d",&n,&x,&t);
  
  if(n % x == 0)
    ans = t * (n / x);
  else
    ans = t * (n / x + 1);
  
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1692
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let sum = a.iter().cloned().sum::<i64>();

    let mut ans = i64::max_value();
    let mut left = 0;

    for i in 0..n - 1 {
        left += a[i];
        let right = sum - left;
        ans = std::cmp::min(ans, (left - right).abs());
    }

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


Measured memory_bytes: 6396
#include <iostream>                                             
#include <string>                                               
using namespace std;                                            
                                                                
int main(void) {                                                
  int a;                                                        
  string s, p;                                                  
  cin >> s >> p;                                                
  s += s;                                                       
  a = s.find(p);                                                
  if (a==-1) {                                                  
    cout << "No" << endl;                                       
  } else {                                                      
    cout << "Yes" << endl;                                      
  }                                                             
  return 0;                                                     
}                                                               
                                 

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;;

int dp[1<<21];
int a[21][21];
int bitcnt[1<<21];
int main(){
    int n;
    cin >> n;
    for (int i = 0; i<n;i++)
        for(int j = 0;j < n; j++)
            cin >> a[i][j];
    
    dp[0] = 1;
    for(int s = 1;s < (1<<n);s++){
        bitcnt[s] = bitcnt[s/2] + s%2;
        for(int l = 0;l<n;l++){
            if ((s >> l) % 2 == 0)continue;
            dp[s] += dp[s-(1<<l)]*a[bitcnt[s]-1][l];
            dp[s] %= MOD;

        }

    }
    cout << dp[(1<<n)-1] << endl;
    

    return 0;
}

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

int main(){
  string S;ll K,ans,l=1;
  cin >> S >> K;
  vector<pair<char,ll>> v;
  for(ll i=0;i<S.length();i++){
    if (i==0)continue;
     if(S[i] == S[i-1]) l++;
     else{
       v.push_back(make_pair(S[i-1],l));
       l=1;
     }
    if (i==S.length()-1) v.push_back(make_pair(S[i],l));
  }
  if (S.length() == 1)v.push_back(make_pair(S[0],1));
  
  ans = 0;
  
  if (v.size() == 1) ans=v[0].second * K / 2;
   else{
    for(ll i=1;i<v.size()-1;i++){
      ans+=v[i].second/2 * K;
    }
     if (v[v.size()-1].first == v[0].first){
       ans +=(v[0].second + v[v.size()-1].second)/2 * (K-1);  
    	ans += v[v.size()-1].second/2;
       ans += v[0].second/2;
     }else{
      ans += v[v.size()-1].second/2 * K;
       ans += v[0].second/2 * K;
     }
   }
 
  cout << ans << endl;
  
}

Measured memory_bytes: 256
package main

import (
   "bufio"
   "fmt"
   "os"
   "sort"
)

func solution(n int, a []int) int {
   sort.Ints(a)
   out := 0
   for i := n; i < 3*n; i += 2 {
        out += a[i]
   }
   return out
}

func main() {
   r := bufio.NewReader(os.Stdin)
   var n int
   fmt.Fscan(r, &n)
   a := make([]int, 3*n)
   for i := range a {
        fmt.Fscan(r, &a[i])
   }
   fmt.Println(solution(n, a))
}

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

int main() {
    int n;
    cin >> n;
    if (n <= 9) cout << n << endl;
    else if (n <= 99) cout << 9 << endl;
    else if (n <= 999) cout << 9 + (n-99) << endl;
    else if (n <= 9999) cout << 9 + 900 << endl;
    else if (n <= 99999) cout << 9 + 900 + (n-9999) << endl;
    else if (n == 100000) cout << 9 + 90900 << endl;
    return 0;
}

Measured memory_bytes: 256
#解説解答
n,a = map(int,input().split())
x = list(map(int,input().split()))
dp0 = [[0 for s in range(n*a+1)] for k in range(n+1)]
dp0[0][0] = 1
dp = dp0
for j in range(n):
  now = []
  for k in range(n+1):
    add = []
    for s in range(n*a+1):
      t = s-x[j]
      if t >= 0 and k >= 1:
        add.append( dp[k][s] + dp[k-1][t] )
      else:
        add.append( dp[k][s] )
    now.append(add)
  dp = now
ans = 0
for k in range(1,n+1):
  ans += dp[k][k*a]
print(ans)

Measured memory_bytes: 94940
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){


	int n;
	cin >> n;

	vector<vector<int>> x(n),y(n);
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
		int b,c;
		rep(j,a[i]){
			cin >> b >> c;
			b--;
			x[i].push_back(b);
			y[i].push_back(c);
		}
	}
	int maxi = 0;
	for(int bit = 0;bit < (1<<(n));bit++){
		int f = 1;
		rep(i,n){
			if(!(bit&(1<<i)))continue;
			rep(j,a[i]){
				if(y[i][j] == 0 && (bit&(1<<x[i][j])))f = 0;
				if(y[i][j] == 1 && !(bit&(1<<x[i][j])))f = 0;
			}
		}
		if(f){
			int cnt = 0;
			rep(i,n)if(bit&(1<<(i)))cnt++;
			chmax(maxi,cnt);
		}
	}
	cout << maxi << endl;




	


	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://abc147.contest.atcoder.jp/tasks/abc147_c

Measured memory_bytes: 3620
H, W, N = map(int, input().split())
h, w = map(int, input().split())
S = input()
T = input()

h -= 1
w -= 1
for i in range(N):
    if S[i] == "L":
        if w-1 < W-w-1:
            w -= 1
    elif S[i] == "R":
        if w > W-w-2:
            w += 1
    elif S[i] == "U":
        if h-1 < H-h-1:
            h -= 1
    elif S[i] == "D":
        if h > H-h-2:
            h += 1
    if w == 0 or h == 0 or h == H or w == W:
        print("NO")
        break

    if T[i] == "L":
        if w-1 > W-w-1:
            w -= 1
    elif T[i] == "R":
        if w < W-w-2:
            w += 1
    elif T[i] == "U":
        if h-1 > H-h-1:
            h -= 1
    elif T[i] == "D":
        if h < H-h-2:
            h += 1
else:
    print("YES")


Measured memory_bytes: 9736
#include <stdio.h>
#include <string.h>
int main(void){
  char s[11];
  scanf("%s\n",s );
  bool flag = true;
  int counter = 0;
  if(s[0] != 'A'){
    flag = false;
  }
  for (size_t i = 2; i < strlen(s)-1; i++) {
    if (s[i] == 'C') {
      break;
    }else if(i == strlen(s)-2){
      flag = false;
    }
  }
  for (size_t i = 0; i < strlen(s); i++) {
    if('A'<=s[i]&&s[i]<='Z'){
      counter++;
    }
  }
  if (counter > 2) {
    flag = false;
  }
  if (flag) {
    puts("AC");
  }else{
    puts("WA");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7


int main(){
    ll k, a, b;
    cin >> k >> a >> b;
    ll inc = b - a;
    ll ans = 0;
    ll step = 0;
    if(inc > 2){
        ans = a;
        ll res = floor((k-a+1) / 2.0);
        ans += inc * res;
        ans = ((k-a+1)%2) ? ans + 1 : ans;
    }else{
        ans = k + 1;
    }
    print(ans);
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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


  ll a, b;
  cin >> n >> a >> b;

  if (a + b > n) ans = a + b - n;
  cout << min(a, b) << " " << ans << endl;




  return 0;
}

Measured memory_bytes: 256
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, lint b) {
	if (!b)return T(1);
	if (b & 1)return mypow(a, b - 1) * a;
	T memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
#line 2 "main.cpp"
int main(){
	int k;
	std::cin>>k;
	lint sum=0;
	rep(i,k+10){
		sum+=modpow(10,i,k)*7%k;
		sum%=k;
		if(sum==0){
			std::cout<<i+1<<std::endl;
			return 0;
		}
	}
	puts("-1");
	return 0;
}

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

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
    int x;
	cin >> x;
	cout << int(pow(x, 3)) << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



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

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

}

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

using namespace std;

int main (void) {
  int N;
  cin >> N;
  while ( N >= 0 ) {
    if ( N % 4 == 0 ) {
      cout << "Yes" << endl;
      return 0;
    }
    N -= 7;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::*;
use std::cmp::max;
use std::collections::BinaryHeap;

#[fastout]
fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };

    let mut score = 0;
    let mut lasts = [-1; 26];
    let mut t = vec![26; d];
    let depth = 20;
    for i in 0..d {
        let mut max_score = -10000000;
        for j in 0..26 {
            let tmp = search(i, j, &c, &s, &mut lasts, depth, d, 0, 6);
            if tmp > max_score {
                max_score = tmp;
                t[i] = j;
            }
        }
        score += max_score;
        lasts[t[i]] = i as i64;
    }

    for &a in &t {
        println!("{}", a + 1);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}

fn search(
    i: usize,
    t: usize,
    c: &Vec<i64>,
    s: &Vec<Vec<i64>>,
    lasts: &mut [i64; 26],
    depth: usize,
    d: usize,
    cscore: i64,
    l: usize,
) -> i64 {
    if depth == 0 || i == d - 1 {
        return calc_score(i, t, &c, &s, lasts) + cscore;
    }

    let l = max(1, l - 1);
    let mut max_score = -1000000;
    let tmp_last = lasts[t];
    lasts[t] = i as i64;
    let tmp_score = calc_score(i, t, &c, &s, lasts);
    let mut cands = BinaryHeap::new();
    for j in 0..26 {
        let tmp_score = calc_score(i + 1, j, &c, &s, lasts);
        cands.push((tmp_score, j));
    }
    let w = if l > 1 { 2 } else { 1 };
    for &(_, j) in cands.iter().take(w) {
        let tmp = search(i + 1, j, &c, &s, lasts, depth - 1, d, cscore + tmp_score, l);

        if tmp > max_score {
            max_score = tmp;
        }
    }

    lasts[t] = tmp_last;
    max_score + cscore
}


Measured memory_bytes: 2344
MAX = 1000000
MOD = 1000000007

fac = [None] * MAX
finv = [None] * MAX
inv = [None] * MAX


def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def comb(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


comb_init()
x, y = [int(x) for x in input().split()]


def solve(x, y):

    if (x + y) % 3 != 0:
        return 0

    n = (2 * y - x) // 3
    m = (2 * x - y) // 3
    if n < 0 or m < 0:
        return 0

    return comb(n + m, n)


print(solve(x, y))

Measured memory_bytes: 121764
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &L[i], &R[i]);
  }
  int l = 1;
  int r = N;
  for (int i = 0; i < M; i++) {
    l = max(l, L[i]);
    r = min(r, R[i]);
  }
  printf("%d\n", (r >= l ? r - l + 1 : 0));
}


Measured memory_bytes: 1024
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

PII p[200020];
PII ans[200010];
signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, m) cin >> p[i].first >> p[i].second;
  sort(p, p+m);
  REP(i, n) ans[i] = {i, i};
  REP(i, m) {
    int y=p[i].second;
    chmin(ans[y].first, ans[y-1].first);
    chmax(ans[y-1].second, ans[y].second);
  }
  REP(i, n) {
    cout << ans[i].second-ans[i].first+1;
    if(i != n-1) cout << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 7784
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m), n | m)
	{
		int k[200], x[200][16], d[200][16];
		for (int i = 0; i < n; ++i)
		{
			scanf("%d", k + i);
			for (int j = 0; j < k[i]; ++j)
				scanf("%d%d", &x[i][j], &d[i][j]);
		}

		const int INF = 1 << 29;
		static int dp[200][16][100];	// row, column, jump left
		for (int i = 0; i < 200; ++i)
			for (int j = 0; j < 16; ++j)
				for (int a = 0; a < 100; ++a)
					dp[i][j][a] = INF;
		for (int i = 0; i < 2; ++i)
			for (int j = 0; j < 16; ++j)
				dp[i][j][m - i] = 0;

		for (int i = 0; i < n - 1; ++i)
		{
			for (int j = 0; j < k[i]; ++j)
			{
				for (int a = 0; a <= m; ++a)
				{
					if (dp[i][j][a] == INF)
						continue;

					for (int b = 0; b < k[i + 1]; ++b)
					{
						min_swap(dp[i + 1][b][a]
						, dp[i][j][a] + (d[i][j] + d[i + 1][b]) * abs(x[i][j] - x[i + 1][b]));
					}
					if (i + 2 < n && a > 0)
					{
						for (int b = 0; b < k[i + 2]; ++b)
						{
							min_swap(dp[i + 2][b][a - 1],
								dp[i][j][a] + (d[i][j] + d[i + 2][b]) * abs(x[i][j] - x[i + 2][b]));
						}
					}
				}
			}
		}
		int res = INF;
		for (int i = n - 2; i < n; ++i)
			for (int j = 0; j < k[i]; ++j)
				for (int a = 0; a <= m; ++a)
					if (i == n - 1 || a > 0)
						min_swap(res, dp[i][j][a]);
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int q, l[100000], r[100000], prime[200001]; //0:not素数 1:素数
    vector<int> like2017;

    prime[1] = 0;
    for (int i = 2; i <= 200000; i++)
        prime[i] = 1;

    for (int i = 2; i <= sqrt(200000); i++)
        if (prime[i] == 1)
            for (int j = i * 2; j <= 200000; j += i)
                prime[j] = 0;

    for (int i = 2; i <= 100001; i++)
        if (prime[i] == 1 && i * 2 - 1 <= 200000 && prime[i * 2 - 1] == 1)
            like2017.push_back(i * 2 - 1);

    //for (int i = 0; i < like2017.size(); i++)
    //  cout << like2017[i] << endl;

    cin >> q;

    for (int i = 0; i < q; i++)
        cin >> l[i] >> r[i];

    for (int i = 0; i < q; i++)
    {
        int j = 0;
        int ans = 0;

        while (like2017[j] < l[i])
            j++;

        while (like2017[j] <= r[i])
            j++, ans++;

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <utility>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    vector< pair<int, int> > x;
    vector< pair<int, int> > y;
    REP(i, n) {
        int x_, y_, a;
        cin >> x_ >> y_ >> a;

        switch (a) {
            case 1:
                x.push_back(pair<int, int>(x_, -1));
                break;
            case 2:
                x.push_back(pair<int, int>(x_, 1));
                break;
            case 3:
                y.push_back(pair<int, int>(y_, -1));
                break;
            case 4:
                y.push_back(pair<int, int>(y_, 1));
                break;
        }
    }

    int mx = 0, Mx = w;
    FOR(i, x) {
        if (i->second == -1) mx = max(mx, i->first);
        else Mx = min(Mx, i->first);
    }
    int my = 0, My = h;
    FOR(i, y) {
        if (i->second == -1) my = max(my, i->first);
        else My = min(My, i->first);
    }
    if (Mx-mx <= 0 || My-my <= 0) cout << 0 << endl;
    else cout << (Mx-mx)*(My-my) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = sc.nextInt();
    int K = sc.nextInt();
    int h;
    int counter = 0;
    for (int i = 0; i < N; i++) {
      h = sc.nextInt();
      if (h >= K) {
        counter++;
      }
    }
    System.out.println(counter);
  }
}


Measured memory_bytes: 47940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const ll mod = 1e9 + 7;

void solve()
{
    int n;
    cin >> n;
    int activity[n][3];
    for (int i = 0; i < n; i++)
    {
        cin >> activity[i][0] >> activity[i][1] >> activity[i][2];
    }
    ll happiness[n][3] = {0};
    happiness[0][0] = activity[0][0];
    happiness[0][1] = activity[0][1];
    happiness[0][2] = activity[0][2];
    for (int i = 1; i < n; i++)
    {
        happiness[i][0]=activity[i][0]+max(happiness[i-1][2],happiness[i-1][1]);
        happiness[i][1]=activity[i][1]+max(happiness[i-1][2],happiness[i-1][0]);
        happiness[i][2]=activity[i][2]+max(happiness[i-1][1],happiness[i-1][0]);
    }
    cout<<max({happiness[n-1][0],happiness[n-1][1],happiness[n-1][2]})<<endl;
}

int main()
{

    solve();

    return 0;
}

Measured memory_bytes: 7060
X = int(input())
r = int(X ** 0.5)
ans = 0
for i in range(1, r + 1):
    a = 0
    for j in range(1, 11):
        if i ** j <= X:
            a = i ** j
        else:
            break
    ans = max(ans, a)
print(ans)

Measured memory_bytes: 3060
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,x,m = list(map(int, input().split()))
v = x
seen = [0]*m
c = 0
val = 0
count = 0
tmp = 0
if n>m:
    while True:
        if seen[v]==2:
            break
        if seen[v]==1:
            count += 1
            tmp += v
        else:
            val += v
            c += 1
        seen[v] += 1
        v = (v**2)%m
    ans = val + ((n-c)//count) * tmp
    for i in range((n-c)%(count)):
        ans += v
        v = (v**2)%m
else:
    ans = 0
    v = x
    for i in range(n):
        ans += v
        v = (v**2)%m
print(ans)

Measured memory_bytes: 68768
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

LL solve(LL x) {
	if (x <= 6) return 1;
	if (x <= 11) return 2;
	LL takes = x / 11;
	if (takes * 11 >= x) return takes * 2;
	if (takes * 11 + 6 >= x) return takes * 2 + 1;
	return takes * 2 + 2;
}

int main()
{
	LL x;
	scanf("%lld", &x);

	printf("%lld\n", solve(x));

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) x.begin(),x.end()
#define DEBUG

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

    int ans = 0;
    rep(i, s.size())
    {
        if(s[i] == s[i+1])
        {
            s[i+1] = (char)((!(int)(s[i+1] - '0')) + '0');
            ++ans;
        }
    }

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

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    int n, m;
    scanf("%d %d",&n ,&m);
    int a[m];
    int b[n];
    int i, j, k=0;
    int flag;
    int ans;
    for(i=0;i<m;i++){
        scanf("%d",&a[i]);
    }

    // shokichi
    if(a[0] == 1 && a[1] == 2){
        printf("0");
        return 0;
    }
    if(a[0] == 2){
        b[0] = 1;
        b[1] = 0;
    }
    else if(a[0] == 1 && a[1] != 2){
        b[0] = 0;
        b[1] = 1;
    }
    else{
        b[0] = 1;
        b[1] = 2;
    }

    //keisan
    for(i=0;i<n-2;i++){
        b[i+2] = b[i+1] + b[i];
        for(j=k;j<m;j++){
            if(a[j] == i+3){
                flag++;
                k = j;
                break;
            }
        }
        if(flag == 1){
            b[i+2] = 0;
            flag--;
        }
        b[i+2] = b[i+2]%1000000007;
    }

    ans = b[n-1];
    printf("%d\n",ans);
    return 0;
    
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
#define MD 1000000007
typedef long long int ll;

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll h, w, dp[100][100] = {};
string s[100] = {};

int main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			if (i != 0 || j != 0)dp[i][j] = 1000;
		}
	}
	rep(i, h)cin >> s[i];
	rep(i, h) {
		rep(j, w) {
			if (i < h - 1) {
				if (s[i][j] != s[i + 1][j]) {
					dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
				}
				else {
					dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
				}
			}
			if (j < w - 1) {
				if (s[i][j] != s[i][j + 1]) {
					dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
				}
				else {
					dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
				}
			}
		}
	}
	if (s[0][0] == '#' && s[h - 1][w - 1] == '#') {
		cout << (dp[h - 1][w - 1] + 1) / 2 + 1 << endl;
	}
	else {
		cout << (dp[h - 1][w - 1] + 1) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
const int maxn=(int)1e6+5;
set<int> s;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int q;cin>>q;while(q--){
        int op=0;cin>>op;
        if(op==3){
            int l,r;
            cin>>l>>r;
            auto ed=s.upper_bound(r);
            for(auto it=s.lower_bound(l);it!=ed;it++)cout<<*it<<endl;
        }else{
            int x=0;
            cin>>x;
            if(op==0){s.insert(x);cout<<s.size()<<endl;}
            if(op==1){cout<<s.count(x)<<endl;}
            if(op==2){s.erase(x);}
        }
        
    }
}
/* 

- insert(xx): Insert xx to SS and report the number of elements in SS after the operation.
- find(xx): Report the number of xx in SS (0 or 1).
- delete(xx): Delete xx from SS.
- dump(LL, RR): Print elements xx in SS such that L≤x≤RL≤x≤R.
9
0 1
0 2
0 3
2 2
1 1
1 2
1 3
0 4
3 2 4
 */


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

int main() {
	int a, n, j;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a[10];
		stack<int> b, c;
		for (j = 0; j < 10; ++j) cin >> a[j];
		for (j = 0; j < 11; j++) {
			if (j == 10) {
				break;
			}
			if (j == 0) {
				b.push(a[j]);
			}
			else if (a[j] < b.top() && c.size() == 0) {
				c.push(a[j]);
			}
			else if (a[j] > b.top()) {
				b.push(a[j]);
			}
			else if (a[j] > c.top()) {
				c.push(a[j]);
			}
			else {
				break;
			}
		}
		if (j == 10) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 2972
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

using vi = std::vector<int>;

constexpr int ElementMax = 10'000;

vi CountingSort(const vi& src, int k);
void solve();

int main()
{
    solve();
    return 0;
}



void solve()
{
    using namespace std;

    int n;
    cin >> n;
    vi src(n);

    for (int& x : src)
        cin >> x;

    auto B = CountingSort(src, ElementMax);

    for (int i = 0; i < B.size(); ++i)
    {
        cout << B[i];
        if (i + 1 != n)
            cout << " ";
    }

    cout << endl;
}

vi CountingSort(const vi& src, int k)
{
    using namespace std;

    vi C(k + 1, 0);

    //C[i]にiの出現数を記録
    for (int in : src)
        ++C[in];

    //C[i]にi以下の数の出現数を記録
    for (int i = 1; i < C.size(); ++i)
        C[i] = C[i] + C[i - 1];

    vi out(src.size(), allocator<int>());

    for_each(make_reverse_iterator(src.cend()),
        make_reverse_iterator(src.cbegin()),
        [&out, &C](int x)
    {
        out[C[x] - 1] = x;
        --C[x];
    });

    return move(out);
}


Measured memory_bytes: 18404
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastt ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


int main()
{
	fastt

	string s,t;
	cin>>s>>t;
	ll ans=INT_MAX;
	
	for(ll i=0;i<=s.size()-t.size();i++){
		string tmp=s.substr(i,t.size());
		ll cnt=0;
		for(ll j=0;j<tmp.size();j++){
			if(tmp[j]!=t[j]) cnt++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll fr[ohara],ba[ohara];

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    fr[0]=a[0];
    rrep(i,1,n)fr[i]=__gcd(fr[i-1],a[i]);
    ba[n-1]=a[n-1];
    rrrep(i,n-2,0)ba[i]=__gcd(ba[i+1],a[i]);
    ans=max(ba[1],fr[n-2]);
    rrep(i,1,n-1){
        ans=max(ans,__gcd(fr[i-1],ba[i+1]));
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 9216
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			TreeSet<Restaurant> set = new TreeSet<>();
			for (int i = 1; i <= n; i++) {
				String s = sc.next();
				int p = sc.nextInt();
				set.add(new Restaurant(i, s, p));
			}
			set.forEach(r -> {
				System.out.println(r.index);
			});

		}
	}

	static class Restaurant implements Comparable<Restaurant> {
		int index;
		String city;
		int point;

		public Restaurant(int index, String city, int point) {
			this.index = index;
			this.city = city;
			this.point = point;
		}

		@Override
		public int compareTo(Restaurant o) {
			if (city.equals(o.city)) {
				return Integer.compare(point, o.point) * -1;
			}
			return city.compareTo(o.city);
		}

	}
}

Measured memory_bytes: 27732
<?php
fscanf(STDIN, '%d', $n);
$sqrt = (int)sqrt($n);

for($s = 1; $s <= $sqrt; $s++) {
    if($n % $s === 0) {
        $i = $s;
        $j = $n/$s;
    }
}

echo ($i+$j-2).PHP_EOL;

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

int main() {
  int N;
  scanf("%d", &N);
  std::string S;
  std::cin >> S;
  std::string out = "";
  N %= 27;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] + N > 'Z') {
      out += {(char)(S[i] + N - 'Z' + 'A' - 1)};
    } else {
      out += {(char)(S[i] + N)};
    }
  }
  printf("%s", out.c_str());
}


Measured memory_bytes: 256