akhauriyash/Code-Regression huggingface dataset:
import heapq

n, m = map(int,input().split())
joblist = {}
for i in range(n):
    a,b = map(int,input().split())
    if a in joblist:
        joblist[a].append(-1*b)
    else:
        joblist[a] = [-1*b]

kouho = []
 
ans =0
 
for i in range(1,m+1):
    if i in joblist:
        for j in joblist[i]:
            heapq.heappush(kouho,j)
    if kouho:
        ans += heapq.heappop(kouho)
 
print(-1*ans)

Measured memory_bytes: 26020
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
typedef long double ld;
ld pi = acos(-1);
int main(){ 
  ld a, b;
  ld h, m;
  cin >> a >> b >> h >> m;

  ld x = (ld)360 / 12 * h;
  ld y = (ld)360 / 60 * m;
  //cout << x << " " << y << endl;
  x += 0.5 * m;
  ld theta = abs(x - y);
  if (x == 0) theta = min(theta, abs(360 - y));
  if (y == 0) theta = min(theta, abs(360 - x));
  theta = theta * (pi / 180);
  ld res = a * a + b * b - 2.0 * a * b * cos(theta);
  res = sqrt(res);
  printf("%.12Lf\n", res); 
  return 0;
} 

Measured memory_bytes: 4148
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>


const int maxn=1010,mod=1e9+7,N=2020;
int h,w,f[maxn][maxn],cnt;
main()
{
    f[1][1]=1;
    cin>>h>>w;
    forinc(i,1,h)
    forinc(j,1,w)
    {
        char ch;
        cin>>ch;
        if(ch=='.')
        {
            f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%mod;
        }
    }
    cout<<f[h][w];
}


Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int a, b;
    cin >> a >> b;
    if (a <= 8 && b <= 8) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}



Measured memory_bytes: 3568
A, B, C, K = map(int, input().split())
s = 0

if A >= K:
    s += K
    K -= K
else:
    s += A
    K -= A

if B >= K:
    K -= K
else:
    K -= B

if C >= K:
    s -= K
    K -= K
else:
    s += C
    K -= C

print(s)


Measured memory_bytes: 9188
#include<iostream>

using namespace std;

const int MAX_N = 2e5;
int Ai[MAX_N];

int main(void) {
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    int N;  cin >> N;

    for (int i = 0; i < N; i ++) 
        cin >> Ai[i];

    int lb = 0, ub = 0;
    long long res = 0;
    int curxor = 0, cursum = 0;

    while (lb < N) {
        while (ub < N && (curxor^Ai[ub]) == cursum+Ai[ub]) {
            curxor^=Ai[ub];
            cursum+=Ai[ub];
            ub++;
        }
        res += (ub - lb);
        curxor ^= Ai[lb];
        cursum -= Ai[lb];
        lb++;
    }

    cout << res << '\n';
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000

int main(){
    int A,B,ans=MAX;
    cin>>A>>B;
    string str;
    cin>>str;
    for(int i=0;i<A;i++){
        if(str[i]<'0' or str[i]>'9') ans=-11;
    }
    if(str[A]!='-')ans=-1;
    for(int i=A+1;i<A+B+1;i++){
        if(str[i]<'0' or str[i]>'9') ans=-11;
    }
    if(ans<0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int h,w; cin >> h >> w;
  vector<string> a(h); rep(i,h) cin >> a[i];
  int cnt = 0;
  rep(i,h) rep(j,w){
    if(a[i][j] == '#') cnt++;
  }
  if(cnt == h+w-1) cout << "Possible";
  else cout << "Impossible";
  cout << endl;
  return 0;
}


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

int main() {
  int date[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
  int a,b,ans=0;
  cin >> a >> b;
  for (int i=a; i>=1; i--) {
    for (int j=b; j>=1; j--) {
      if (i == j) ans++;
    }
    b = date[i-1];
  }
  cout << ans << endl;
}

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

main(){
	map<string,int> M ;
	string s ;
	int n ;
	
	cin >> n ;
	while(n--){
		cin >> s ;
		M[s]++ ;
	}
	
	cin >> n ;
	int cnt=1 ;
	while(n--){
		cin >> s ;
		if( !M[s] ) cout << "Unknown " << s << endl ;
		else {
			if( cnt%2 ) cout << "Opened by " << s << endl ;
			else cout << "Closed by " << s << endl ;
			cnt++ ;
		}
	}
}

Measured memory_bytes: 1240
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int x; cin >> x;
    cout << (x<1200 ? "ABC" : "ARC") << endl;
}


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

const int INF = numeric_limits<int>::max();

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i - j >= 0) {
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }
    cout << dp[n - 1] << endl;

    return 0;
}

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

