akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

bool isWhiteRow(int, vector<vector<char>>);
bool isWhiteCol(int, vector<vector<char>>);

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> table[i][j];
    }
  }
  
  vector<int> col(0); //列
  vector<int> row(0); //行
  
  for(int i = 0; i < H; i++) {
    if (!isWhiteRow(i, table))
      row.push_back(i);
  }
  for(int j = 0; j < W; j++) {
    if (!isWhiteCol(j, table))
      col.push_back(j);
  }
  
  for(int i = 0; i < row.size(); i++) {
    for(int j = 0; j < col.size(); j++) {
      cout << table[row[i]][col[j]];
    }
    cout << endl;
  }
}

bool isWhiteRow(int i, vector<vector<char>> table) {
  for(int j = 0; j < table[i].size(); j++) {
    if (table[i][j] != '.')
      return false;
  }
  return true;
}

bool isWhiteCol(int j, vector<vector<char>> table) {
  for(int i = 0; i < table.size(); i++) {
    if (table[i][j] != '.')
      return false;
  }
  return true;
}


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

using namespace std;

int main()
{
  int N, A, B;
  int TA;
  
  cin >> N >> A >> B;
  
  TA = N * A;
  
  if(TA < B){
    cout << TA << endl;
  }
  else{
    cout << B << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main{
        static void printArray(int[] A){
                for(int i=0; i<A.length; i++){
                        System.out.print(A[i]);
                        if(i != A.length-1)
                                System.out.print(" ");
                }
                System.out.println();
        }
        public static void main(String[] args){
                Scanner scanner = new Scanner(System.in);
                int N = scanner.nextInt();
                int[] A = new int[N];
                for(int i=0; i<N; i++){
                        A[i] = scanner.nextInt();
                }

                for(int i=1; i<N; i++){
                        int key = A[i];
                        int j = i-1;
                        printArray(A);
                        while(j>=0 && A[j]>key){
                                A[j+1] = A[j];
                                j--;
                        }
                        A[j+1] = key;
                }
                printArray(A);
        }
}

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

using namespace std;

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

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

  vector<int> Xs {X};
  sort(begin(Xs),end(Xs));

  const int x {Xs[N/2-1]};
  const int y {Xs[N/2]};

  for(int i = 0; i < N; ++i){
    if(X[i] > x) cout << x;
    else cout << y;
    cout << endl;
  }
}

Measured memory_bytes: 3712
import Control.Monad
import Data.List
import Data.Maybe

main = do
  s <- getLine
  k <- readLn
  putChar $ solve s k

solve :: String -> Integer -> Char
solve (c : s) k
  | k == 1 = c
  | c /= '1' = c
  | otherwise = solve s (k - 1)

Measured memory_bytes: 3896
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main(){
   int n,k,q;
   cin >> n >> k >> q;
   vector<int> human(n);
   rep(i,n) human[i] = 0;

   rep(i,q){
      int current;
      cin >> current;
      human[current-1]++;
   }
   rep(i,n){
      if(k-(q-human[i])>0) cout << "Yes" << endl;
      else cout << "No" << endl;
   }
   return 0;
}


Measured memory_bytes: 1024
from operator import itemgetter


def main():
    n, m = list(map(int, input().split()))
    alist = list(map(int, input().split()))
    bc = []
    for _ in range(m):
        b, c = list(map(int, input().split()))
        bc.append((b, c))

    xy = [(1, ai) for ai in alist] + bc
    rest = n
    total = 0
    for number, score in sorted(xy, key=itemgetter(1), reverse=True):
        if rest <= number:
            total += score * rest
            break
        else:
            total += score * number
            rest -= number

    print(total)


main()

Measured memory_bytes: 33992
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main() {
  int N;
  cin >>N;
  
  
  vector<string> si(N);
  vector<int> ti(N); 
  for(int i=0;i<N;i++){
    cin>>si.at(i)>>ti.at(i);
  }
  
  string X;
  cin>>X;
  
  int index;
  for(int i=0;i<N;i++){
    if(si.at(i)==X){
      index=i;
      break;
    }
  }
 
  int sum=0;
  for(int i=index+1;i<N;i++){
    sum+=ti.at(i);
  }
  
  cout<<sum;
  
  return 0;
}

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

int main(){
  int i,j,k,max=0,max2=0;;
  int N;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d ",&A[i]);
    if(max < A[i]){
      max = A[i];
      j=i;
    }
  }
  
  for(i=0;i<N;i++){
    if(i !=j)
      printf("%d\n",max);
    else{
      for(k=0;k<N;k++){
        if(k!=j){
          if(max2 < A[k])
            max2=A[k];
        }
      }
      printf("%d\n",max2);
    }
  }
  return 0;
}
          
    

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n; string s;
    vector<string> v;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s;
        v.push_back(s);
    }
    for(int i = 0; i < n - 1; i++){
        if(v[i].back() != v[i+1].front()){
            cout << "No" << endl;
            exit(0);
        }
        for(int j = 0; j < n; j++){
            if(i != j && v[i] == v[j]){
                cout << "No" << endl;
                exit(0);
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int solve(a,b,c)
        int a;
        int b;
        int c;
{
    return (a*a+b*b)==(c*c);
}
int isort(a,b)    
        const void *a;    
        const void *b;    
{    
    if     (*(int*)a <  *(int*)b) return -1;    
    else if(*(int*)a == *(int*)b) return  0;    
    return 1;    
}
int main()
{
    int N,i,ret;
    int sides[3];
    scanf("%d",&N);
    while (N--)
    {
        for (i=0;i<3;i++) scanf("%d",&sides[i]);
        qsort((void*)sides, 3, sizeof(sides[0]), isort);
        ret = solve(sides[0],sides[1],sides[2]);
        printf("%s\n", ret? "YES":"NO");
    }
    return 0;
}

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

int main(void)
{
	std::string s;
	std::cin>>s;
	int n = (int)s.size();
	int lln = 0;
	for(int i=0;i<n;i++)
	{
		bool ok = 1;
		for(int j=i;j<n;j++)
		{
			if(s[j] != 'A' && s[j] != 'G' && s[j] != 'C' && s[j] != 'T')
			{
				ok = 0;
				break;
			}
			else lln = std::max(lln, (j - i + 1));
		}	
	}
	std::cout<<lln<<"\n";
	return 0;
}

Measured memory_bytes: 256
import itertools,math,bisect,pprint,sys

n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
def use_d(n):
    for i in list(str(n)):
        if int(i) in d:
            return True
    else:
        return False
while n < 100000:
    if use_d(n):
        n += 1
    else:
        print n
        sys.exit()


Measured memory_bytes: 3836
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 130;
int ans[MAXN][MAXN];
vector<int> v1;
int main(){
    int h,w;
    cin>>h>>w;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        for(int j=0;j<x;j++){
            v1.push_back(i);
        }
    }
    int ptr = 0;
    for(int i=1;i<=h;i++){
        if(i%2){
            for(int j=1;j<=w;j++){
                ans[i][j] = v1[ptr];
                ptr++;
            }
        }else{
            for(int j=w;j>=1;j--){
                ans[i][j] = v1[ptr];
                ptr++;
            }
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n%1000==0)cout<<0<<endl;
	  else{
	  	for(int i=1;i<=10;i++)
	  	  if(1000*i>n){ cout<<1000*i-n<<endl;return 0;}
	  }
	return 0;
}

Measured memory_bytes: 3172
#include <iostream>
using namespace std;
using ll = long long;

int main() {
	ll x, a, b, kuri = 1, flag = 0;
	cin >> x;
	while (!flag) {
		for (a = 1; a <= kuri; a++) {
			for (b = a * (-1); b <= a; b++) {
				if (a * a * a * a * a - b * b * b * b * b == x) {
					flag = 1;
					break;
				}
			}
			if (flag == 1)
				break;
		}
		kuri++;
	}

	cout << a << " " << b << endl;
}

Measured memory_bytes: 3632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class APoor {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      vector<int> a(3);
      rep(i, 3) cin >> a[i];
      sort(all(a));
      if (a[0] == a[1] && a[1] != a[2]) {
        cout << "Yes" << endl;
        return;
      }
      if (a[0] != a[1] && a[1] == a[2]) {
        cout << "Yes" << endl;
        return;
      }
      cout << "No" << endl;
    }
};

signed main() {
  APoor solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n*n);

    vector<vector<bool> > isEmpty(n+2, vector<bool>(n+2, true));
    vector<vector<int> > cost(n+2, vector<int>(n+2, 0));
    for(int y=1; y<=n; ++y){
        for(int x=1; x<=n; ++x){
            isEmpty[y][x] = false;
            cost[y][x] = min({y, x, n+1-y, n+1-x});
        }
    }

    int ans = 0;
    for(int i=0; i<n*n; ++i){
        int p;
        cin >> p;
        -- p;
        int sy = p / n + 1;
        int sx = p % n + 1;

        isEmpty[sy][sx] = true;
        -- cost[sy][sx];
        ans += cost[sy][sx];

        queue<pair<int, int> > q;
        q.push(make_pair(sy, sx));
        while(!q.empty()){
            auto [y, x] = q.front();
            q.pop();
            for(int j=0; j<4; ++j){
                int y2 = y + dy[j];
                int x2 = x + dx[j];
                int tmp = cost[y][x] + (isEmpty[y2][x2] ? 0 : 1);
                if(tmp < cost[y2][x2]){
                    cost[y2][x2] = tmp;
                    q.push(make_pair(y2, x2));
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5368
void main() {
  problem();
}

void problem() {
  auto K = scan!int;
  auto A = scan!int;
  auto B = scan!int;

  bool solve() {
    foreach(i; A..B+1) {
      if (i % K == 0) return true;
    }

    return false;
  }

  writeln(solve() ? "OK" : "NG");
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 2704
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int a;
int b;
int main(){
	scanf("%d %d", &a, &b);
	if (b%a == 0){
		printf("%d\n", b+a);
	}
	else {
		printf("%d\n", b-a);
	}
	return 0;
}


Measured memory_bytes: 128
n, m = gets.split.map(&:to_i)
card = gets.split.map(&:to_i)

op    = []

m.times do
  tmp = gets.split.map(&:to_i)
  op << tmp
end

op   = op.sort_by{|ary| ary[1]}.reverse
card = card.sort
cnt  = 0
ans  = 0

while card.size > 0 && op.size > 0
  if card[0] < op[0][1]
    op[0][0] -= 1
    ans += op[0][1]
    if op[0][0] == 0
      op.shift
    end
    card.shift
  else
    ans += card.shift
  end
end

if card.size > 0
  ans += card.inject(:+)
end

puts ans


Measured memory_bytes: 20832
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  if(A) cout<<N/(A+B)*A+min(A,N%(A+B))<<endl;
  else cout<<0<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
      	if (n == 1 && a== b) {
          System.out.println(1);
          return;
        }
        if (n < 2 || a > b) {
            System.out.println(0);
            return;
        }
        System.out.println((n - 2) * (b - a) + 1);
    }

}

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

using namespace std;
using ll = long long;

struct item {
  ll a, b;
};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<item> vec(n);
  for (auto &v : vec) {
    cin >> v.a >> v.b;
  }

  sort(vec.begin(), vec.end(), [](auto &lhs, auto &rhs) { return lhs.a < rhs.a; });

  ll ans = 0;
  ll cnt = 0;
  for (auto &v : vec) {
    ll tmp = min(m, cnt + v.b);
    ans += (tmp - cnt) * v.a;
    cnt = tmp;
    if (cnt == m)
      break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4828
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long x;
	cin>>x;
	long long y=x/11;
	long long z=x%11;
	if(z!=0){
		if(z<=6)z=1;
		else z=2;
	}
	long long ans=y*2+z;
	cout<<ans<<endl;
	return 0;
}
 

Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = sc.nextInt();
		String s = sc.next();
		char before = '1';

		for (char c : s.toCharArray()) {
			if (before == c)
				n--;
			before = c;
		}

		System.out.println(n);
	}

}


Measured memory_bytes: 26068
#include <bits/stdc++.h>
#define N 106
using namespace std;
int n,p[N][26];char s[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=strlen(s+1);j++)p[i][s[j]-97]++;
	}
	for(int i=0;i<26;i++){
		int mi=p[1][i];
		for(int j=2;j<=n;j++)mi=min(mi,p[j][i]);
		for(int j=1;j<=mi;j++)putchar(i+97);
	}puts("");
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
  {
    cin >> h[i];
  }
  vector<int> ans(n, 1);
  for (int i = 0; i < m; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;

    if (h[a] >= h[b])
    {
      ans[b] = 0;
    }
    if (h[a] <= h[b])
    {
      ans[a] = 0;
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++)
  {
    if (ans[i])
    {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define sc second
using namespace std;

const int N = 1e5 + 5;

int d[N], v[N];
vector<int> adj[N];

int dfs(int i) {
	v[i] = 1;
	for (int j = 0; j < (int) adj[i].size(); j++) {
		int t = adj[i][j];
		if (v[t]) t = d[t] + 1; else t = dfs(t);
		d[i] = max(d[i], t);
	}
	return d[i] + 1;
}

int main() {
	int n, m; cin >> n >> m;
	ii s[N];
	for (int i = 1; i <= n; i++) {
		s[i].second = i;
	}
	for (int i = 1; i <= m; i++) {
		int u, v; cin >> u >> v;
		adj[v].push_back(u);
		s[u].first += 1;
	}
	sort(s + 1, s + n + 1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!v[s[i].second]) {
			dfs(s[i].second);
			ans = max(ans, d[s[i].second]);
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 15252
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long ko[4];
    ko[0] = a*c;
    ko[1] = a*d;
    ko[2] = b*c;
    ko[3] = b*d;
    sort(ko,ko+4);
    cout<<ko[3];
    return 0;
}

Measured memory_bytes: 3184
#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;
}

ll N;

double dp[305][305][305];

double rec(ll c1, ll c2, ll c3){
	if(dp[c1][c2][c3]>=0) return dp[c1][c2][c3];
	if(c1==0&&c2==0&&c3==0) return 0.0;
	ll c0 = N - c1 - c2 - c3;
	double tmp = 0;
	if(c1>0) tmp += ((1.0*c1)/N)*(1+rec(c1-1, c2, c3));
	if(c2>0) tmp += ((1.0*c2)/N)*(1+rec(c1+1, c2-1, c3));
	if(c3>0) tmp += ((1.0*c3)/N)*(1+rec(c1, c2+1, c3-1));
	double p = (1.0*c0)/N;
	double res = (p+tmp)/(1.0-p);
	dp[c1][c2][c3] = res;
	return res;
}

int main(){
	cin >> N;
	vector<ll> a(N);
	REP(i, N) cin >> a[i];

	vector<ll> count(4, 0);
	REP(i, N) count[a[i]]++;
	REP(i, 305)REP(j, 305)REP(k, 305) dp[i][j][k] = -1;

	printf("%.15f\n", rec(count[1], count[2], count[3]));
    return 0;
}

Measured memory_bytes: 221952
import bisect

a, b, q = map(int, input().split())
ans = 0

shrine = []
temple = []

for i in range(a):
    s = int(input())
    shrine.append(s)

for i in range(b):
    t = int(input())
    temple.append(t)


for j in range(q):
    shrine_list = []
    temple_list = []
    query = int(input())
    shrine_index = bisect.bisect_left(shrine, query)
    temple_index = bisect.bisect_left(temple, query)
    if shrine_index == 0:
        shrine_list.append(shrine[shrine_index])
    elif shrine_index == len(shrine):
        shrine_list.append(shrine[shrine_index-1])
    else:
        shrine_list.append(shrine[shrine_index])
        shrine_list.append(shrine[shrine_index-1])
    if temple_index == 0:
        temple_list.append(temple[temple_index])
    elif temple_index == len(temple):
        temple_list.append(temple[temple_index-1])
    else:
        temple_list.append(temple[temple_index])
        temple_list.append(temple[temple_index-1])
    min_dist = 10**12
    for sh in shrine_list:
        for tm in temple_list:
            if sh < query < tm:
                dist = min(tm - sh + (query - sh), tm - sh + (tm - query))
            elif tm < query < sh:
                dist = min(sh - tm + (query - tm), sh - tm + (sh - query))
            elif min(query, sh, tm) == query:
                dist = max(sh, tm) - query
            elif max(query, sh, tm) == query:
                dist = query - min(sh, tm)
            if dist < min_dist:
                min_dist = dist
    print(min_dist)



Measured memory_bytes: 12092
#include <bits/stdc++.h>
using namespace std ;
int func(vector<int> &h,vector<int> &best,int n){
    if(n==0&&best[0]==-1) best[0] = 0 ;
    else if(n==1&&best[1]==-1) best[1] = abs(h[1]-h[0]) ;
    else if(best[n]==-1) best[n] = min(abs(h[n]-h[n-1])+func(h,best,n-1),abs(h[n]-h[n-2])+func(h,best,n-2)) ;
    return best[n] ;
}
int main(){
    int n , i ; 
    cin >> n ;
    vector<int> h(n) , best(n,-1) ;
    for(i=0;i<n;++i) cin >> h[i] ;
    best[0] = 0 ;
    best[1] = abs(h[1]-h[0]) ;
    cout << func(h,best,n-1) << "\n" ;
    return 0 ;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, k;
int main() {
	cin >> n >> k;
	vector<ll> s(n);
	REP(i, n)cin >> s[i];
	sort(ALL(s));
	ll ans = 0;
	REP(i, n - k) ans += s[i];
	cout << ans << endl;
}


Measured memory_bytes: 1792
# 解説AC
from fractions import gcd
def judge(A,B,C,D):
    """
    在庫数をXとする。
    C < X < B のときFalse
    p,qを0以上の整数とすると、
    X = A + D * p - B * q 
    X = A % G + k * G

    C + 1 <= X
    -> k = ceil((C + 1 - A % G) / G)
    """

    if A < B: return False
    if D < B: return False
    if C >= B: return True
    
    G = gcd(B, D)
    k = (C - (A % G) + G) // G
    return False if ((A % G + k * G) < B) else True

T = int(input())
for _ in range(T):
    A,B,C,D = map(int, input().split())
    if judge(A,B,C,D): print('Yes')
    else: print('No')

Measured memory_bytes: 5304
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n,a,b; cin >> n >> a >> b;
    cout << (n/(a+b))*a + min((n%(a+b)),a) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
	int n,cnt=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i+=2)
	{
		if(a[i]%2)
			cnt++;
	}
	cout<<cnt;

	return 0;
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a > k) {
    cout << ":(" << endl;
  }
  else if (e - b > k) {
    cout << ":(" << endl;
  }
  else if (e - c > k) {
    cout << ":(" << endl;
  }
  else if (e - d > k) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }
}


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

int main(void)
{
	int n, x;
	cin >> n >> x;
	vector<int> m(n);
	for (int i = 0; i < n; i++)
		cin >> m[i];

	sort(m.begin(), m.end());
	int remain = x - accumulate(m.begin(), m.end(), 0);
	cout << m.size() + remain / m[0] << endl;

	return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
s = [input() for _ in range(h)]

for i in range(h):
    l = ''
    for j in range(w):
        if s[i][j] == '#':
            l += s[i][j]
        else:
            l += str(sum([t[max(0,j-1):min(j+2,w)].count('#')\
                     for t in s[max(0,i-1):min(h,i+2)]]))
    print(l)

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

int main(){
  int n,t,a,h[1000],ans;
  double c[1000],hoge,k;
  cin >>n>>t>>a;
  ans = 0;
  for(int i=0;i<n;i++){
    cin >> h[i];
    c[i] = t -0.006*h[i];
    hoge = c[ans] - a;
    k = c[i] -a;
    if(hoge<0)hoge = -1*hoge;
    if(k<0)k= -1*k;
    
    if(hoge > k) ans = i;
  }
  cout << ++ans << endl;
}
    

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

using namespace std;

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 


int main(){
    int n_jobs;
    cin >> n_jobs;

    vector< pair <int,int> > jobs;

    for(int i=0; i<n_jobs; ++i){
        vector<int> temp;
        int temp_cost_time, temp_deadline;
        cin >> temp_cost_time;
        cin >> temp_deadline;
        jobs.push_back( make_pair(temp_cost_time, temp_deadline) );
    }

    sort(jobs.begin(), jobs.end(), sortbysec);

    // check
    // for (vector< pair <int,int> >::iterator it = jobs.begin(); it != jobs.end(); ++it){
    //     cout << (*it).first << " " << (*it).second << endl;
    // }

    int job_sum = 0;
    for (vector< pair <int,int> >::iterator it = jobs.begin(); it != jobs.end(); ++it){
        job_sum += (*it).first;
        if(job_sum > (*it).second){
            cout << "No" << endl;
            return 0;
        }
        // cout << (*it).first << " " << (*it).second << endl;
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 2420
using System;

class Program
{
    static void Main(string[] args)
    {
        //入力
        string S = Console.ReadLine();

        Console.WriteLine( ManyFormulas(S, 0) );

    }

    static ulong ManyFormulas(string s, int begin)
    {
        ulong ret = 0;
        for(int i = begin; i < s.Length; i++)
        {
            ret += (ulong.Parse(s.Substring(begin, i - begin + 1)) << Math.Max(0, s.Length - i - 2));
            ret += ManyFormulas(s, i + 1);
        }
        return ret;
    }
}


Measured memory_bytes: 11348
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());
		Integer[] L2 = new Integer[2*N];
		String[] L = br.readLine().split(" ");
		for(int i=0;i<L.length;i++){
			L2[i] = Integer.parseInt(L[i]);
		}
		
		int sum = 0;
		Arrays.sort(L2);
		for(int i=L2.length-1;i>0;i-=2){
			sum += Math.min(L2[i], L2[i-1]);
		}
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 8020
// ABC067_A.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
	return 0;
}



Measured memory_bytes: 256
#import <Foundation/Foundation.h>
int main() {
  int N;
  scanf("%d", &N);
  NSInteger n = 1;
  NSInteger result;
  while(N >= n) {
    
    if (N < n * 10 - 1) {
      result += N - n + 1;
    } else {
      result += 9 * n;
    }
    
    n *= 100;
    
  }
  
  printf("%d", result);
  return 0;
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int N;
int main() {
  cin >> N;
  int ans =0;
  for (int i=1; i<=N; i+=2) {
    int cnt = 0;
    for (int j=1; j<=i;j++) {
      if (i%j==0) cnt++;
    }
    if (cnt == 8) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String N = br.readLine();
		
		if (N.contains("9")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	
	}
 
}


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

int main(){
    ll n, x, t; cin >> n >> x >> t;
    if(n % x == 0) put(n / x * t);
    else put((n / x + 1) * t);
}

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

int main(){
    long long n;
    cin>>n;
    vector<long long>v(n);
    for(long long i=0;i<n;i++){
        cin>>v[i];
    }
    for(long long i=0;i<n;i++){
        v[i]=v[i]-i-1;
    }
    sort(v.begin(),v.end());
    long long a=v[n/2];
    long long ans=0;
    for (int i = 0; i < n; i++){
		ans = ans + abs(v[i] - a);
    }
        cout<<ans;

}

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


int main(){
  int r,c;

  while(true){
    cin >> r >> c;
    if(r == 0 && c == 0) break;

    bool flag[r][c];
    for(int i = 0;i <r; ++i)
      for(int k = 0; k<c;++k)
	flag[i][k] = false;

    bool work = false;
    bool end_flag = false;
    for(int x = 0;x < r; ++x){
      for(int y = 0;y < c; ++y){
	if(x - 1 >= 0){
	  if(!flag[x-1][y]){
	    flag[x-1][y] = true;
	    work = true;
	  }
	}
	if(x + 1 < r){
	  if(!flag[x+1][y]){
	    if(!work){
	      flag[x+1][y] = true;
	      work = true;
	    }
	  }
	}
	if(y - 1 >= 0){
	  if(!flag[x][y-1]){
	    if(!work){
	      flag[x][y-1] = true;
	      work = true;
	    }
	  }
	}
	if(y + 1 < c){
	  if(!flag[x][y+1]){
	    if(!work){
	      flag[x][y+1] = true;
	      work = true;
	    }
	  }
	}
	if(!work){
	  cout << "no" << endl;
	  end_flag = true;
	  break;
	}
	work = false;
      }
      if(end_flag) break;
    }

    if(!end_flag) cout << "yes" << endl;
  }

  return 0;
}



Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  ll n,m,c=0;
  cin>>n>>m;
  vector<ll> k(m),b(m);
  vector<vector<ll>> a(m);
  for(int i=0;i<m;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      ll d;
      cin>>d;
      a[i].push_back(d-1LL);
    }
  }
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  for(int i=0;i<pow(2,n);i++){
    ll d=i;
    bool f=true;
    vector<ll> t(m,0);
    for(int j=0;j<n;j++){
      if(d%2==1){
        for(int s=0;s<m;s++){
          for(auto au:a[s]){
            if(au==j) t[s]++;
          }
        }
      }
      d/=2;
    }
    for(int j=0;j<m;j++){
      //cout<<t[j]<<endl;
      if(t[j]%2!=b[j])f=false;
    }
    if(f) c++;
  }
  cout<<c;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  int res = 0;
  for (int i = 1; i <= N; ++i) {
    int tmp = 0;
    for (int j = i; j > 0; j /= 10) {
      tmp += j % 10;
    }
    if ((A <= tmp) && (tmp <= B)) {
      res += i;
    }
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;

const int INF = 100000000;





int main(int argc, char *args[]) {
	int a[6];
	int k;
	bool flag = false;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	cin >> k;
	int d[5];
	for (int i = 1; i < 5; i++) {
		d[i] = a[i] - a[0];
		if (d[i] > k) {
			flag = true;
		}
	}
	if (flag)cout << ":(" << endl;
	else cout << "Yay!" << endl;
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
char s[200002];
char ss;
long int ans;

long int getSN(char ss){
	if(ss == '0')return 0;
	else if(ss == '1')return 1;
	else if(ss == '2')return 2;
	else if(ss == '3')return 3;
	else if(ss == '4')return 4;
	else if(ss == '5')return 5;
	else if(ss == '6')return 6;
	else if(ss == '7')return 7;
	else if(ss == '8')return 8;
	else if(ss == '9')return 9;
	else return 0;
}

int main(void) {
	scanf("%s", s);

	for(int j = 0; s[j] != '\0'; j++){
		int n = getSN(s[j]);
		ans = (ans + n) % 9;
	}
	if(ans == 0)printf("Yes");
	else printf("No");

	return 0;
}

Measured memory_bytes: 1908
#include <stdio.h>
int main(void){
    int A,B,C,D;
    scanf("%d%d%d%d", &A, &B, &C, &D);

    int X, Y;
    if (A >= C){
        X = A;
    }
    else {
        X = C;
    }
    if (B >= D){
        Y = D;
    }
    else {
        Y = B;
    }

    int ans = Y - X;
    if (ans < 0){
        printf("%d\n", 0);
    }
    else {
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 128
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
int main()
{
	int n, k, x, y;
	int sum = 0;
	cin >> n >> k >> x >> y;
	for (int i = 1; i <= n; i++)
	{
		if (i <= k)
		{
			sum += x;
		}
		else
		{
			sum += y;
		}
}
	cout << sum << endl;
	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=1001001001;

int main(){
    int n,t;
    cin>>n>>t;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int mx=0,x=a[0];
    for(int i=1; i<n; ++i){
        mx=max(mx,a[i]-x);
        x=min(x,a[i]);
    }
    int now=a[0],cnt=0;
    for(int i=1; i<n; ++i){
        if(a[i]-now>=mx){
            cnt+=a[i]-now-mx+1;
            a[i]-=a[i]-now-mx+1;
        }
        now=min(now,a[i]);
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3772
A=list(map(int,list(input())))
L = len(A)
num = L
pre = A[0]
end = True
for i in range(1,L):
    if A[i] != pre:
        if i*2 < L and L - i < num:
            num = L - i
        elif i < num:
            num = i
    pre = A[i]
print(num)

Measured memory_bytes: 50288
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <deque>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    double l;
    cin >> l;

    printf("%.14lf\n",l*l*l/27);
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int H, N, sum=0, sum1=0, i,j;
    scanf("%d %d", &H, &N);
    int arr[N];

    for(i=0; i<N; i++)
    {
        scanf("%d", &arr[i]);

        sum = sum + arr[i];

    }


    if(sum>=H)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 512
N = int(input())
L = [10**10]*4
for _ in range(N):
  x,y = [int(i) for i in input().split()]
  L[0] = min(L[0],x+y)
  L[1] = min(L[1],x-y+10**9)
  L[2] = min(L[2],-x+y+10**9)
  L[3] = min(L[3],-x-y+2*(10**9))
print(max(2*(10**9)-L[0]-L[3],2*(10**9)-L[1]-L[2]))

Measured memory_bytes: 69912
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    for(int i = 0; i <= N; i++){
        if(i + i * 8 / 100 == N){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}



Measured memory_bytes: 256
while 1:
	n = input()
	if n == 0: break
	ans = {}
	for i in range(n):
		group,name = raw_input().split(":")
		if i == 0: first = group
		ans[group] = set(name[:-1].split(","))
	while 1:
		for key in ans:
			flag = 0
			if key == first: continue
			for key1 in ans:
				if key in ans[key1]:
					ans[key1] |= ans[key]
					ans[key1].discard(key)
					flag = 1
			if flag:
				del ans[key]
				break
		if flag == 0: break
	print len(ans[first])

Measured memory_bytes: 4416
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

  while (N >= 10) {
    N %= 10;
  }

  if (N == 3) {
    cout << "bon" << endl;
  } else if (N == 0 || N == 1 || N == 6 || N == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3632
S = input()

ans = [1] * len(S)
for i in range(1, len(S)):
    if S[i-1] == S[i] == 'R':
        ans[i+1] += ans[i-1]
        ans[i-1] = 0
for i in range(len(S)-2, 0, -1):
    if S[i+1] == S[i] == 'L':
        ans[i-1] += ans[i+1]
        ans[i+1] = 0
print(*ans)   

Measured memory_bytes: 6400
#include <math.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <ostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _lcint;
#define REP(i, n) for (_lcint i = 0; i < n; i++)
#define FOR(i, a, b) for (_lcint i = (_lcint)(a); i < (_lcint)(b); i++)
#define FORREV(i, a, b) for (_lcint i = (_lcint)(b)-1; i >= (_lcint)(a); i--)
#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)  \
  cout << #v << ": "; \
  REP(i, v.size()) cout << " " << v[i] << endl;

#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// permutation
ll mPn(ll m, ll n) {
  ll a = 1;
  REP(i, n) { a *= m - i; }
  return a;
}

// excrametion
ll exc(ll m) {
  ll a = 1;
  FOR(i, 1, m) { a *= i + 1; }
  return a;
}

// combination
ll mCn(ll m, ll n) {
  ll a = 1, b = 1;
  REP(i, n) {
    a *= m - i;
    b *= n - i;
  }
  return a / b;
}

int main() {
  int A, B;
  cin >> A >> B;
  cout << (B % A == 0 ? A + B : B - A) << endl;
  return 0;
}

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

int main (){
  int a,b;
  cin>>a>>b;
  cout<<a*b;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
#define GETINT(x) int (x); cin >> (x);
#define FOR(i, N) for(int i = 0; i < (N); (i)++)
#define RET cout << endl;
constexpr int _10e(int n) { return n == 0 ? 1 : 10 * _10e(n - 1); }

int main() {
    GETINT(D);
    
    switch (D) {
        case 25: cout << "Christmas" << endl; break;
        case 24: cout << "Christmas Eve" << endl; break;
        case 23: cout << "Christmas Eve Eve" << endl; break;
        case 22: cout << "Christmas Eve Eve Eve" << endl; break;
    }
    
    return 0;
}

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

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

    int r = n-1, w = 0, ans = 0;
    bool rf = false, wf = false;
    while (1) {
        while (1) {
            if (r <= w) break;
            if (s[r] == 'R') {
                rf = true;
                break;
            }
            else r--;
        } 
        while (1) {
            if (w >= r) break;
            if (s[w] == 'W') {
                wf = true;
                break;
            }
            else w++;
        }
        if (rf && wf) {
            ans++;
            r--;
            w++;
            rf = false;
            wf = false;
        }
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


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

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

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

using namespace std;

int main() {
  while(1){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(!a)break;
    int na,nb,nc;
    cin>>na>>nb>>nc;
    int sum = 0;
    if (nc>=d){
      sum += e*nc;
      nc = 0;
    }
    else if(nc+nb>=d && nc*c+min(nb,d-nc)*b > e*d){
      sum += e*d;
      nb = max(0,nb-(d-nc));
      nc = 0;
    }
    else if(nc+nb<d && nc*c+nb*b+min(na,d-nc-nb)*a > e*d){
      sum += e*d;
      na = max(0,na-(d-nc-nb));
      nb = 0;
      nc = 0;
    }
    sum += nc*c+nb*b+na*a;
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import math
a,b,x = map(int,input().split())
v = a**2*b
d = 0
if x<v/2:
  d = math.atan2(b,x*2/a/b)
else:
  d = math.atan2((v-x)*2/a/a,a)
print(math.degrees(d))

Measured memory_bytes: 3060
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    K = I()
    non_one = 0
    if K < len(s):
        print(s[K-1])
        return

    for i, c in enumerate(s):
        if c != '1':
            non_one = i
            break

    print(s[non_one])

main()



Measured memory_bytes: 6192
#include <iostream>
#include <cstdlib>

#define Finding 																																\
			for(int j = 0; j < nGems; j++)																										\
			{																																	\
				if(!GemList[j].Recovered && GemList[j].x == this->x && GemList[j].y == this->y)													\
				{																																\
					GemList[j].Recovered = true;																								\
					RecoverCount++;																												\
				}																																\
				if(RecoverCount >= Unrecovered) return RecoverCount;																			\
			}

// stdin : Gems / Instructions

struct Gem
{
	int x, y;
	bool Recovered;
};
class Robot
{
public:
	void Initialize();
	int MoveAndRecover(Gem*, int, char, int, int);
private:
	int x, y;
};

int main(void)
{
	int nGems, MaxGems, nInsts;
	Gem* GemList;
	Robot Mychar;
	
	do
	{
		std::cin >> nGems;
		if(nGems == 0) break;
		MaxGems = nGems;
		GemList = (Gem*)malloc(sizeof(Gem) * nGems);
		for(int i = 0; i < nGems; i++)
		{
			std::cin >> GemList[i].x;
			std::cin >> GemList[i].y;
			GemList[i].Recovered = false;
		}
		std::cin >> nInsts;
		Mychar.Initialize();
		for(int i = 0; i < nInsts; i++)
		{
			// North:+y, East:+x
			std::string dir;
			int dist;
			std::cin >> dir;
			std::cin >> dist;
			nGems -= Mychar.MoveAndRecover(GemList, MaxGems, dir[0], dist, nGems);
		}
		if(nGems <= 0)
		{
			std::cout << "Yes" << std::endl;
		}
		else
		{
			std::cout << "No" << std::endl;
		}
		free(GemList);
	} while(true);
	
	return 0;
}

void Robot::Initialize()
{
	this->x = 10;
	this->y = 10;
}
int Robot::MoveAndRecover(
	Gem* GemList, int nGems, char Direction, int Distance, int Unrecovered)
{
	int RecoverCount = 0;
	
	if(Unrecovered <= 0) return 0;
	
	if(Direction == 'N')
	{
		// 自分の位置から下にDistanceまで走査する(実際に動く)
		for(int i = 0; i < Distance; i++)
		{
			Finding;
			this->y++;
		}
		Finding;
	}
	else if(Direction == 'S')
	{
		// 自分の位置から上にDistanceまで走査する(実際に動く)
		for(int i = 0; i < Distance; i++)
		{
			Finding;
			this->y--;
		}
		Finding;
	}
	else if(Direction == 'E')
	{
		// 自分の位置から下にDistanceまで走査する(実際に動く)
		for(int i = 0; i < Distance; i++)
		{
			Finding;
			this->x++;
		}
		Finding;
	}
	else if(Direction == 'W')
	{
		// 自分の位置から下にDistanceまで走査する(実際に動く)
		for(int i = 0; i < Distance; i++)
		{
			Finding;
			this->x--;
		}
		Finding;
	}
	
	return RecoverCount;
}

Measured memory_bytes: 1200
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

a,b,k = map(int,input().split())
ans = []
if b-a<=k:
    for i in range(a,b+1):
        print(i)
else:
    for i in range(a,a+k):
        ans.append(i)
    for i in range(b-k+1,b+1):
        ans.append(i)
    ans = set(ans)
    ans = list(ans)
    ans.sort()
    for i in range(len(ans)):
        print(ans[i])


Measured memory_bytes: 21120