akhauriyash/Code-Regression huggingface dataset:
K, S = [int(n) for n in input().split()]

def main():

    ans = 0
    for x in range(K + 1):
        for y in range(x + 1):
            z = S - x - y
            if z < 0 or\
                K < z or\
                x < z or\
                y < z:
                continue
            if x == y == z:
                ans += 1
            elif x != y != z:
                ans += 6
            else:
                ans += 3
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int gcd(int a,int b){
    while(b^=a^=b^=a%=b);
    return a;}
int main(){
    scanf("%d%d%d",&a,&b,&c);
    int l=gcd(a,b);
    if(c%l!=0) printf("NO");
    else printf("YES");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define maxn 100005
#define mp make_pair
#define fi first
#define se second
using namespace std;
vector <int> G[maxn];
pair <int, int> e[maxn];
int dfs(int u, int f, int d, int lim){
    int cnt = d > lim;
    for (int i = 0; i < G[u].size(); ++ i){
        int v = G[u][i];
        if (v != f)
            cnt += dfs(v, u, d + 1, lim);
    }
    return cnt;
}
int main(){
    int n, k;
    cin >> n >> k;
    for (int i = 1; i < n; ++ i){
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
        e[i] = mp(u, v);
    }
    if (k % 2 == 0){
        int ans = n;
        for (int i = 1; i <= n; ++ i)
            ans = min(ans, dfs(i, 0, 0, k / 2));
        cout << ans << endl;
        return 0;
    }
    else{
        int ans = n;
        for (int i = 1; i < n; ++ i)
            ans = min(ans, dfs(e[i].fi, e[i].se, 0, (k - 1) / 2) + dfs(e[i].se, e[i].fi, 0, (k - 1) / 2));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <map>
#include <memory.h>
#include <vector>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef pair<int, int> P;
const double EPS = 1e-12;
const int INF = 1 << 29;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
P par[60][60];
char field[60][60];
int oncost[60][60];
int offcost[60][60];
int keepcost[60][60];
int dist[60][60];
int r[2000];
int c[2000];

vector<int> visit[60][60];
int R, C, M;

void bfs(int sr, int sc){
  int r, c;
  queue<P> que;
  que.push(P(sr, sc));
  while(!que.empty()){
    P p = que.front();
    que.pop();
    r = p.first;
    c = p.second;
    rep(i, 4){
      int r2 = r + dy[i];
      int c2 = c + dx[i];
      if(0 <= r2 && r2 < R && 0 <= c2 && c2 < C && dist[r2][c2] == -1 && field[r2][c2] == '.'){
	dist[r2][c2] = dist[r][c] + 1;
	que.push(P(r2, c2));
	par[r2][c2] = p;
      }
    }
  }
}

int main(){
  cin >> R >> C >> M;
  rep(i, R) rep(j, C) cin >> field[i][j];
  rep(i, R) rep(j, C) cin >> keepcost[i][j];
  rep(i, R) rep(j, C) cin >> oncost[i][j];
  rep(i, R) rep(j, C) cin >> offcost[i][j];
  rep(i,M){
    cin >> r[i] >> c[i];
  }
  int t = 0;
  int res = 0;
  rep(i, M - 1){
    memset(dist, -1, sizeof(dist));
    memset(par, -1, sizeof(par));
    dist[r[i]][c[i]] = 0;
    bfs(r[i], c[i]);
    for(P p = P(r[i+1], c[i+1]); p.first != -1; p = par[p.first][p.second]){
      visit[p.first][p.second].push_back(t + dist[p.first][p.second]);
    }
    t += dist[r[i+1]][c[i+1]];
  }
  rep(i, R)rep(j, C){

    if(!visit[i][j].empty()){
      sort(visit[i][j].begin(), visit[i][j].end());
      res += oncost[i][j] + offcost[i][j];
      rep(k, (int)visit[i][j].size() - 1){
	int d = visit[i][j][k+1] - visit[i][j][k];
	int add = min(d * keepcost[i][j], oncost[i][j] + offcost[i][j]); 
	res += add;
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 6176
def three_letter_acronym(s1: str, s2: str, s3: str) -> str:
    return (s1[0] + s2[0] + s3[0]).upper()


if __name__ == "__main__":
    s1, s2, s3 = input().split()
    ans = three_letter_acronym(s1, s2, s3)
    print(ans)


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

long long A, B, C, X, Y;

int main() {
  cin >> A >> B >> C >> X >> Y;
  if(X > Y) { swap(X, Y); swap(A, B); }
  if(C * 2 > A + B) {
    cout << A * X + B * Y << endl;
  } else {
    cout << C * 2 * X + min(C * 2, B) * (Y - X) << endl;
  }
  return 0;
}


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

int main()
{
  int N, L;
  cin >> N >> L;
  
  vector<string> S(N);
  for(int i = 0; i < N; i++)
    cin >> S.at(i);
  
  string ans = "";
  sort(S.begin(), S.end());
  for(string str : S)
    ans += str;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;


int main(){
    // 入力
    Init();
    ll n;
    cin >> n;
    vi c(n);
    map<ll, ll> cnt;
    rep(i, n) cin >> c[i];
    
    // dp; i番目の文字まででありうるものの個数
    vi dp(n+1, 0);
    dp[0] = 1;

    for(ll i=1; i<=n; i++){
        // 1つ前までの結果を受け取る
        dp[i] = dp[i-1];
        // 一つ前と同じ文字なら特に処理無し
        if(i >= 2 && c[i-1] == c[i-2]) continue;
        // 今見ている文字がこれまでに出てきていたらひっくり返すことを考える
        dp[i] += cnt[c[i-1]];
        dp[i] %= MODV;
        cnt[c[i-1]] += dp[i-1];
        cnt[c[i-1]] %= MODV;
    }
    cout << dp[n]%MODV << endl;
}

Measured memory_bytes: 18716
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;

int main()
{
	ll n;
	cin >> n;
	int r = -1;
	for (int i = 1;i <= sqrt(n);i++)
	{
		if (n % i == 0) r = i;
	}
	r = n / r;
	int g = 0;
	while (r > 0)
	{
		g++;
		r /= 10;
	}
	cout << g;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main(){
    int a,b,c,x,count=0;
    cin >> a >> b >> c >> x;

    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x){
                    count++;
                }
            }
        }
    }

    cout << count << endl;
}




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

int main(){
    int N;
    cin >> N;
    int L[100];
    for (int i=0; i<N; i++) cin >> L[i];
    sort(L, L+N, greater<int>());
    int sum;
    for (int i=1; i<N; i++) {
        sum += L[i];
    }
    if (L[0] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

typedef long long LL;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, tmp;
    vector<int> a, b, c;
    cin >> n;
    rep(i, n){
        cin >> tmp;
        a.push_back(tmp);
    }
    rep(i, n){
        cin >> tmp;
        b.push_back(tmp);
    }
    rep(i, n){
        cin >> tmp;
        c.push_back(tmp);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    LL ans = 0;
    LL tmp1, tmp2;
    vector<int>::iterator itr1, itr2;
    for(int i = 0;i < n; i++){
        tmp1 = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        tmp2 = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += tmp1 * tmp2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int n;
	cin >> n;
    ll ans = 0;
    vector<ll> dif(n);
    rep(i,n) {
        ll a, b;
        cin >> a >> b;
        dif[i] = a+b;
        ans -= b;
    }
    sort(dif.begin(), dif.end());
    reverse(dif.begin(), dif.end());
    rep(i,n) if(i%2==0) ans += dif[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main(){
  int n;
  cin >> n;
  long long l[n+1];
  l[0]=2;
  l[1]=1;
  for(int i = 2; i <= n; i++){
    l[i]=l[i-1]+l[i-2];
  }
  cout << l[n] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;

int main() {
ll k;
string s;
string ans="";
cin >> k >> s;
if(s.size()<=k) cout << s << endl;

else {
    rep(i,k){
        ans+=s[i];
    }
    cout << ans+"..." << endl;
    
}
}


Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int keta = 0;
        int tmp = i;
        while (1)
        {
            if (tmp > 0)
            {
                tmp = tmp / 10;
                keta++;
            }
            else
            {
                break;
            }
        }
        if (keta % 2 != 0)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
 
int N, Q, K;
vector<vector<P>> root(100001);  //pair<辺の距離, 行先の頂点>
vector<ll> dp(100001, LLONG_MAX);

void rec(ll cost = 0, int corrent = K, int prev = 0){
    
    if(dp[corrent] != LONG_MAX && dp[corrent] < cost) return;
    dp[corrent] = cost;
    
    for(auto p : root[corrent]){
        if(p.second != prev) rec(cost + p.first, p.second, corrent);
    }
    
    return;
}

int main(void){
    
    cin >> N;
    for(int i = 0; i < N - 1; ++i){
        int a, b, c; scanf("%d %d %d", &a, &b, &c);
        root[a].push_back(make_pair(c, b)), root[b].push_back(make_pair(c, a));
    }
    
    scanf("%d %d", &Q, &K);
    rec();
    for(int i = 0; i < Q; ++i){
        ll x, y; cin >> x >> y;
        cout << dp[x] + dp[y] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 14336
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            string rtn = null;

            for(int i=0; i<S.Length; i++)
            {
                rtn += alphabet[(alphabet.IndexOf(S[i]) + N) % 26];
            }
            Console.WriteLine(rtn);
        }
    }
}


Measured memory_bytes: 34772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll N; cin >> N;
    vi H(N);
    rep(i, N) cin >> H[i];

    ll jj = 0, ans = 0;
    rep(i, N - 1) {
        if (H[i] >= H[i + 1]) { ++jj; }
        else {
            ans = max(ans, jj);
            jj = 0;
        }
    }
    ans = max(ans, jj);
    cout << ans << endl;
}

Measured memory_bytes: 640
from collections import deque

h, w = map(int, input().split())
G = []
for i in range(h):
  g = list(input())
  G.append(g)
  
que = deque()
dist = [[-1]*w for _ in range(h)]

sx, sy = 0, 0
gx, gy = w-1, h-1
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

dist[0][0] = 0
que.append([sx,sy])

while que:
  x, y = que.popleft()
  
  for i in range(4):
    nx = x+dx[i]
    ny = y+dy[i]
    
    if nx<0 or nx>=w or ny<0 or ny>=h or G[ny][nx]=='#':
      continue

    if dist[ny][nx]==-1:
      que.append([nx, ny])
      dist[ny][nx] = dist[y][x] +1
      
bk = 0
for i in range(h):
  for j in range(w):
    if G[i][j] == '#':
      bk += 1
      

if dist[gy][gx]==-1:
  print(-1)
else:
  print(h*w - bk - dist[gy][gx]-1)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int A,B,C,sum[104],j=0;
	cin>>A>>B>>C;
	for(int i=1;i<=100;i++)
	{
		if(A%i==0&&B%i==0)
		{
			sum[j]=i;
			j++;
		}
	}
	cout<<sum[j-C];
	return 0;
}

Measured memory_bytes: 256
N, W, H = map(int, input().split())
row, col = [0] * (H + 1), [0] * (W + 1)
for _ in range(N):
    x, y, w = map(int, input().split())
    row[max(0, y - w)] += 1
    row[min(H, y + w)] -= 1
    col[max(0, x - w)] += 1
    col[min(W, x + w)] -= 1
for i in range(H):
    row[i + 1] += row[i]
for i in range(W):
    col[i + 1] += col[i]
row.pop(), col.pop()
print("Yes" if all(x > 0 for x in row) or all(x > 0 for x in col) else "No")

Measured memory_bytes: 15512
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long sq = (long)Math.sqrt(N);
        long ans = Long.MAX_VALUE;
        for(long i=1;i<=sq;i++){
            if(N==(N/i)*i){
                ans = Math.min(ans, N/i+i);
            }
        }
        System.out.println(ans-2);
    }
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

vector<int> split(string s) {
	s += 'T';
	vector<int> r;
	for (int i = 0; i < s.size(); i++) {
		int j = i;
		for (; j < s.size() && s[j] == 'F'; j++) {

		}
		r.emplace_back(j - i);
		i = j;
	}
	return r;
}

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

	string s;
	pair<int, int> goal;

	cin >> s >> goal.first >> goal.second;

	vi v = split(s);
	goal.first -= v[0];
	vi puni, muni;

	for (int i = 1; i < v.size(); i++) {
		(i % 2 ? muni : puni).emplace_back(v[i]);
	}

	set<int> x, y;
	x.emplace(0);
	y.emplace(0);

	for (auto &i : puni) {
		set<int> next;
		for (auto &j : x) {
			next.emplace(j + i);
			next.emplace(j - i);
		}
		swap(x, next);
	}

	for (auto &i : muni) {
		set<int> next;
		for (auto &j : y) {
			next.emplace(j + i);
			next.emplace(j - i);
		}
		swap(y, next);
	}

	cout << (x.find(goal.first) != x.end() && y.find(goal.second) != y.end() ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 768
fn is_prime(n: usize) -> bool {
    if n <= 1 {
        return false;
    }
    for k in 2.. {
        if k * k > n {
            break;
        }
        if n % k == 0 {
            return false;
        }
    }
    true
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let x: usize = s.trim().parse().unwrap();
    for n in x.. {
        if is_prime(n) {
            println!("{}", n);
            return;
        }
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.buffer.readline

def main():
    N,M = map(int,input().split())
    a = list(map(int,input().split()))
    use = -1
    for i in range(N-1):
        if a[i]+a[i+1] >= M:
            use = i
            break
    
    if use == -1:
        print("Impossible")
    else:
        print("Possible")
        for j in range(i):
            print(j+1)
        for j in range(N-1,i,-1):
            print(j)

if __name__ == "__main__":
    main()

Measured memory_bytes: 12524
#include<iostream>
int main() {
	int a[14];
	std::cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> a[7] >> a[8] >> a[9] >> a[10] >> a[11] >> a[12] >> a[13];
	std::cout << a[0] - a[1] << std::endl;
	std::cout << a[2] - a[3] << std::endl;
	std::cout << a[4] - a[5] << std::endl;
	std::cout << a[6] - a[7] << std::endl;
	std::cout << a[8] - a[9] << std::endl;
	std::cout << a[10] - a[11] << std::endl;
	std::cout << a[12] - a[13] << std::endl;
	return 0;
}


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

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
    int k,a,b;
    cin>>k;
    cin>>a>>b;
    int ll=min(a,b)/k;
    if(k*ll >=a || k*(ll+1) <= b)
        cout<<"OK";
    else
        cout<<"NG";
    return 0;
}


Measured memory_bytes: 3624
/*Saurav Paul*/
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define boost				  ios_base::sync_with_stdio(0);
#define eb                    emplace_back
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1e9+7
#define itoc(c)               ((char)(((int)'0')+c))
#define ctoi(c)               ((int)(((int)c)-'0'))
#define all(p)                p.begin(),p.end()
#define iscn(num)             scanf("%d",&num);
#define scn(num)              scanf("%lld",&num);
#define scn2(num,num2)        scanf("%lld%lld",&num,&num2);
using namespace std;
///////////////////////

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
////////////////////////

template<typename T>T set_bit(T N,T pos){return N=N | (1<<pos);}
template<typename T>T reset_bit(T N,T pos){return N= N & ~(1<<pos);}
template<typename T> bool check_bit(T N,T pos){return (bool)(N & (1<<pos));}
template<typename T>void bin_print(T N){bitset<25>bit(N);cerr<<bit.to_string()<<"\n";}
template<typename T> void max_self(T &a, T b){
	a=max(a,b);
}
template <typename T > void min_self(T &a, T b){
	a=min(a,b);
}
template <typename T > void add_self(T &a, T b){
	a+=b;
}
////////////////////////

const ll INF = 2e18 + 99;
typedef pair<ll,ll> Pair;
typedef vector<ll> vec;;

template<typename T> void ara_read(T &v,ll n){
	ll temp;
	for(ll i=0; i< n; i++){
		scanf("%lld",&temp);
		v.emplace_back(temp);
	}
}
template<typename T> void ara_print(T &v){
	for(ll x : v)
		printf("%lld ",x);
	puts("");
}
////////////////////////
int const nax = 3005;
ll dp[nax][nax] ;	

int main()
{
	
	int n;
	scanf("%d",&n);
	vector < int > in;
	ara_read(in,n);
	
	for(int L=n-1; L >=0 ; L--){
		
		for(int R = L ; R < n ; R++){
			if(L==R){
				dp[L][R] = in[L] ;
			}else{
				
				dp[L][R] = max(in[L] - dp[L+1][R] , in[R] - dp[L][R-1]);
			}
			debug() << dbg(L) dbg(R) dbg(dp[L][R]) dbg(dp[L+1][R]) dbg(dp[L][R-1]);
		}
	}
	
	printf("%lld\n",dp[0][n-1]);
	
    return 0;
}


Measured memory_bytes: 70016
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main() {
    int n; cin >> n;
    vector<ll> ab_sum(n);
    ll b_sum = 0;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        ab_sum[i] = a+b;
        b_sum += b;
    }
    sort(ab_sum.begin(), ab_sum.end(), greater<ll>());

    ll ans = -b_sum;
    for (int i = 0; i < n; i++)
    {
        if(i % 2 == 0) {
            ans += ab_sum[i];
        } 
    }
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;

	cin >> n;

	REP(i, 26) {
		ll x = n - i * 4;
		if (x < 0) {
			break;
		}
		if (x % 7 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int N;
	cin >> N;
	int a[N];
	for (int i = 0; i < N; i++) {
		int tmp; cin >> tmp;
		a[i] = tmp - i - 1;
	}

	sort(a, a + N);

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ans += abs(a[i] - a[N / 2]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)

using namespace std;
using ll = __int64_t;

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

bool comp(const pair<int, ll>& p1, const pair<int, ll>& p2){
    return p1.second > p2.second;
}

void solve(){
    int n, sum=0, res=1000;
    int w[105];
    cin >> n;
    rep(i, n){
        cin >> w[i];
        sum += w[i];
    } 
    int sum2 = 0;
    rep(i, n){
        sum2 += w[i];
        res = min(res, abs(sum - sum2*2));
    }
    cout << res << endl;
}

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

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

const int64_t MOD = 1000 * 1000 * 1000 + 7;

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

  // i番目の文字を見た時に13との剰余がnになる個数を数え上げる
  std::vector<int64_t> dp(s.length() * 13);

  {
    int val = -1;
    if (s[0] != '?') val = s[0] - '0';
    if (val == -1) {
      for (int i = 0; i < 10; ++i) {
        dp[i % 13] = 1;
      }
    } else {
      dp[val % 13] = 1;
    }
    // % 13は不要だけど定義に帰るため
  }

  for (int i = 1, e = s.length(); i < e; ++i) {
    int val = -1;
    if (s[i] != '?') val = s[i] - '0';
    if (val == -1) {
      for (int here = 0; here < 10; ++here) {
        for (int pre = 0; pre < 13; ++pre) {
          auto &here_dp = dp[i * 13 + ((pre * 10 + here) % 13)];
          const auto &pre_dp = dp[(i - 1) * 13 + pre];
          here_dp = (here_dp + pre_dp) % MOD;
        }
      }
    } else {
      for (int pre = 0; pre < 13; ++pre) {
        auto &here_dp = dp[i * 13 + ((pre * 10 + val) % 13)];
        const auto &pre_dp = dp[(i - 1) * 13 + pre];
        here_dp = (here_dp + pre_dp) % MOD;
      }
    }
  }

  std::cout << dp[(s.length() - 1) * 13 + 5] << std::endl;

  // for (int i = 0, e = s.length(); i < e; ++i) {
  // for (int j = 0; j < 13; ++j) {
  //   printf("%5d", dp[i * 13 + j]);
  // }
  // std::cout << std::endl;
  //}
  return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

using P = pair<int64_t, int64_t>;

bool intersect(P a, P b) {
  assert(a.first < b.first);
  return b.first < a.second;
}

P merge(P a, P b) {
  if (a.first > b.first) {
    swap(a, b);
  }
  return {a.first, b.second};
}

int main() {
  int N; int64_t T; cin >> N >> T;
  vector<int64_t> t(N); cin >> t;
  deque<P> vs;
  vs.emplace_back(0, T);
  REP(i, 1, N) {
    auto np = make_pair(t[i], t[i] + T);
    if (intersect(vs.back(), np)) {
      auto m = merge(vs.back(), np);
      vs.pop_back();
      vs.push_back(m);
    } else {
      vs.push_back(np);
    }
  }
  int64_t sum = 0;
  for (auto e: vs) {
    sum += e.second - e.first;
  }
  cout << sum << "\n";
}


Measured memory_bytes: 5120
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int H;
int W;
int D;
int A;
int X[90000];
int Y[90000];
int Q;
int L;
int R;
int s[90000];
int main(){
  int Lj4PdHRW, i;
  rd(H);
  rd(W);
  rd(D);
  for(i=0;i<(H);i++){
    int j;
    for(j=0;j<(W);j++){
      rd(A);A += (-1);
      X[A] = i;
      Y[A] = j;
    }
  }
  for(i=(D);i<(H*W);i++){
    s[i] = s[i-D] + abs(X[i]-X[i-D]) + abs(Y[i]-Y[i-D]);
  }
  rd(Q);
  for(Lj4PdHRW=0;Lj4PdHRW<(Q);Lj4PdHRW++){
    rd(L);L += (-1);
    rd(R);R += (-1);
    wt_L(s[R] - s[L]);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190902-1

// --- original code ---
// int H, W, D, A, X[9d4], Y[9d4], Q, L, R;
// int s[9d4];
// {
//   rd(H,W,D);
//   rep(i,H) rep(j,W){
//     rd(A--);
//     X[A] = i;
//     Y[A] = j;
//   }
//   rep(i,D,H*W) s[i] = s[i-D] + abs(X[i]-X[i-D]) + abs(Y[i]-Y[i-D]);
//   rd(Q);
//   rep(Q){
//     rd(L--, R--);
//     wt(s[R] - s[L]);
//   }
// }


Measured memory_bytes: 2176
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

int n, m;
vector<P> as, bs;
bool v[1000];

double solve(){
	
	priority_queue<pair<double, int> > q;
	q.push(mp(0, 0));
	memset(v, 0, sizeof(v));
	
	while(!q.empty()){
		int c = q.top().second;
		double cost = q.top().first; q.pop();
		
		if(v[c]) continue;
		v[c] = 1;
		if(c == 1) return abs(as[0] - as[1]) - cost;
		
		rep(i, m) if(i != c && !v[i]){
			if(intersectSS(L(as[0], as[1]), L(bs[c], bs[i]))) continue;
			q.push(mp(cost - abs(bs[c] - bs[i]), i));
		}
	}
	return INF;
}

int main()
{
	cin >> n >> m;
	rep(i, n){
		int x, y;
		cin >> x >> y;
		as.pb(P(x, y));
	}
	rep(i, m){
		int x, y;
		cin >> x >> y;
		bs.pb(P(x, y));
	}
	
	double ans = INF;
	rep(i, 2){
		ans = min(ans, solve());
		if(i == 0) swap(as, bs), swap(n, m);
	}
	if(ans == INF) puts("-1");
	else printf("%.20f\n", ans);
	
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;cin>>n;
    vi a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll ans=0;
    rep(i,n-1){
        if(a[i]>a[i+1]){ans+=a[i]-a[i+1];a[i+1]=a[i];}
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3972
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int main(void){
  int N,K,num=1;
  cin>>N>>K;

  FOR(i,0,N){
    if(num>K){
      num+=K;
    }else{
      num+=num;
    }
  }
  cout<<num<<endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include<iostream>

using namespace std;


int NData[200000];
int MData[200000];
int n = 0;
int m = 0;

int compare_int(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}
int main(void) {
	

	

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> NData[i];
	}
	qsort(NData,n,sizeof(int), compare_int);
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> MData[i];
	}
	qsort(MData, m, sizeof(int), compare_int);

	int p = 0;
	for (int i = 0; i < m; i++) {
		for (int j = p; j < n; j++) {
			if (MData[i] < NData[j]) {
				cout << "NO";
				return 0;
			}
			if (MData[i] == NData[j]) {
				NData[j] = -1;
				p = j;
				break;
			}
		}
	}	
	cout << "YES";

	return 0;
}

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


int main() {
	int n;
	int sum = 0;
	cin >> n;
	int* point = new int[n];

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

	if (sum % 10 != 0) {
		cout << sum;
		delete[] point;
		return 0;
	}

	int min = 100;
	for (int i = 0; i < n; i++) {
		if (point[i] < min&&point[i] % 10 != 0) {
			min = point[i];
		}
	}
	if (min == 100) {
		cout << 0;
		delete[] point;
		return 0;
	}
	cout << sum - min;


	delete[] point;
	return 0;
}

Measured memory_bytes: 256
x,y,X,Y,v,d;S(){scanf("%d%d",&X,&Y);}C(w){w=abs(y-Y);d=(X<x-(v=(w+y%2)/2)?x-v-X:X>x+(v=(w+1-y%2)/2)?X-x-v:0)+w;}m,n,D[124][101],s,b,F="%d\n";main(c){for(;S(),n=Y,m=X;printf(F,b)){for(memset(D,scanf(F,&s),5e4);s--;)for(S(y=n);y;y--)for(x=m;x;x--)C(),d<D[x][y]?D[x][y]=d:0;for(b=!scanf(F,&s);s--;b=c>b?c:b)for(S(c=0),y=n;y;y--)for(x=m;x;c+=d<D[x--][y])C();}exit(0);}

Measured memory_bytes: 0
#include <iostream>
#include "bits/stdc++.h"
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define lpe(i, n) for (int i = 1; i <= (int)(n); ++i)
#define lpd(i, n) for (int i = (int)(n); i >= 1; --i)
#define ll long long
using namespace std;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
typedef map<ll, ll> ml;
int a[1000000];
int main()
{

ll x;
cin>>x;
ll sum=x/500;
x=x%500;
x=x/5;
cout<<sum*1000+x*5;
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    dp = []
    now = 1
    ans = 0
    for i in range(n+1):
        if a[i] > now:
            print(-1)
            return
        else:
            dp.append(now)
            now -= a[i]
            now *= 2
    now = 0
    for i in range(n, -1, -1):
        now += a[i]
        ans += min(now, dp[i])
    print(ans)


main()


Measured memory_bytes: 702036
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>

using ll = long long;

using namespace std;

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    ll dif = abs(a - b);
    cout << (w * t + dif <= v * t ? "YES" : "NO") << '\n';
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
ll a[100010], num[45];
int main() {
	int n; ll k;
	cin >> n >> k;
	rep(i,n) {
		cin >> a[i];
		rep(j,40) {
			if ((a[i]>>j) & 1) num[j]++;
		}
	}

	ll x = 0;
	for (int i = 39; i >= 0; i--)	{
		if (num[i] * 2 <= n) x += (1LL << i);
		if (x > k) x -= (1LL << i);
	}
	ll ans = 0;
	rep(i,n) {
		ans += x ^ a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4364
H,W,N = map(int, input().split())
st = [int(i) for i in input().split()]
S = input()
T = input()

 
safe_ud = [1, H]
safe_lr = [1, W]
flag = True
for i in reversed(range(N)):
    if T[i] == 'L': #守りが'L'なら安全地帯の左端を狭める
        if safe_lr[1] != W:
            safe_lr[1] += 1
    elif T[i] == 'R': #守りが'R'なら安全地帯の右端を狭める
        if safe_lr[0] != 1:
            safe_lr[0] -= 1
    elif T[i] == 'U': #守りが'U'なら安全地帯の下端を狭める
        if safe_ud[1] != H:
            safe_ud[1] += 1
    elif T[i] == 'D': #守りが'D'なら安全地帯の上端を狭める
        if safe_ud[0] != 1:
            safe_ud[0] -= 1
    
    if S[i] == 'L': #攻めが'L'なら安全地帯の右端を広げる
        safe_lr[0] += 1
    elif S[i] == 'R': #攻めが'R'なら安全地帯の左端を広げる
        safe_lr[1] -= 1
    elif S[i] == 'U': #攻めが'U'なら安全地帯の上端を広げる
        safe_ud[0] += 1
    elif S[i] == 'D': #攻めが'D'なら安全地帯の下端を広げる
        safe_ud[1] -= 1

    if safe_lr[1] - safe_lr[0] < 0 or safe_ud[1] - safe_ud[0] < 0: #安全地帯が無くなったらOUT
        flag = False
        break
 
if flag:
    if safe_ud[0] <= st[0] <= safe_ud[1] and safe_lr[0] <= st[1] <= safe_lr[1]:
        pass
    else:
        flag = False
 
if flag:
    print('YES')
else:
    print('NO')

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

int main()
{
    int n , a , b;
    cin>>n>>a>>b;
    
    if ( abs(b-a) % 2 == 0 )
    {
        cout<<"Alice"<<endl;
    }
    else if ( abs(b-a) % 2 == 1 )
    {
        cout<<"Borys"<<endl;
    }
    else
    {
        cout<<"Draw"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX], n;
    
    cin >> n;
    for( int i = 0; i < n; i++ ) cin >> R[i];
    
    int maxv = -2000000000; //十分小さい値を初期値に設定
    int minv = R[0];
    
    for( int i = 1; i < n; i++ ){ //ここで毎回R[i]を読み込めば配列は不要
        maxv = max(maxv, R[i] - minv); //最大値を更新
        minv = min(minv, R[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3872
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    int n; cin >> n;
    ll a[300001];
    ll ans = 0;

    rep(i,3*n){
        cin >> a[i];
    }

    sort(a,a+3*n);

    rep(i,n){
        ans += a[(3*n-2)-2*i];
    }
    cout << ans;
    return 0;
}











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


int main() {
  int N;
  cin>>N;
  
  map<int,int> mp;
  for(int i=1;i<=N;i++){
    int x;
    cin>>x;
    mp[x]=i;
  }
  
   for(int i=1;i<=N;i++){
     cout<<mp[i];
     if(i!=N) cout<<" ";
   }
  cout<<endl;
  
}

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

struct Card { char suit, value; };

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

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

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

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

int main(){
    Card C1[100], C2[100];
    int n;
    char ch;
    
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> C1[i].suit >> C1[i].value;
    }
    
    for(int i=0; i<n; i++) C2[i] = C1[i];
    
    bubble(C1, n);
    selection (C2, n);
    
    print(C1, n);
    cout << "Stable" << endl;
    print(C2, n);
    if(isStable(C1, C2, n)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3080
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for(int i=0; i<n; ++i) cin >> p[i];

	sort(p.begin(),p.end());
	int ans=0;
	for(int i=0; i<k; ++i) ans += p[i];
	cout << ans << endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main{

    int n,m;
    int[][] e;
    int[] par;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            m = sc.nextInt();
            if(n==0 && m==0) break;

            //a, b, w
            e = new int[m][3];
            for(int i=0; i<m; i++){
                int a = sc.nextInt(), b = sc.nextInt();
                int w = sc.nextInt();
                e[i] = new int[]{a-1,b-1,w};
            }

            Arrays.sort(e, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        return a[2] - b[2];
                    }
                });
            int ans = Integer.MAX_VALUE;
            for(int i=0; m-i>=n-1; i++){
                ans = Math.min(ans, kruskal(i));
            }

            if(ans==Integer.MAX_VALUE) ans = -1;
            System.out.println(ans);
        }
    }

    int kruskal(int idx){
        par = new int[n];
        for(int i=0; i<n; i++) par[i] = i;

        int res = 0, cnt = 0;
        for(int i=idx; i<m; i++){
            int a = find(e[i][0]), b = find(e[i][1]);
            if(a!=b){
                par[a] = par[b];
                res = e[i][2];
                cnt++;
            }
        }

        if(cnt==n-1) return res-e[idx][2];
        else return Integer.MAX_VALUE;
    }

    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }

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

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#define rep(a,i,n) for(int i = (a) ; i< (n);i++)
#define ic(n) int (n); cin>>(n);
#define SORT(a) sort((a).begin(),(a).end());
#define che(a,string) cout<<string<<":"<<(a)<<endl;
#define ch(a,string) cout<<string<<":"<<(a)<<" ";
using namespace std;
typedef pair<int,int> P;
int main(){
	ic(n);
	if(1==n){
		cout<<"Hello World"<<endl;
	  }
	else if(2==n){
		ic(a);ic(b);
		cout<<a+b<<endl;
	  }
  }

Measured memory_bytes: 256
s = input()
ans = 10**18

for i in range(26):
    #print(chr(i+65+32))
    cnt = 0
    tmp = 0
    if s.count(chr(i+65+32)) == 0:
        continue
    #print(chr(i+65+32))
    for j in range(len(s)):
        if s[j] == chr(i+65+32):
            tmp = max(tmp,cnt)
            cnt = 0
        else:
            cnt += 1
    tmp = max(tmp,cnt)
    #print(tmp,cnt,ans)
    ans = min(ans,tmp)
            
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int r,pi,area,area1 ;
    scanf("%d",&r);
    pi=3.1416 ;
    area = pi*pow(r,2) ;
    area1 = pi;
    area/area1 ;
    printf("%d\n",area/area1);
    return 0;
}


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

int n;
int x[10], y[10];

double dist(int i, int j){
double dx = x[i]-x[j];
double dy = y[i]-y[j];
return pow(dx*dx+dy*dy,0.5);
}

void solve(){
cin >> n;
for(int i = 1;i<=n;i++)cin>>x[i]>>y[i];
    vector<int> v(n);
    for(int i = 0; i < n; i++) v[i] = i + 1;
    double sum = 0.0;
do {
for(int i = 0;i<n-1;i++)sum+=dist(v[i],v[i+1]);

} while(next_permutation(v.begin(),v.end()));
    int Factorial = 1;
    for(int i = 2; i <= n; i++) Factorial *= i;
    cout<<fixed<<setprecision(10)<<sum/Factorial<<endl;


}


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


Measured memory_bytes: 256