akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
typedef long long ll; typedef long double ld; typedef double dd;typedef vector<int> vi; typedef pair<int, int> pii;typedef pair<ll,ll> pll;
const ll INFLL=(ll)4e18, MOD=1e9+7; const int INF=0x3f6f6f6f;
//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vi vis, color, level; int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}


const int NN=3e3+10;
ll psum[NN], a[NN], memo[NN][NN];
ll dp(int l, int r){
	if(l==r) return a[l];
	else if(memo[l][r]!=-1) return memo[l][r];

	ll& ret=memo[l][r];
	ret=max(a[l]+psum[r+1]-psum[l+1]-dp(l+1, r), a[r]+psum[r]-psum[l]-dp(l,r-1));
	return  ret;
}
///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

memset(memo,-1,sizeof(memo));
int n; cin>>n;
for(int i=0;i<n;++i) cin>>a[i];
psum[0]=0;
for(int i=1;i<=n;++i) psum[i]=psum[i-1]+a[i-1];
cout<<2*dp(0,n-1)-psum[n]<<el;




return 0;
}


Measured memory_bytes: 71296
#include <stdio.h> 
int main(void) 
{ 
    int W,H,i,j; 
    for ( ; scanf("%d %d\n",&H,&W) != EOF; ) 
    {
        for (i = 0; i < H; i++) 
        {
            for (j = 0; j < W; j++) 
            if (j%2==0&&i%2==0 || j%2==1&&i%2==1)
            {putchar('#');}
            else
            {putchar('.');}
            putchar('\n'); 
            
        } 
        if (H==0 && W==0) break; 
        putchar('\n');
    }
    return 0; 
    
}


Measured memory_bytes: 2048
import numpy as np
N,D=input().split()
N=int(N)
D=int(D)
divider=[]
for _ in range(N):
    array=list(map(int,input().split()))
    x=array[0]
    y=array[1]
    distance=np.sqrt(x**2+y**2)
    if distance<=D:
        divider.append(distance)
        continue
    else:
        continue
print(len(divider))