int main(){
    int H, W, K; cin >> H >> W >> K;
    vector<vector<char> > c(H, vector<char>(W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> c[i][j];
        }
    }
    int ans = 0;
    for(int maskR = 0; maskR < (1 << H); maskR++){
        for(int maskC = 0; maskC < (1 << W); maskC++){
            int black = 0;
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if(((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 
                        and c[i][j] == '#') black++;
                }
            }
            if(black == K) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(){
  int M[100][100];
  int n, i, j, k, u, v;

  scanf("%d", &n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j] = 0;
    }
  }

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

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

  return 0;
}
 

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

struct xyh {
  int x, y, h;
};

int main()
{
  int n;
  cin >> n;
  vector<xyh> survey(n);

  for (int i = 0; i < n; i++) {
    cin >> survey[i].x >> survey[i].y >> survey[i].h;
  }

  vector<xyh> pyramid(101 * 101);

  for (int y = 0; y <= 100; y++) {
    for (int x = 0; x <= 100; x++) {
      pyramid[101 * y + x] = {x, y, 0};
    }
  }

  for (auto&& p : pyramid) {
    if (p.h < 0) continue;
    for (auto&& s : survey) {
      if (s.h == 0) continue;
      if (p.h == 0) {
        p.h = abs(p.x - s.x) + abs(p.y - s.y) + s.h;
      } else {
        if (p.h != abs(p.x - s.x) + abs(p.y - s.y) + s.h) {
          p.h = -1;
          break;
        }
      }
    }
    if (p.h < 0) continue;
    for (auto&& s : survey) {
      if (s.h != 0) continue;
      if (p.h > abs(p.x - s.x) + abs(p.y - s.y)) {
        p.h = -1;
        break;
      }
    }
  }
  for (auto&& p : pyramid) {
    if (p.h > 0) {
      cout << p.x << " " << p.y << " " << p.h << endl;
      break;
    }
  }
}


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

int main() {
    int n, x;
    vector<int> m;
    int num = 0;
    int tmp;

    cin >> n >> x;

    for (int i = 0; i < n; i++) {
        cin >> tmp;
        m.push_back(tmp);
        num += m[i];
    }
    int minx = m[0];

    for(int i = 0; i < (int)m.size(); ++i) {
        if( m[i] < minx )
            minx = m[i];
    }

    x -= num;
    
    while (x >= minx) {
        x -= minx;
        n++;
    }

    cout << n;
}

Measured memory_bytes: 256
S = input()
T = input()

dp = [[0] * (len(T)+1) for i in range(len(S)+1)]
for i, s in enumerate(S, 1):
  for j, t in enumerate(T, 1):
    if s == t:
      dp[i][j] = dp[i-1][j-1] + 1
    else:
      dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = []
while i > 0 and j > 0:
  if dp[i][j] == dp[i][j-1]:
    j -= 1
  elif dp[i][j] == dp[i-1][j]:
    i -= 1
  else:
    ans.append(S[i-1])
    i -= 1
    j -= 1

print(''.join(ans[::-1]))

Measured memory_bytes: 112476
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
 
using ll = long long;
 
using namespace std;
 
int main() {
  int n;
  cin >> n;

  int ans = n/2;
  if (n%2 == 1) {
    ans++;
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,n;
string b[105];
int main()
{
    cin>>a>>n;
    for(int s=0;s<a;s++)
    {
        cin>>b[s];
    }
    sort(b,b+a);
    for(int s=0;s<a;s++)
    cout<<b[s];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
   	int a = sc.nextInt();
    int count = 0;
    int count2 = 0;
    
    if(a == 1) count--;
    if(a == 2) count -= 2;
    
    while(count2 < 2){
      	count++;
      	if(a == 4) count2++;
		if(a % 2 == 0) a /= 2;
      	else a = a*3+1;     	
    }
    
    System.out.println(count);

  }
}


Measured memory_bytes: 35632
#include<bits/stdc++.h>
using namespace std;
int n, q, s, t, x, d, u;
vector<pair<int, pair<int, bool>>> pr;
set<int> st;
int main(){
    scanf("%d%d", &n, &q);
    
    for(int i = 0; i < n; i++){
        scanf("%d%d%d", &s, &t, &x);
        pr.push_back(make_pair(s-x, make_pair(x,true)));
        pr.push_back(make_pair(t-x, make_pair(x,false)));
    }
    sort(pr.begin(), pr.end());
    for(int i = 0; i < q; i++){
        scanf("%d", &d);
        while(u < pr.size() && pr[u].first <= d){
            if(pr[u].second.second) st.insert(pr[u].second.first);
            else st.erase(pr[u].second.first);
            u++;
        }
        printf("%d\n", st.empty() ? -1 : *st.begin());
    }
}

Measured memory_bytes: 15852
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] dts = null;
        string r = "";

        while(true)
        {
            // 0:H, 1:W
            dts = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            if (dts[0] == 0 && dts[1] == 0) break;

            for (int i = 0; i < dts[0]; i++)
            {
                r = "";
                
                for (int j = 0; j < dts[1]; j++)
                {
                    if (i == 0 || i == (dts[0] - 1))
                        r += "#";
                    else
                    {
                        if (j == 0 || j == (dts[1] - 1))
                            r += "#";
                        else
                            r += ".";
                    }
                }

                Console.WriteLine(r);    
            }

            Console.WriteLine("");
        }
    }
}


Measured memory_bytes: 9616
from itertools import accumulate

N = int(input())
xys = []
m_x = 0
m_y = 0

for i in range(N):
	xy = list(map(int, input().split()))
	xys += [xy]
	x_1,y_1,x_2,y_2 = xy
	m_x = max(x_2, m_x)
	m_y = max(y_2, m_y)