Measured memory_bytes: 34376
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	K := nextInt()
	S := nextInt()
	ans := make([]string, 0)
	for i := 0; i < N; i++ {
		if i < K {
			ans = append(ans, strconv.Itoa(S))
		} else if S != 1e9 {
			ans = append(ans, strconv.Itoa(S+1))
		} else {
			ans = append(ans, "1")
		}
	}
	fmt.Println(strings.Join(ans, " "))
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 11392
s = gets.chomp.to_s.split(//)
ary = ["+", "-"].repeated_permutation(3).to_a
sum = 0

ary.each do |x|
  sum += s[0].to_i
  3.times do |i|
    if x[i] == "+"
      sum += s[i+1].to_i
    elsif x[i] == "-"
      sum -= s[i+1].to_i
    end
  end
  if sum == 7
    puts s[0] + x[0] + s[1] + x[1] + s[2] + x[2] + s[3] + "=" + "7"
    exit
  else
    sum = 0
  end
end


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 200200;
int n;
char s[N];

bool solve(int k) {
	bool allZ = true, allO = true;
	for (int i = 0; i < n; i++) {
		if (i >= k || i + k < n) continue;
		allZ &= s[i] == '0';
		allO &= s[i] == '1';
	}
	return allZ || allO;
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%s", s);
	n = strlen(s);
	int l = 1, r = n + 1;
	while(r - l > 1) {
		int k = (l + r) / 2;
		if (solve(k))
			l = k;
		else
			r = k;
	}
	printf("%d\n", l);

	return 0;
}


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

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	if (n%k==0)
	{
		cout<<"0\n";
	}
	else
	{
		cout<<"1\n";
	}
	return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int const MAX_N = 2510;
ll const INF = 1e18;

struct edge {
    int to,cap;
    ll cost;
    int rev;
};
 
ostream& operator<<(ostream& os,const edge& a) {os << "(" << a.to << ", " << a.cap << ", " << a.cost << ", " << a.rev << ")";return os;}
 
vector<edge> G[MAX_N];
ll dist[MAX_N];
int prevv[MAX_N],preve[MAX_N];
 
void add_edge(int from,int to,int cap,ll cost) {
    G[from].push_back(edge{to,cap,cost,(int)G[to].size()});
    G[to].push_back(edge{from,0,-cost,(int)G[from].size()-1});
}
 
ll min_cost_flow(int s,int t,int f,int n) {
    ll res = 0;
    while (f > 0) {
        fill(dist,dist+n,INF);
        dist[s] = 0;
        bool update = true;
        while (update) {
            update = false;
            for (int v = 0;v < n;++v) {
                if (dist[v] == INF) continue;
                // cout << "aaa" << v << newl;
                for (int i = 0;i < G[v].size();++i) {
                    edge& e = G[v][i];
                    if (e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
                        dist[e.to] = dist[v]+e.cost;
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }
        // p_ary(dist,0,n);
        // if (dist[t] == INF) return -1;
        if (dist[t] == INF) break;
        int d = f;
        for (int v = t;v != s;v = prevv[v]) d = min(d,G[prevv[v]][preve[v]].cap);
        f -= d;
        res += d*dist[t];
        for (int v = t;v != s;v = prevv[v]) {
            edge& e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

int main() {
    int n,m;
    cin >> n >> m;
    int s = n*m,g = n*m+1;
    vector<string> c(n);
    for (int i = 0;i < n;++i) cin >> c[i];
    for (int i = 0;i < n;++i) for (int j = 0;j < m-1;++j) if (c[i][j] != '#' && c[i][j+1] != '#') add_edge(i*m+j,i*m+j+1,3000,-1);
    for (int i = 0;i < n-1;++i) for (int j = 0;j < m;++j) if (c[i][j] != '#' && c[i+1][j] != '#') add_edge(i*m+j,(i+1)*m+j,3000,-1);
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) if (c[i][j] == 'o') add_edge(s,i*m+j,1,0);
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) if (c[i][j] != '#') add_edge(i*m+j,g,1,0);
    // for (int i = 0;i < n*m+2;++i) p_ary(G[i],0,G[i].size());
    ll ans = min_cost_flow(s,g,3000,n*m+2);
    // p_ary(dist,0,n*m+2);
    cout << -ans << newl;
}

Measured memory_bytes: 4232
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int tp = 0, xp = 0, yp = 0;
    for (int i = 0; i < N; i++)
    {
        int tn, xn, yn;
        cin >> tn >> xn >> yn;
        int t = tn - tp;
        int d = abs(xn - xp) + abs(yn - yp);
        if (d > t || (t - d) % 2 == 1)
        {
            cout << "No" << endl;
            return 0;
        }
        tp = tn, xp = xn, yp = yn;
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

// Number of bits to represent int
#define BITS 62

// Function to return maximum XOR subset in set[]
ll maxSubarrayXOR(ll set[], int n)
{
  // Initialize index of chosen elements
  int index = 0; //ランク

  // Traverse through all bits of integer starting from the most significant bit (MSB)
  for (int i = BITS-1; i >= 0; i--){ //bit桁ぶん進めていく
    // Initialize index of maximum element and the maximum element
    int maxInd = index;
    ll maxEle = -1;
    for (int j = index; j < n; j++){ //まだ整っていないところから最大値maxEleを探す。
      // If i'th bit of set[j] is set and set[j] is greater than max so far.
      if ( (set[j] & ((ll)1 << i)) != 0 && set[j] > maxEle ) {
        maxEle = set[j], maxInd = j;
      }
    }

    // If there was no element with i'th bit set, move to smaller i その桁のすべてのbitが0だった場合
    if (maxEle == -1) continue;

    // Put maximum element with i'th bit set at index 'index'
    swap(set[index], set[maxInd]); //最大のものを上に持ってくる

    // Update maxInd and increment index
    maxInd = index;

    // Do XOR of set[maxIndex] with all numbers having i'th bit as set.
    rep(j, n){ // XOR set[maxInd] those numbers which have the i'th bit set
      if (j != maxInd && (set[j] & ((ll)1 << i)) != 0){
        set[j] = set[j] ^ set[maxInd];
      }
    }

    // Increment index of chosen elements
    index++; //ランクを1つ上げる。
  }

  // setは掃き出し済 ランクはindex
  // Final result is XOR of all elements
  ll res = 0;
  rep(i, n) res ^= set[i];
  return res;
}

// Driver program
void Main() {

  int N;
  cin>>N;
  ll set[N];
  ll allxor=0;
  rep(i,N){
    cin>>set[i];
    allxor ^= set[i];
  }
  rep(i,N){
    set[i] &= ~allxor;
  }

  ll x=maxSubarrayXOR(set, N);

  cout<< x*2 + allxor<<"\n";
}


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


Measured memory_bytes: 1024
N,A,B = map(int,input().split())
#n blue red
#8 3 4
#bbbrrrrb
#4
ans = 0
x = N // (A+B)
ans += (x * A)
N -= x * (A+B)
if N <= A:
  ans += N
else:
  ans += A
print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h> 
using namespace std; 
  
const int MAX = 1000001; 
  
// array to store prime factors 
int factor[MAX] = { 0 }; 
  
 
void generatePrimeFactors() 
{ 
    factor[1] = 1; 
  
   
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
  
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
  
    
    for (int i = 3; i * i < MAX; i++) { 
        // check if it has no prime factor. 
        if (factor[i] == i) { 
            
            for (int j = i * i; j < MAX; j += i) { 
                
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
  
// function to calculate number of factors 
int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
  
   
    int dup = factor[n]; 
  
    
    int c = 1; 
    int j = n / factor[n]; 
  
    // false when prime factorization is done 
    while (j != 1) { 
        if (factor[j] == dup) 
            c += 1; 
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
  
        // prime factorizes a number 
        j = j / factor[j]; 
    } 
  
    // for the last prime factor 
    ans = ans * (c + 1); 
  
    return ans; 
} 
  

int main(){
  int n;
  cin>>n;
  generatePrimeFactors();
  int ans=0;
  for(int i=1;i<n;i++){
    int count=calculateNoOFactors(i);
    ans+=count;
  }
  // ll ans=calculateNoOFactors(n-1);
  cout<<ans;
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

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

    int n, k;
    cin >> n >> k;

    vi h(n);
    rep(i, 0, n) { cin >> h[i]; }

    vi dp(n, 0);

    rep(i, 1, n) {
        int tmp = INT_MAX;
        int j = 1;
        while (j <= k && i - j >= 0) {
            tmp = min(tmp, dp[i - j] + abs(h[i] - h[i - j]));
            ++j;
        }
        dp[i] = tmp;
    }
    cout << dp.back() << endl;

    return 0;
}

Measured memory_bytes: 1024
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

bitset<60000> dp[80][80];
int D[80][80];
signed main() {
  int H, W;
  cin >> H >> W;
  rep(i, 0, H) rep(j, 0, W) { cin >> D[i][j]; }
  rep(i, 0, H) rep(j, 0, W) {
    int b;
    cin >> b;
    D[i][j] -= b;
    dp[i][j] = 0;
  }

  dp[0][0][30000 + D[0][0]] = 1;
  dp[0][0][30000 - D[0][0]] = 1;

  rep(i, 0, H) {
    rep(j, 0, W) {
      if (i + 1 < H) {
        int d = abs(D[i + 1][j]);
        dp[i + 1][j] |= dp[i][j] << d;
        dp[i + 1][j] |= dp[i][j] >> d;
        dump(i, j, "d");
      }
      if (j + 1 < W) {
        int d = abs(D[i][j + 1]);
        dp[i][j + 1] |= dp[i][j] << d;
        dp[i][j + 1] |= dp[i][j] >> d;
        dump(i, j, dp[i][j][30000 + 3], "r");
      }
    }
  }
  rep(k, 0, 30000) {
    if (dp[H - 1][W - 1][30000 - k] || dp[H - 1][W - 1][30000 + k]) {
      cout << k << endl;
      return 0;
    }
  }
  cout << INF << endl;
  return (0 ^ _ ^ 0);
}



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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, c;
    cin >> n >> c;
    vector< vector<bool> > jest(c, vector<bool>(100000, false));
    for (int i = 0; i < n; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        for (int j = a - 1; j < b; ++j)
            jest[c - 1][j] = true;
    }
    int odp = 0;
    for (int i = 0; i < 100000; ++i)
    {
        int prze = 0;
        for (int j = 0; j < c; ++j)
            if (jest[j][i])
                ++prze;
        odp = max(odp, prze);
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 640
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 3*1e5 , limit = 9*1e18 , MOD=1e9+7;

string binary(int n){bitset<60>b(n) ;string p =b.to_string();return p;}

int decimal(string n) { int dec_value = 0;  int base = 1;  for (int i = n.size() - 1; i >= 0; i--) { if (n[i] == '1') 
dec_value += base; base = base * 2; } return dec_value; } 

bool isPrime(int n){if (n <= 1) return false; if (n <= 3) return true;if (n % 2 == 0 || n % 3 == 0) return false;

for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }

int pow (int x, int n,int mod) {if (n == 0) return 1; int res = pow (x, n / 2,mod);res = (res * res) % mod;if (n % 2) res = (res * x ) % mod;return res;}
// int calcInverse(int a, int n = MOD){int t = 0, newt = 1;int r = n, newr = a;  while (newr != 0) {auto quotient = r /newr;tie(t, newt) = make_tuple(newt, t- quotient * newt);
// tie(r, newr) = make_tuple(newr, r - quotient * newr);}if (r > 1)throw runtime_error("a is not invertible");if (t < 0)t += n;t=t%n;    return t;}

#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n';

int32_t main(){
    boost;
    int n;
    
   int x;
    cin>>x;
    
    
    int p = x/1000 ;
    if(x%1000)p++;
    p = p*1000;
    
    int res = p - x;
    cout<<res<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
using namespace std;
int main()
{
	int p,q,r;
	cin>>p>>q>>r;
	int ans=min(p+q,p+r);
	ans=min(ans,q+r);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 2e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

  if (a > b)
    swap(a, b);

  if ((b - a) % 2 == 0) {
    cout << (b - a) / 2 << en;
    return 0;
  }

  ll res = min(b - 1, n - a);

  ll b1 = b - a;
  if (b1 > 1)
    res = min(res, a + abs(b1 - 1) / 2);

  ll a2 = a + (n - b + 1);
  if (a2 < n)
    res = min(res, (n - b + 1) + abs(n - a2) / 2);

  cout << res << en;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int i, j, h, w;
  char c;
  bool s[100][100];
  int dp[100][100];

  cin >> h >> w;

  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      cin >> c;
      if(c=='#'){
        s[i][j] = 1;
      }
      else{
        s[i][j] = 0;
      }
    }
  }

  dp[0][0] = s[0][0];

  for(i=1;i<h;i++){
    dp[i][0] = dp[i-1][0] + (!s[i-1][0]&&s[i][0]);
  }

  for(i=1;i<w;i++){
    dp[0][i] = dp[0][i-1] + (!s[0][i-1]&&s[0][i]);
  }

  for(i=1;i<h;i++){
    for(j=1;j<w;j++){
      dp[i][j] = min(dp[i-1][j]+(!s[i-1][j]&&s[i][j]),dp[i][j-1]+(!s[i][j-1]&&s[i][j]));
    }
  }

  cout << dp[h-1][w-1] << endl;
  
  return 0;
}


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

int main(void)
{
    string s,t;
    cin >> s;
    cin >> t;
    int i;
    int out;
    for(i=0;i<3;i++)
    {
        if(s[i]==t[i])
        {
            out++;
        }
    }
    cout << out << endl;

    return 0;
}

Measured memory_bytes: 256
using System;

namespace A___The_Number_of_Even_Pairs
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var m = int.Parse (input[1]);
            var ans = n * (n - 1) / 2 + m * (m - 1) / 2;
            Console.WriteLine (ans);
        }
    }
}

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

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

   vector<pair<int, int>> AB(N);
   rep(i, 0, N) cin >> AB.at(i).first >> AB.at(i).second;

   vector<int> mn_cost(H + 1, 1000000000);
   mn_cost.at(0) = 0;

   for (int i = 1; i <= H; i++) {
     rep(j, 0, N) {
       mn_cost.at(i) = min(mn_cost.at(max(0, i - AB.at(j).first)) + AB.at(j).second, mn_cost.at(i));
     }
   }

   cout << mn_cost.at(H) << endl;
 }


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

using namespace std;

using ll = long long;

const long long MOD_NUMBER = 1000000007;
const int MAX = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  ll n;
  string s;
  cin >> n;
  do {
    n--;
    s += n % 26 + 'a';
    n /= 26;
  } while (n);
  reverse(s.begin(), s.end());
  cout << s << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int     ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,m;
    cin>>m;
    ll ar[m+1];
    map<ll,ll>mp;
    for(ll i=0; i<m; i++)
    {
        cin>>ar[i];
        mp[ar[i]]++;
    }
    ll mn=1e18,ans=0;
    for(ll i=1; i<1e6+7; i++)
    {
        if(mp[i]==0)
            continue;
        else if(mp[i]==1)
            ans++;
        for(ll j=i+i; j<1e6+7; j+=i)
        {
            mp[j]=0;
        }
    }
    cout<<ans<<nn;



}


/* Final check before submit :

1. array size or integer overflow.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***

*/



Measured memory_bytes: 67692
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define vi vector<long long>
#define vs  vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
/*bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
*/
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int main()
{
    ll a,b,c,t,n,k,p,q,r,y,yy,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    set<ll>st;
    char ch;
    map<ll,ll>mp;
    vector<ll>v,vv,vz;

      cin>>a>>b>>c;
      st.insert(a);
      st.insert(b);
      st.insert(c);
       cout<<st.size()<<endl;
}





Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll m = a * c;
    chmax(m, a * d);
    chmax(m, b * c);
    chmax(m, b * d);
    cout << m << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
#define mod int(1e9+7)
#define ll long long
int a[2002];
ll n,k,ans;
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<i;j++)
			if(a[j]<a[i])ans=(ans+((k-1)*k>>1))%mod;
		for(int j=i+1;j<=n;j++)
			if(a[j]<a[i])ans=(ans+((k+1)*k>>1))%mod;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>	
#define pb push_back
typedef long long ll;
const int inf = 2e9;
using namespace std;

#define MAX 200005
#define MOD 1000000007

int n,m,k,t,q,p,a,b,c,x,y,minimo=inf,maximo;
ll mod=1000000007;

vector<int> G[MAX];

ll N[MAX];
//bool P[MAX];

//char M[MAX];

//char M[105][105];

//char M[1001][1001];

int main(){
	
	int a,b,c;
	ll k;
	scanf("%d%d%d%lld",&a,&b,&c,&k);
	if(k%2==0) printf("%d\n", a-b);
	else printf("%d\n", b-a);
	return 0;

}

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

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


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

using namespace std;

int main(){
    int N; cin >> N;
    vector<double> v(N);
    for(int i=0; i<N; i++) cin >> v.at(i);
    sort(v.begin(), v.end());
    
    double k = v.at(0);
    for(int i=0; i<N-1; i++){
        k = (k + v.at(i+1)) / 2;
    }
    printf("%f\n", k);   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int N;
int a[2][SIZE];
ll K;

int main()
{
	cin >> N;
	int c;
	rep(i,0,N){
		cin >> c;
		a[i%2][c]++;
	}

	int v[2] = {0,0};
	int n[2];
	rep(i,0,SIZE){
		if(v[0] < a[0][i]){
			v[0] = a[0][i];
			n[0] = i;
		}
		if(v[1] < a[1][i]){
			v[1] = a[1][i];
			n[1] = i;
		}
	}
	//cout << N - v[0] - v[1] << endl;
	sort(a[0],a[0]+SIZE);
	sort(a[1],a[1]+SIZE);
	reverse(a[0],a[0]+SIZE);
	reverse(a[1],a[1]+SIZE);
	int k=0;
	if(n[0] == n[1]){
		k = max(a[0][0]+a[1][1],a[0][1]+a[1][0]);
	}else{
		k = a[0][0] + a[1][0];
	}
	cout << N - k << endl;
		

	return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
      	boolean d;
      
      	if((a+b+c) < 22) d = true;
		else d = false;

		if(d) System.out.println("win");
      	else System.out.println("bust");
	}
}

Measured memory_bytes: 35848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=3050;
const int M=200050;
const int mod=1e9+7;
int add(int x, int y){ x+=y;return x>=mod?x-mod:x;}
int sub(int x, int y){ x-=y;return x<0?x+mod:x;}
int mul(int x, int y){ return (ll)x*y%mod;}
int powmod(int x, int k)
{
	int ans=1;
	for(;k;k>>=1,x=mul(x,x)) if(k&1) ans=mul(ans,x);
	return ans;
}
int inv(int x){ return powmod(x,mod-2);}
int x[N],y[N],id[N],F[M],I[M];
bool comp(int i, int j){ return mp(x[i],y[i])<mp(x[j],y[j]);}
int binom(int n, int k){ return mul(F[n],mul(I[k],I[n-k]));}
int dp[N];
int main()
{
	F[0]=1;for(int i=1;i<M;i++) F[i]=mul(F[i-1],i);
	I[M-1]=inv(F[M-1]);for(int i=M-2;~i;i--) I[i]=mul(I[i+1],i+1);
	int n,H,W;
	scanf("%i %i %i",&H,&W,&n);
	for(int i=1;i<=n;i++) scanf("%i %i",&x[i],&y[i]),id[i]=i;
	sort(id+1,id+1+n,comp);
	for(int k=1;k<=n;k++)
	{
		int i=id[k];
		dp[i]=binom(x[i]+y[i]-2,x[i]-1);
		for(int l=1;l<k;l++)
		{
			int j=id[l];
			int a=x[i]-x[j],b=y[i]-y[j];
			if(a>=0 && b>=0)
				dp[i]=sub(dp[i],mul(dp[j],binom(a+b,a)));
		}
	}
	int ans=binom(H+W-2,H-1);
	for(int i=1;i<=n;i++)
		ans=sub(ans,mul(dp[i],binom(H+W-x[i]-y[i],H-x[i])));
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int k, s;
  cin >> k >> s;

  int ans = 0;
  rep(x, 0, k + 1) {
    rep(y, 0, k + 1) {
      int z = s - (x + y);
      if (z >= 0 && z <= k)
        ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    typedef long long ll;
    #define mx 400
    #define pb push_back
    ll mod = 1e9 + 7;
    using namespace std;
    ll arr[mx + 3];
    ll dp[mx + 3][mx + 3];
    ll inf = 1e18;
    ll solve(int i, int j) {
    	if (i == j)
    		return 0;
    	if (dp[i][j] != inf)
    		return dp[i][j];
    	for (int k = i; k < j; ++k)
    		 dp[i][j] = min(dp[i][j], solve(i, k) + solve(k + 1, j));
    	return dp[i][j] +=  arr[j] - arr[i - 1];
    }
    int main() {
    	int n;
    	cin >> n;
    	for (int i = 1; i <= n; ++i)
    		for (int j = 1; j <= n; ++j)
    			dp[i][j] = inf;
     
    	for (int i = 1; i <= n; ++i)
    		cin >> arr[i], arr[i] += arr[i - 1];
    	cout << solve(1, n) << endl;
    }

Measured memory_bytes: 1536
using System;

class program
{
    public static void Main()
    {
        while (true)
        {
            var str = Console.ReadLine().Split(' ');
            var H = int.Parse(str[0]);
            var W = int.Parse(str[1]);

            if (H == 0 && W == 0) break;

            for (int height = 0; height < H; height++)
            {
                for (int width = 0; width < W; width++)
                {
                    if (height % 2 == 0)
                    {
                        if (width % 2 == 0)
                        {
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write(".");
                        }
                    }
                    else
                    {
                        if (width % 2 == 0)
                        {
                            Console.Write(".");
                        }
                        else
                        {
                            Console.Write("#");
                        }
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 5292
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    int N,M;
    cin >> N >> M;
    vector<int> a(M),b(M),c(M);
    int d[N][N];
    rep(i,M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
    }
    rep(i,N) rep(j,N){
        if(i == j) d[i][j] = 0;
        else d[i][j] = 1e9;
    }
    
    rep(i,M) d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
    
    rep(k,N) rep(i,N) rep(j,N) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    
    set<P> st;
    rep(k,M) rep(i,N) if(d[i][a[k]] + c[k] == d[i][b[k]]) st.insert(mp(a[k],b[k]));
    
    pr(M-sz(st));
}

Measured memory_bytes: 384
#include<iostream>

using namespace std;

int n,now = 0,maxn = 0;
char a;

int main(void)
{
	cin>>n;
	
	for(int i = 0;i < n;++i)
	{
		cin>>a;
		if(a == 'I')
			++now;
			
		else
		{
			maxn = max( maxn , now );
			--now;
		}
	}
	
	maxn = max(maxn , now);
	
	cout<<maxn<<endl;
	
	return 0;
}

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

class LadderPermutation
{
public:
	vector <int> createLadder(long long int n,long long int m,long long int k)
	{
		if(m+k-1>n || n>m*k)
		{
			return {};
		}
		vector <int> res;
		vector <int> v;
		long long int num = n;
		for(int i=0;i<k;i++)
		{
			v.push_back(num);
			num--;
		}
		
		for(int i=0;i<v.size();i++)
		{
			if(num==0)
			{
				res.push_back(v[i]);
			}
			else
			{
				int start = max(1LL,num-m+2);
				int end = num;
				for(int j=start;j<=end;j++)
				{
					res.push_back(j);
				}
				num-=(m-1);
				if(num < 0)
				{
					num = 0;
				}
				res.push_back(v[i]);
			}
		}
		if(num>=1)
		{
			for(int i=1;i<=num;i++)
			{
				res.push_back(i);
			}
		}
		return res;
	}
}; 
int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(0);

	long long int n,m,k;

	cin >> n >> m >> k;
	LadderPermutation p;

	vector <int> res = p.createLadder(n,m,k);

	if(res.size()==0)
	{
		cout << -1 << '\n';
		return 0;
	}
	for(auto it : res)
	{
		cout << it << ' ';
	}
	cout << '\n';

	return 0;
}

Measured memory_bytes: 5808
// AtCoder Grand Contest 018
// A - Getting Difference

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


int N;
ll K;

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


int main() {

    ll a, max_a;
    ll res;

    cin >> N >> K;
    cin >> res;
    max_a = res;
    for (int i = 1; i < N; i++) {
        cin >> a;
        max_a = max(max_a, a);
        res = gcd(res, a);
    }
    cout << ((K <= max_a) && (K % res == 0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;

    return 0;

}





Measured memory_bytes: 256
n,m=map(int,input().split())
a=[input()for i in range(n)]
b=[input()for i in range(m)]
cnt=False
for i in range(n-m+1):
    for j in range(n-m+1):
        t=[k[j:j+m]for k in a[i:i+m]]#n*nの一部分を抜粋している
        if t==b:
            cnt=True
print("Yes" if cnt else "No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf = 1e9;
const int MAX = 1e5+5;
const ll MOD = 1e9+7;
#define REP(i, n) for (int i = 0; i < (n); ++i)

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    vector<vector<int>> bingo(3, vector<int>(3));
    REP(i, 3){
        REP(j, 3){
            cin >> bingo[i][j];
        }
    }
    int n; cin >> n;
    int tmp;
    REP(i, n){
        cin >> tmp;
        REP(j, 3){
            REP(k, 3){
                if(tmp == bingo[j][k]) bingo[j][k] = -1;
            }
        }
    }
    bool aranged = false;
    REP(i, 3){
        if(bingo[i][0] == -1 && bingo[i][1] == -1 && bingo[i][2] == -1) aranged = true;
        if(bingo[0][i] == -1 && bingo[1][i] == -1 && bingo[2][i] == -1) aranged = true;
    }
    if(bingo[0][0] == -1 && bingo[1][1] == -1 && bingo[2][2] == -1) aranged = true;
    if(bingo[0][2] == -1 && bingo[1][1] == -1 && bingo[2][0] == -1) aranged = true;
    if(aranged) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int a, b;
	scanf("%d%d", &a, &b);
	if ((a + b) % 2 == 0)printf("%d\n", (a + b) / 2);
	else printf("IMPOSSIBLE\n");
	

	return 0;
}


Measured memory_bytes: 128
// abc059.a

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (b % a == 0) {
		cout << a + b << endl;
	} else {
		cout << b - a << endl;
	}
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  l=['Sunny','Cloudy','Rainy']

  if s==l[0]:
    return l[1]
  elif s==l[1]:
    return l[2]
  else:
    return l[0]

# main()
print(main())


Measured memory_bytes: 7848
#include <stdio.h>
#define INFTY 1410065408

void mergeSort(int*,int,int);
void merge(int*,int,int,int);

int count=0;

int main(){
  int n,i;
  scanf("%d",&n);
  int S[n];

  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  mergeSort(S,0,n);

  for(i=0;i<n;i++){
    if(i==n-1) printf("%d\n",S[i]);
    else printf("%d ",S[i]);
  }
  printf("%d\n",count);
  
  return 0;
}

void mergeSort(int *S,int left,int right){
  int mid=(left+right)/2;
  if(left+1<right){
    mergeSort(S,left,mid);
    mergeSort(S,mid,right);
    merge(S,left,mid,right);
  }
  
}


void merge(int *S,int left,int mid,int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;
  int L[n1+1],R[n2+1];
  
  for(i=0;i<n1;i++){
    L[i]=S[left+i];
  }
  L[i]=INFTY;
  
  for(i=0;i<n2;i++){
    R[i]=S[mid+i];
  }
  R[i]=INFTY;
  
  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      S[k]=L[i];
      i++;
    }

    else{
      S[k]=R[j];
      j++;
    }
    count++;
  }
}



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

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

#define M 1046527

string Hash[M];

int getChar(char s) {
  if (s == 'A') return 1;
  else if (s == 'C') return 2;
  else if (s == 'G') return 3;
  else if (s == 'T') return 4;
  else return 0;
}

ll getKey(string str) {
  ll sum = 0, p = 1;
  rep(i, str.size()) {
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) {
  return key % M;
}

int h2(int key) {
  return 1 + (key % (M-1));
}

void insert(string str) {
  ll key, i, h;
  key = getKey(str);
  for (i=0; ; i++) {
    h = (h1(key) + i*h2(key)) % M;
    if (Hash[h] == str) return;
    else if (Hash[h].size() == 0) {
      Hash[h] = str;
      return;
    }
  }
  return;
}

bool find(string str) {
  ll key, i, h;
  key = getKey(str);
  for (i=0; ; i++) {
    h = (h1(key) + i*h2(key)) % M;
    if (Hash[h] == str) return true;
    else if(Hash[h].size() == 0) return false;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<pair<string, string>> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;

  rep(i,n) {
    if (a[i].first == "insert") {
      insert(a[i].second);
    } else if (a[i].first == "find") {
      if (find(a[i].second)) {
	cout << "yes" << endl;
      } else {
	cout << "no" << endl;
      }
    } else {
      cout << "Invalid command: " << a[i].first << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 126652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

/*---------------------------------------------------------------------------------------------------*/

void solve()
{
  int n;
  cin >> n;
  int a[n];
  f(i,n)
    cin >> a[i];
  int ans=0;
  fp(i,1,n-1)
  {
      if(a[i]<a[i-1])
        {
            ans+=(a[i-1]-a[i]);
            a[i]=a[i-1];
        }
  }
  cout << ans << '\n';
  return;
} 

signed main()
{
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 5208
#include <stdio.h>
int main(void) {
    char s[11];
    int i;
 
    while (scanf(" %10s ", s) != EOF) {
        while (s[1] != '\0') {
            for (i = 0; s[i] != '\0'; i++) {
                s[i] = (s[i] + s[i + 1] - '0' - '0') % 10 + '0';
            }
            s[i - 1] = '\0';
        }
        puts(s);
    }
    return 0;
}

Measured memory_bytes: 524
N=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(N[K-1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x,2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vd = vector<long double>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(){
      int len=par.size(),ans=0;
      vi v(len);
      for(int i=0;i< len;i++){
        v[root(i)]++;
      }
      for(int i=0;i< len;i++){
        if(ans<v[i]){ans=v[i];}
      }
      return ans;
    }
};
int main() {
  int n,m,a,b;
  cin >> n>>m;
  UnionFind tree(n);
  rep(i,m){
    cin >> a>>b;
    tree.unite(a-1,b-1);
  }
  cout << tree.size() << endl;
  return 0;
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(x-a) > abs(x-b)) cout << 'B' << endl;
  else cout << 'A' << endl;
  

 }

Measured memory_bytes: 256