im = [[0]*(m_x+1) for i in range(m_y+1)]

for xy in xys:
	x_1,y_1,x_2,y_2 = xy
	im[y_1][x_1] += 1
	im[y_1][x_2] -= 1
	im[y_2][x_1] -= 1
	im[y_2][x_2] += 1

print(max(map(max, map(accumulate, zip(*map(accumulate, im))))))



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

lol W[300011]; 
lol E[300011];

int main() {
    lol n;
    string s;
    cin >> n >> s;
    for(lol i=0; i<n; i++){
        if(i==0){
            if(s[i]=='W'){
                W[0]=1;
                E[0]=0;
            }
            else{
                W[0]=0;
                E[0]=1;
            }
        }
        else{
            W[i]=W[i-1]+(s[i]=='W');
            E[i]=E[i-1]+(s[i]=='E');
        }
    }
    lol ans=INT_MAX;
    for(lol i=0; i<n; i++){
        if(i==0){
            lol temp=E[n-1]-E[0];
            ans=min(ans,temp);
        }
        else if(i==(n-1)){
            lol temp=W[n-2];
            ans=min(ans,temp);
        }
        else{
            lol temp=(W[i-1])+(E[n-1]-E[i]);
            ans=min(ans,temp);
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5380
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

vi v;
int main() {
    string S;
    int K;
    cin >> S >> K;

    int i,c = 1;
    LLI ans = 0;
    for (i = 1; i < S.size(); i++) {
        if (S[i] == S[i-1]) c++;
        else v.pb(c),c = 1;
    }
    v.pb(c);
    if (v.size() == 1) printf("%lld\n",((LLI) K*S.size())/2);
    else if (v.size() == 2) printf("%lld\n",(LLI) K*(v[0]/2+v[1]/2));
    else {
        int c = 0;
        for (i = 1; i < v.size()-1; i++) c += v[i]/2;
        if (S[0] == S[S.size()-1]) {
            LLI ans = (LLI) K*c;
            ans += v[0]/2+v.back()/2;
            ans += (LLI) (K-1)*((v[0]+v.back())/2);
            printf("%lld\n",ans);
        }
        else c += v[0]/2+v.back()/2,printf("%lld\n",(LLI) K*c);
    }

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
#define MP make_pair
#define PB push_back
#define F_d first
#define S_d second
#define LARGE 100000000
#define MOD 100000
#define LL long long

int c[5] = {};
int main() {
	for (int i = 0; i < 3; i++) {
		int a, b;
		cin >> a >> b;
		c[a]++; c[b]++;
	}
	if (c[1] == 3 || c[2] == 3 || c[3] == 3 || c[4] == 3)cout << "NO" << endl;
	else cout << "YES" << endl;

	return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var _S, _T string
	fmt.Scanf("%s\n%s", &_S, &_T)
	S, T := []rune(_S), []rune(_T)
	for i := 0; i < len(S); i++ {
		for j := 0; j < len(S); j++ {
			if S[(j+i)%len(S)] != T[j] {
				goto A
			}
		}
		fmt.Printf("Yes\n")
		return
	A:
	}
	fmt.Printf("No\n")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin >> n;
    map<ll,ll>arr;
    ll temp ;
    for(ll i=0 ; i < n-1 ; i++)
    {
        cin >> temp;
        auto j = arr.find(temp);
        if( j == arr.end())
            arr.insert(make_pair(temp,1));
        else
            j->second++;
    }

    for(ll i = 1 ; i <= n ; i++)
    {
        auto j = arr.find(i);
        if( j == arr.end())
            cout << 0 << endl;
        else
            cout << j->second << endl;
    }
    return 0;
}


Measured memory_bytes: 16128
#include <iostream>

int main () {
  long long N, A, B, C, D;
  std::cin >> N >> A >> B >> C >> D;
  bool ans = false;
  for (int up = 0; up < N; ++up) {
    int down = N - 1 - up;
    long long base = A + (up - down) * C;
    long long ma = base + up * (D - C);
    long long mi = base - down * (D - C);
    ans |= mi <= B && B <= ma;
  }
  std::cout << (ans ? "YES" : "NO") << std::endl;
}


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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;

int v[15][15];

int main() {
	Boost();

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

	for(int i = 0; i <= 9; ++i) {
		for(int j = 0; j <= 9; ++j) {
			cin >> v[i][j];
		}
	}

	for(int k = 0; k <= 9; ++k) {
		for(int i = 0; i <= 9; ++i) {
			for(int j = 0; j <= 9; ++j) {
				if(i == j || i == k || j == k) continue;
				if(v[i][k] + v[k][j] < v[i][j]) {
					v[i][j] = v[i][k] + v[k][j];
				}
			}
		}
	}

	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			int x;
			cin >> x;

			if(x != -1) ans += v[x][1];
		}
	}

	cout << ans;
	return 0;
}

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

const int INF = 100000;
const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int N, X, Y;

void dfs(int v, int dist, vector<int> &d) {
    d[v] = dist;
    if (0 <= v-1 && d[v-1] == INF) dfs(v-1, dist+1, d);
    if (v+1 < N && d[v+1] == INF) dfs(v+1, dist+1, d);
    if (v == X && d[Y] == INF) dfs(Y, dist+1, d);
    if (v == Y && d[X] == INF) dfs(X, dist+1, d);
}

int main() {
    cin >> N >> X >> Y;
    X --; Y--;

    vector<int> d1(N, INF), d2(N, INF);
    dfs(X, 0, d1);
    dfs(Y, 0, d2);

    map<int,int> cnt;
    for (int i=0; i<N; ++i) {
        for (int j=i+1; j<N; ++j) {
            int mn = min({abs(i-j), d1[i]+1+d2[j], d2[i]+1+d1[j]});
            cnt[mn] ++;
        }
    }

    for (int i=1; i<=N-1; ++i) {
        cout << cnt[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007


int main(){
    string s = "";
    char a, b, c, d; cin >> a >> b >> c >> d;
    s += a;
    s += b;
    s += c;
    s += d;
    
    int e=0;
    int f=0;
    int g=0;
    int h=0;
    for(char c:s){
        if(c=='1')e++;
        if(c=='9')f++;
        if(c=='7')g++;
        if(c=='4')h++;
    }
    if(e==1&&f==1&&g==1&&h==1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


YES = "Possible"  # type: str
NO = "Impossible"  # type: str


def solve(A: int, B: int):
    print(YES if A * B * (A + B) % 3 == 0 else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


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

int main(){
	int N; cin >> N;
	
	vector<int> p(N);
	for(int i = 0; i < N; i++){
		cin >> p[i];
	}

	sort(p.begin(),p.end(),greater<int>());
	
	int ans = 0;
	for(int i = 0; i < N; i++){
		if(i == 0){
			ans += p[i] / 2;
		}
		else{
			ans += p[i];
		}
	}
	
	cout << ans;
	return 0;
}

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

fn main() {
    let stdin = io::stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut input = buf.split_whitespace().map(|i| usize::from_str(i).unwrap());
    let (youki, mizu1, mizu2) = (input.next().unwrap(), input.next().unwrap(), input.next().unwrap());

    let mut result = 0;

    if (youki < (mizu1 + mizu2)) {
        result = mizu2 - (youki - mizu1);
    }

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

Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int find(int n){
  int x=0;
  
  while(n>0){
    x += n%10;
    n /= 10;
  }
  
  return x;
}
  

int main(){
  int N,A,B,X;
  int total=0;
  
  cin >> N >> A >> B;
  for(int i=0; i<=N; i++){
    X = find(i);
    if(A<=X && X<=B) total += i;
  }
  
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	int N=S.size();
	int ans=1;
	int twoflag=0;
	rep1(i,N-1){
		//printf("i:%d s:%c two:%d ans:%d\n",i,S[i],twoflag,ans);
		if(S[i]!=S[i-1]||twoflag){
			ans++;
			twoflag=0;
		}
		else{
			if(i!=N-1) ans++;
			i++;
			twoflag=1;
		}

	}
	prin(ans);
	return 0;
}


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

using namespace std;
ifstream fin("f.in");
ofstream fout("f.out");

#define hello cout << "hello" << endl
#define dbg(var) cout << #var << " --> " << var << endl
#define mset(a, b)  memset(a, b, sizeof(a))
#define vi vector<int>
#define vii vector<pair<int, int> >
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define boost ios_base::sync_with_stdio(false)

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int N = 1e5 + 10;

int suffix_sum1[N];
int suffix_sum2[N];
int main(){
	boost;
	string s, t;
	cin >> s >> t;
	int q;
	cin >> q;
	suffix_sum1[0] = (s[0] == 'A')? 1 : 2;
	for(int i = 1; i < s.length(); ++i){
		suffix_sum1[i] = suffix_sum1[i - 1];
		if(s[i] == 'A')
			suffix_sum1[i] += 1;
		else
			suffix_sum1[i] += 2;
	}
	suffix_sum2[0] = (t[0] == 'A')? 1 : 2;
	for(int i = 1; i < t.length(); ++i){
		suffix_sum2[i] = suffix_sum2[i - 1];
		if(t[i] == 'A')
			suffix_sum2[i] += 1;
		else 
			suffix_sum2[i] += 2;
	}
	while(q--){
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		// what's wrong with following two lines?
		// int x = suffix_sum1[b - 1] - suffix_sum1[a - 1] + (s[a - 1] == 'A')? 1 : 2;
		// int y = suffix_sum2[d - 1] - suffix_sum2[c - 1] + (t[c - 1] == 'A')? 1 : 2;

		int x = suffix_sum1[b - 1] - suffix_sum1[a - 1];
		int y = suffix_sum2[d - 1] - suffix_sum2[c - 1];
		if(s[a - 1] == 'A')
			x += 1;
		else 
			x += 2;
		if(t[c - 1] == 'A')
			y += 1;
		else
			y += 2;
		x %= 3;
		y %= 3;
		if(x == y){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1744
# https://atcoder.jp/contests/abc057/tasks/abc057_c
import numpy as np

N = int(input())
max_A = int(np.sqrt(N))

while max_A > 0:
    if N %  max_A == 0:
        B = N / max_A
        break
    else:
        max_A -= 1

digit_count = 0
while B >= 1:
    digit_count += 1    
    B /= 10

print(digit_count)

Measured memory_bytes: 12396
#include <stdio.h>

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

if(a==1||b==1){
        if(a==b)
            printf("Draw\n");
        else if(a<b)
            printf("Alice\n");
        else
            printf("Bob\n");
    } else{
        if(a>b)
            printf("Alice\n");
        else if(a==b)
            printf("Draw\n");
        else
            printf("Bob\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
using namespace std;
using ll = long long;

const int MAX = 200005;

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

	ll p1[MAX], p2[MAX];
	for (int x, i = 1; i <= N; i++) {
		scanf("%d", &x);
		p1[i] = x;
		p2[N + 1 - i] = L - x;
	}

	ll dp1[MAX] = { L - p1[N] }, dp2[MAX] = { L - p2[N] };
	ll ans = max(L - dp1[0], L - dp2[0]);

	for (int i = 1; i < N; i++) {
		dp1[i] = dp1[i - 1] + p1[N - (i - 1) / 2] + p1[N - i / 2] - 2 * p1[N - i];
		dp2[i] = dp2[i - 1] + p2[N - (i - 1) / 2] + p2[N - i / 2] - 2 * p2[N - i];
		ans = max({ ans, (i + 1ll) * L - dp1[i], (i + 1ll) * L - dp2[i] });
	}

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 6400
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	} 
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

map<ll, ll> mp;

int main(){
	ll N;
	cin >> N;

	REP(i, N){
		ll A;
		cin >> A;
		if(mp[A]>0){
			mp[A]--;
		}else{
			mp[A]++;
		}
	}
	ll res = 0;
	for(auto itr=mp.begin();itr!=mp.end();itr++){
		if(itr->second>0) res++;
	}
	cout << res << endl;
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int a = 0;
  for (int i = 0; i < S.size();i++){
    if(i %2== 0&&(S.at(i) == 'R'||S.at(i) == 'U'||S.at(i) =='D')){
      a++;
    }
    else if (i%2==1&&(S.at(i) == 'L'|| S.at(i) == 'U'||S.at(i) == 'D')){
      a++;
    }
  }
  if(a == S.size()){
    cout << "Yes"<< endl;
  }
  else {
    cout << "No" <<endl;
  }
}
  
      
      

    
    
  

Measured memory_bytes: 256
#include <stdio.h>
#define SUM(a,b) a+b

int main(void){
    int n,m,l,i,j,k;
    scanf("%d %d %d",&n,&m,&l);
    long long int buf=0, mat_a[n][m], mat_b[m][l], ans[n][l];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++) scanf("%ld",&mat_a[i][j]);
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++) scanf("%ld",&mat_b[i][j]);
    }

    for (i=0;i<n;i++){
        for (j=0;j<l;j++,buf=0){
            for (k=0;k<m;k++) buf=SUM(buf,mat_a[i][k]*mat_b[k][j]);
            ans[i][j] = buf;
        }
    }
    for (i=0;i<n;i++){
        for(j=0;j<l;j++){
            printf("%lld",ans[i][j]);
            if (j<l-1) printf(" ");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;


public class Main {
	static int N;
	static int[] flowers;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 flowers = new int[N];

		 for(int i = 0 ; i < N ; i++){
			 flowers[i] = sc.nextInt();
			 }
		 sc.close();

		 int ans = 0;
		 int cur = 0;

			 for(int k = 0 ; k < N ; k++){
				if(flowers[k]>cur){
					ans += flowers[k] - cur;
				 }
			cur = flowers[k];
			 }
		 System.out.println(ans);


	}
}


Measured memory_bytes: 23764
def check(m,d1,d10):
    if (d10>=2):
        if(d1>=2):
            if (d1*d10==m):
                return 1
    return 0
    
(M,D)=list(map(int,input().split()))
count=0
for m in range(1,M+1):
    for d in range(1,D+1):
        copy=d
        d1=copy%10
        copy=int(copy/10)
        d10=copy%10
        result=check(m,d1,d10)
        if(result==1):
            count=count+1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int a, b, k;

	cin>> k >> a >> b;

	for (int i = a;i <= b;i++) {
		if (i%k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}

	cout<< "NG" << endl;

}


Measured memory_bytes: 3632
def main():
    SFT = 8000

    CMDs = map(len, input().split('T'))
    X, Y = map(int, input().split())

    # [-SFT,SFT] -> [0,SFT*2]
    axis = 0
    curr = [1 << (next(CMDs) + SFT), 1 << SFT]
    for d in CMDs:
        axis ^= 1
        curr[axis] = (curr[axis] >> d) | (curr[axis] << d)

    cond = (curr[0] >> (SFT + X)) & 1 and (curr[1] >> (SFT + Y)) & 1
    print('Yes' if cond else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

w=input()
c=collections.Counter(w)
for k,i in c.items():
    if i%2==1:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 63980
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    long long answer, value, v_tmp;
    answer = 0;
    vector<long long> x, y, z;
    vector<long long> v;
    v.resize(8);
    cin >> n >> m;
    x.resize(n);
    y.resize(n);
    z.resize(n);
    for (int i=0; i<n; ++i){
        cin >> x[i] >> y[i] >> z[i];
    }
    v.resize(n);
    for (int k=0; k<8; ++k){
        value = 0;
        for (int i=0; i<n; ++i){
            switch(k){
            case 0:
                v_tmp = x[i] + y[i] + z[i];
                break;
            case 1:
                v_tmp = x[i] + y[i] - z[i];
                break;
            case 2:
                v_tmp = x[i] - y[i] + z[i];
                break;
            case 3:
                v_tmp = x[i] - y[i] - z[i];
                break;
            case 4:
                v_tmp = (-1 * x[i]) + y[i] + z[i];
                break;
            case 5:
                v_tmp = (-1 * x[i]) + y[i] - z[i];
                break;
            case 6:
                v_tmp = (-1 * x[i]) - y[i] + z[i];
                break;
            case 7:
                v_tmp = (-1 * x[i]) - y[i] - z[i];
                break;
            }
            v[i] = v_tmp;
            //cout << v_tmp << endl;
        }
        sort(v.begin(), v.end(), std::greater<long long>());
        for (int j=0; j<m; ++j){
            value += v[j];
        }
        answer = max(answer, abs(value));
    }
    cout << answer << endl;
}

Measured memory_bytes: 760
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for b in range(N):
    for a in range(b):
        ab = L[a]+L[b]
        r = bisect.bisect_left(L, ab)
        l = b+1
        ans += max(0, r-l)
print(ans)


Measured memory_bytes: 43100
class RollingHash:

    def __init__(self, string, root, mod):
        self.root = root
        self.mod = mod
        self.hs = [0] * (len(string) + 1)
        self.pw = [1] * (len(string) + 1)
        for i in range(len(string)):
            self.hs[i + 1] = (self.hs[i] * self.root + ord(string[i])) % self.mod
            self.pw[i + 1] = self.pw[i] * self.root % self.mod

    def get_hash(self, l, r):
        "get the hash of s[l:r] (0 <= l <= r <= len(s))"
        return (self.hs[r] - self.hs[l] * self.pw[r - l]) % self.mod

    def __getitem__(self, index):
        if isinstance(index, slice):
            return self.get_hash(index.start, index.stop)
        else:
            return 0


RHMOD = (1 << 61) - 1
POSITIVIZER = RHMOD << 61
class RollingHashMOD61:
    """
    MOD == 2 ** 61 - 1
    参考: https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
    """


    def __init__(self, string, root):
        self.root = root
        self.hs = [0] * (len(string) + 1)
        self.pw = [1] * (len(string) + 1)
        for i in range(len(string)):
            tmp = self.hs[i] * self.root + ord(string[i])
            self.hs[i + 1] = (tmp >> 61) + (tmp & RHMOD)
            tmp = self.pw[i] * self.root
            self.pw[i + 1] = (tmp >> 61) + (tmp & RHMOD)

    def get_hash(self, l, r):
        "get the hash of s[l:r] (0 <= l <= r <= len(s))"
        ret = (self.hs[r] - self.hs[l] * self.pw[r - l] + POSITIVIZER)
        ret = (ret >> 61) + (ret & RHMOD)
        if ret >= RHMOD:
            ret -= RHMOD
        return ret

    def __getitem__(self, index):
        if isinstance(index, slice):
            return self.get_hash(index.start, index.stop)
        else:
            return 0
        
if __name__ == "__main__":
    N = int(input())
    S = input()

    MOD = 2 ** 61 - 1
    root = 10000

    rh = RollingHashMOD61(S, root)

    ok = 0
    ng = N
    while ng - ok > 1:
        mid = (ok + ng) // 2
        hashes = dict()
        flg = False
        for i in range(N - mid + 1):
            hashofsub = rh[i:i+mid]
            if hashofsub in hashes:
                if i >= hashes[hashofsub] + mid:
                    flg = True
                    break
            else:
                hashes[hashofsub] = i
        
        if flg:
            ok = mid
        else:
            ng = mid

    print(ok)


Measured memory_bytes: 75988
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto ns = readln.split.to!(int[]);
    auto N = ns[0];
    auto A = ns[1];
    auto B = ns[2];
    auto C = ns[3];
    int[] ls;
    foreach (_; 0..N) ls ~= readln.chomp.to!int;

    auto as = new int[](N);
    int solve(int i) {
        if (i == N) {
            int a, b, c, an, bn, cn;
            foreach (j; 0..N) {
                switch (as[j]) {
                    case 1: a += ls[j]; ++an; break;
                    case 2: b += ls[j]; ++bn; break;
                    case 3: c += ls[j]; ++cn; break;
                    default:
                }
            }
            if (an == 0 || bn == 0 || cn == 0) return int.max;
            return abs(A - a) + abs(B - b) + abs(C - c) + (an-1)*10 + (bn-1)*10 + (cn-1)*10;
        } else {
            int r = int.max;
            foreach (j; 0..4) {
                as[i] = j;
                r = min(r, solve(i+1));
            }
            return r;
        }
    }
    writeln(solve(0));
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <cmath>
 
class PrimeNumberChecker {
public:
    PrimeNumberChecker() {
        m_checkedPrimeNumSet.insert(2);
    }
    ~PrimeNumberChecker() {}
    bool isPrimeNumber(const int& x);
private:
    std::set<int> m_checkedPrimeNumSet;
};
 
bool PrimeNumberChecker::isPrimeNumber(const int& x) {
    if (x <= 1) {
        return false;
    }
    if (m_checkedPrimeNumSet.find(x) != m_checkedPrimeNumSet.end()) {
        return true;
    }
    if (x % 2 == 0) {
        return false;
    }
    for (int i = 3; i <= std::sqrt(x); i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}
 
int main(int argc, const char *argv[]) {
    int n;
    std::cin >> n;
    PrimeNumberChecker checker;
    int ret = 0;
    for (int i = 0, x; i < n && std::cin >> x; i++) {
        if (checker.isPrimeNumber(x)) {
            ret++;
        }
    }
    std::cout << ret << std::endl;
    return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    vector<int> a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    c[0] = a[n - 1] ^ a[0];
    d[0] = b[n - 1] ^ b[0];
    for (int i = 1; i < n; i++) {
        c[i] = a[i - 1] ^ a[i];
        d[i] = b[i - 1] ^ b[i];
    }

    ll h = 0;
    for (int i = 0; i < n; i++) {
        h <<= 31;
        h += d[i];
        h %= P;
    }
    ll h0 = h;

    h = 1;
    for (int i = 0; i < n; i++) {
        h <<= 31;
        h %= P;
    }
    ll h1 = h;

    h = 0;
    for (int i = 0; i < n; i++) {
        h <<= 31;
        h += c[i];
        h %= P;
    }
    for (int i = 0; i < n; i++) {
        if (h == h0) {
            cout << i << ' ' << (a[i] ^ b[0]) << '\n';
        }
        h <<= 31;
        h -= c[i] * h1;
        h += c[i];
        h %= P;
        if (h < 0) h += P;
    }

    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j

int lbidx(vector<int> x, int y) {
  auto itr = lower_bound(x.begin(), x.end(), y);
  int idx = itr - x.begin();
  return idx;
};

int upidx(vector<int> x, int y) {
  auto itr = upper_bound(x.begin(), x.end(), y);
  int idx = itr - x.begin();
  return idx;
}

ll n,q;
ll s[200100],t[200100],x[200100];
ll d[200100];
struct road{
	ll sx;
	ll a_d;
	ll dis;
	road(ll _sx,ll _a_d,ll _dis){
		sx=_sx;
		a_d=_a_d;
		dis=_dis;
	}
	bool operator<(road &r2){
		if(sx!=r2.sx){
			return sx<r2.sx;
		}else {
			return a_d<r2.a_d;
		}
	}
};
vector<road> rr;
ll ans[200100];
int main(){
	cin>>n>>q;
	for(ll i=0;i<n;i++)cin>>s[i]>>t[i]>>x[i];
	for(ll i=0;i<q;i++)cin>>d[i];
	for(ll i=0;i<n;i++){
		rr.push_back(road(s[i]-x[i],1,x[i]));
		rr.push_back(road(t[i]-x[i],-1,x[i]));
	}
	sort(rr.begin(),rr.end());
	// rep(i, 0, rr.size())cout<<rr[i].sx<<" "<<rr[i].a_d<<" "<<rr[i].dis<<endl;
	set<ll> t1;
	ll t=0;
	for(ll i=0;i<q;i++){

		while(t<rr.size()&&rr[t].sx<=d[i]){
			//cout<<i<<" "<<t<<endl;
			if(rr[t].a_d==1){
				t1.insert(rr[t].dis);
			}else{
				t1.erase(rr[t].dis);
			}
			t++;
			//cout<<t1.size()<<endl;
			//cout<<i<<" "<<t<<endl;
		}
		if(t1.empty())cout<<-1<<endl;
		else cout<<*t1.begin()<<endl;
	}
	//REP(i,q)cout<<ans[i]<<endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(i, n)  for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    int a, b, ab, x, y;
    cin >> a >> b >> ab >> x >> y;

    int ans = 0;

    if((a + b) <= (ab * 2)) {
        ans = (a * x) + (b * y);
    }else {
        int mn = min(x, y);
        int mx = max(x, y);

        // abのみで買いそろえる
        ans = ab * (mx * 2);

        // abと単体で揃える
        int tmp = ab * (mn * 2);

        if(mx == x) tmp += a * (mx - mn);
        else        tmp += b * (mx - mn);

        ans = min(ans, tmp);
    }

    cout << ans;
}

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

using namespace std;

class Square {
public:
	int num_h, num_w;
};

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

	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}

	vector<vector<Square>> square(h, vector<Square>(w));
	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;
			if (i == 0 || s[i - 1][j] == '#') {
				int tmp = 0;
				while (1) {
					tmp++;
					if (i + tmp == h || s[i + tmp][j] == '#') {
						break;
					}
				}
				square[i][j].num_h = tmp;
			}
			else {
				square[i][j].num_h = square[i - 1][j].num_h;
			}
			if (j == 0 || s[i][j - 1] == '#') {
				int tmp = 0;
				while (1) {
					tmp++;
					if (j + tmp == w || s[i][j + tmp] == '#') {
						break;
					}
				}
				square[i][j].num_w = tmp;
			}
			else {
				square[i][j].num_w = square[i][j - 1].num_w;
			}
			ans = max(ans, square[i][j].num_h + square[i][j].num_w - 1);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[110] ={}, b[110]={};
    for(int i=1; i<=n-1; i++){
        cin >> b[i];
    }
    a[1]= b[1];
    for(int i=2; i<=n-1; i++){
        a[i] = min(b[i], b[i-1]);
    }
    a[n] = b[n-1];
    int ans = 0;
    for(int i=1; i<=n; i++){
       ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll A, B;
    cin >> A >> B;

    if(A == 2 || B == 2){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
int cnt[401];
int a[401][401];
int u[401];
 
int main () {
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			cin >> a[i][j];
		}
	}
	int kol = 0;
	int ans = 1e9;
	while (kol < m) {
		for (int i = 1;i <= n;i ++) {
			for (int j = 1;j <= m;j ++) {
				if (!u[a[i][j]]) {
					cnt[a[i][j]] ++;
					break;
				}
			}
		}
		int mx = 0;
		for (int i = 1;i <= m;i ++) {
			if (cnt[i] > cnt[mx]) {
				mx = i;                     	
			}
		}  	
		u[mx] = 1;
		kol ++;
		ans = min (ans, cnt[mx]);
		memset (cnt, 0, sizeof cnt);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<string>
#include<tuple>
#include<algorithm>

using namespace std;

int main(){
    int N,K;
    string S;

    cin >> N >> K;
    cin >> S;

    S[K-1] = S[K-1] + 0x20;

    cout << S;

}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):    
            t = 500 * a + 100 * b + 50 * c
            if t == X:
                ans += 1
print(ans)

Measured memory_bytes: 39664
#include <stdio.h>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

#define NUM 8
#define NIL -1

bool canPlace[NUM][NUM];
vector<pair<int,int>> Qs;

void print__(){
    printf("\n");
    for(int i = 0; i < NUM; i++){
        for(int j = 0; j < NUM; j++){
            if(canPlace[j][i]){
                printf("x");
            }else{
                printf("o");
            }
        }
        printf("\n");
    }
    printf("\n");
}

void print_(){
    char board[NUM][NUM];
    for(int i = 0; i < NUM; i++){
        for(int j = 0; j < NUM; j++){
            board[i][j] = '.';
        }
    }

    for(int i = 0; i < Qs.size(); i++){
        board[Qs[i].first][Qs[i].second] = 'Q';
    }
    for(int i = 0; i < NUM; i++){
        for(int j = 0; j < NUM; j++){
            printf("%c", board[j][i]);
        }
        printf("\n");
    }
}

pair<int, int> getNextPos(int x, int y){
    for(int j = y; j < NUM; j++){
        for(int i = 0; i < NUM; i++){
            if(canPlace[i][j] == true){
                continue;
            }
            if(j == y && i <= x){
                continue;
            }
            return make_pair(i, j);
        }
    }
    return make_pair(NIL, NIL);
}

void push_Q(int x, int y){
    for(int i = 0; i < NUM; i++){
        canPlace[i][y] = true;
        canPlace[x][i] = true;
    }
    for(int i = 0; i < NUM; i++){
        if(0 <= -x + y + i && -x + y + i < NUM){
            canPlace[i][-x + y + i] = true;
        }
        if(0 <= x + y - i && x + y - i < NUM){
            canPlace[i][x + y - i] = true;
        }
    }
    Qs.push_back(make_pair(x, y));
}

void init(void);

pair<int, int> pop_Q(){
    pair<int, int> p = Qs[Qs.size() - 1]; Qs.pop_back();

    init();
    for(int k = 0; k < Qs.size(); k++){
        int x = Qs[k].first; int y = Qs[k].second;
        for(int i = 0; i < NUM; i++){
            canPlace[i][y] = true;
            canPlace[x][i] = true;
        }
        for(int i = 0; i < NUM; i++){
            if(0 <= -x + y + i && -x + y + i < NUM){
                canPlace[i][-x + y + i] = true;
            }
            if(0 <= x + y - i && x + y - i < NUM){
                canPlace[i][x + y - i] = true;
            }
        }
    }
    return p;
}

void init(void){
    for(int i = 0; i < NUM; i++){
        for(int j = 0; j < NUM; j++){
            canPlace[i][j] = false;
        }
    }
}

int main(void){
    init();

    int k;
    scanf("%d", &k);

    for(int i = 0; i < k; i++){
        int r, c;
        scanf("%d %d", &r, &c);
        push_Q(c, r);
    }

    pair<int, int> p = getNextPos(-1, 0);

    while(Qs.size() != NUM){
        //print_();
        //print__();
        if(p.first == NIL){
            pair<int, int> p_before = pop_Q();
            p = getNextPos(p_before.first, p_before.second);
            continue;
        }
        push_Q(p.first, p.second);
        p = getNextPos(-1, 0);
    }

    print_();
}



Measured memory_bytes: 3156