akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define int64 long long
#define sz(a) ((int) (a).size())

const int64 INF = (int64) 2e18 + 10;
const int N = (int) 2e5 + 10;
int64 a[N], b[N], sum;
int n, d, x;

struct data {
	int minA, minB;
	pair<int, int> bestPair;

	data(): minA(-1), minB(-1), bestPair(make_pair(-1, -1)) {}
	data(int minAValue, int minBValue, pair<int, int> bestPairValue): minA(minAValue), minB(minBValue), bestPair(bestPairValue) {}

	int64 getDiff() const {
		return (bestPair.first == -1) ? INF : (a[bestPair.first] + b[bestPair.second]);
	}
	int64 getMinA() const {
		return (minA == -1) ? INF : a[minA];
	}
	int64 getMinB() const {
		return (minB == -1) ? INF : b[minB];
	}
} rmq[4 * N];

data operator+(const data& l, const data& r) {
	if (l.minA == -1) return r;
	if (r.minB == -1) return l;
	data res;
	res.minA = (l.getMinA() <= r.getMinA()) ? l.minA : r.minA;
	res.minB = (l.getMinB() < r.getMinB()) ? l.minB : r.minB;
	res.bestPair = (l.getDiff() < r.getDiff()) ? l.bestPair : r.bestPair;
	if (res.getDiff() > b[r.minB] + a[l.minA]) res.bestPair = make_pair(l.minA, r.minB);
	return res;
}

void update(int t, int l, int r, int i) {
	if (l == r - 1) {
		rmq[t] = data(l, l, make_pair(-1, -1));
	} else {
		int m = (l + r) / 2;
		if (i < m) {
			update(t * 2 + 1, l, m, i);
		} else {
			update(t * 2 + 2, m, r, i);
		}
		rmq[t] = rmq[t * 2 + 1] + rmq[t * 2 + 2];
	}
}

void build(int t, int l, int r) {
	if (l == r - 1) {
		rmq[t] = data(l, l, make_pair(-1, -1));
	} else {
		int m = (l + r) / 2;
		build(t * 2 + 1, l, m);
		build(t * 2 + 2, m, r);
		rmq[t] = rmq[t * 2 + 1] + rmq[t * 2 + 2];
	}
}

data neutral(-1, -1, make_pair(-1, -1));

data get(int t, int l, int r, int x, int y) {
	if ((y <= l) || (r <= x)) return neutral;
	if ((x <= l) && (r <= y)) return rmq[t];
	int m = (l + r) / 2;
	return get(t * 2 + 1, l, m, x, y) + get(t * 2 + 2, m, r, x, y);
}

void solve(int l, int r) {
	if (l == r - 1) return;
	pair<int, int> bestPair = get(0, 0, n, l, r).bestPair;
	int minA = bestPair.first, minB = bestPair.second;
	sum += b[minB] + a[minA];
	for (int i = minA + 1; i < minB; ++i) {
		sum += min(b[i] + a[minA], a[i] + b[minB]);
	}
	b[minA] = min(b[minA], b[minB]), a[minB] = min(a[minA], a[minB]);
	update(0, 0, n, minA);
	update(0, 0, n, minB);
	if (l < minA) {
		solve(l, minA + 1);
	}
	if (minB < r) {
    	solve(minB, r);
    }
}

int main() {
	scanf("%d%d", &n, &d);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &x);
		a[i] = x - i * (int64) d;
		b[i] = x + i * (int64) d;
	}
	build(0, 0, n);
	solve(0, n);
	printf("%lld\n", sum);
	return 0;
}


Measured memory_bytes: 28032
#バケット法による解
N = int(input())
dlist = []
for i in range(N):
    dlist.append(int(input()))
dbacket = [0]*101
for d in dlist:
    dbacket[d] += 1
answer = 0
for db in dbacket:
    if db > 0:
        answer += 1
print(answer)

Measured memory_bytes: 3060
x = int(input())
y = list(map(int, input().split(" ")))

for i in range(x - 1):
  if y[i] < 0:
    y[i] *=-1
    y[i + 1] *=-1

if y[-1] < 0 and abs(min(y[0:-1])) < abs(y[-1]) :
  y[-1] *= -1
  y[y.index(min(y[0:-1]))] *= -1

print(sum(y))

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

ll solve() {
    ll H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    Ch--, Cw--, Dh--, Dw--;
    vector<string> S(H);
    for ( int i = 0; i < H; i++ ) cin >> S[i];
    vector<int> dh = {0, 1, 0, -1}, dw = {1, 0, -1, 0};
    ll INF = 1LL<<60;
    vector<vector<ll>> d(H, vector<ll>(W,INF));
    deque<pii> q;
    q.push_front(pii(Ch,Cw));
    d[Ch][Cw] = 0;
    while ( !q.empty() ) {
        pii v = q.front();
        q.pop_front();
        int h0 = v.first, w0 = v.second;
        for ( int ii = 0; ii < 4; ii++ ) {
            int h = h0 + dh[ii];
            int w = w0 + dw[ii];
            if ( h < 0 || h >= H || w < 0 || w >= W ) continue;
            if ( S[h][w] == '#' ) continue;
            if ( d[h][w] > d[h0][w0] ) {
                d[h][w] = d[h0][w0];
                q.push_front(pii(h,w));
            }
        }
        for ( int i1 = -2; i1 <= 2; i1++ ) {
            for ( int j1 = -2; j1 <= 2; j1++ ) {
                int h = h0 + i1;
                int w = w0 + j1;
                if ( h < 0 || h >= H || w < 0 || w >= W ) continue;
                if ( S[h][w] == '#' ) continue;
                if ( d[h][w] > d[h0][w0] + 1 ) {
                    d[h][w] = d[h0][w0] + 1;
                    q.push_back(pii(h,w));
                }
            }
        }
    }
    ll ans = d[Dh][Dw];
    if ( ans == INF ) ans = -1;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 13472
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
  std::cout << std::fixed << std::setprecision(15);

  int N, M; cin >> N >> M;
  vector<vector<int> > s(M);
  rep(i, M){
    int k; cin >> k;
    rep(j, k){
      int t; cin >> t;
      s[i].push_back(t);
    }
  }

  vector<int> p(M);
  rep(i, M){
    cin >> p[i];
  }

  int ans = 0;
  rep(bit, 1 << N){
    bool ok =true;
    rep(j, M){
      int cnt = 0;
      rep(t, s[j].size()){
        if(bit >> (s[j][t] - 1) & 1){
          cnt++;
        }
      }
      if(cnt % 2 != p[j]) ok = false;
    }
    if(ok){
      ans++;
    }
  }

  cout << ans << endl;
}  


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int a, b, h, m;
	cin >> a >> b >> h >>m;
	double degh = 30 * h + 0.5 * m;
	double degm = 6 * m;
	double deg = abs(degh - degm);
	deg = min(360 - deg, deg);
	deg *= PI / 180;
	deg = cos(deg);
//	cout << deg << endl;
	double ans = a * a + b * b - 2 * a * b * deg;
	ans = sqrt(ans);
	cout.precision(10);
	cout << fixed;
	cout << ans;
	return 0;
}

Measured memory_bytes: 4188
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << ' ' << y << ' ' << z;
    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 MAX_N = 200005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

vector<int> to[200005];

mint dfs(int v) {
	mint res = 1;
	for (int u :to[v]) {
		res *= dfs(u);
	}
	return res + 1;
}

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>>P(N);
	for (int n = 0 ;n < N;++n) {
		cin >> P[n].first >> P[n].second;
	}
	sort(P.begin(), P.end());
	set<pair<int, int>>S; 

	for (int i = N - 1;i>=0; --i) {
		int x = P[i].first, d = P[i].second;
		while (S.size() && S.begin()->first < x+d) {
			to[i].push_back(S.begin()->second);
			S.erase(S.begin());
		}
		S.emplace(x, i);
	}
	mint ans = 1;
	for (auto x:S) {
		int v = x.second;
		ans *= dfs(v);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 25160
#![allow(unused)]

//input
use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [u64;n],
    }

    let mut h = h;

    h.sort_by_key(|x| !x);

    let ans: u64 = h.iter().skip(k).sum();

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

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

int mincost(int ar[],int n,int k)
{
    int cost[n];

    cost[n-1]=0;
    cost[n-2]=abs(ar[n-2]-ar[n-1]);

    for(int j=n-3; j>=0; j--){
        int a,Min=999999999;
        for(int i=1; i<=k; i++){
            if(j+i>n-1){
                break;
            }
            a=cost[j+i]+abs(ar[j]-ar[j+i]);
            Min=min(Min,a);
        }
        cost[j] = Min;
    }
    return cost[0];
}
int main()
{
    int n,k;
    cin>>n>>k;
    int ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    cout << mincost(ar,n,k);
}



Measured memory_bytes: 1024
def main3(N):
    lst = list()
    for i in range(1, 10):
        lst.append([0]*9)

    for n in range(1, N+1):
        head = int(str(n)[0])
        tail = int(str(n)[-1])
        #末尾が0はNG
        if tail != 0:
            lst[head-1][tail-1] += 1
        
    #for i in range(0, len(lst)):
    #    print(lst[i])
    
    count = 0
    for i in range(0, len(lst)):
        for j in range(0, len(lst[i])):
            count += lst[i][j] * lst[j][i]

    print(count)

N = int(input())
main3(N)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
#define allSum(a) accumulate(a.begin(),a.end(),0)
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

signed main(){
  int n,m;
  cin>>n>>m;
  vint a(n);
  rep(i,n)cin>>a[i];
  a.pb(m);
  SORT(a);
  vint d(n);
  rep(i,n)d[i]=a[i+1]-a[i];
  int ans=d[0];
  rep(i,n)ans=__gcd(ans,d[i]);
  out(ans);
  

  return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			long[] array = new long[n];
			for (int i = 0; i<n; i++) array[i] = sc.nextLong();
			boolean same = true;
			int query = sc.nextInt();
			for (int i = 0; i<query; i++) {
				Long k = sc.nextLong();
				if (k > array[n - 1]) System.out.println(n);
				else {
					System.out.println(lowerBound(array,k));
				}
			}
		}
	}
	
	static int lowerBound(long[] array, long target) {
		int low = 0;
		int high = array.length-1;  //最後

		while (low < high) {
			//System.out.println(low + "    "+ high);
			int mid = (high + low)/2;
			if (array[mid] == target) {
				while ((mid != 0)&&(array[mid - 1] == target)) mid--;  //前がある場合移動
				return mid;
			}
			else if (array[mid] < target) low = mid + 1;
			else high = mid;
		}
		while ((high != 0)&&(array[high - 1] == array[high])) high--;  //前がある場合移動
		return high; //大きいほうを返す
	}
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int n,m;
    cin >> n >> m;
    ll a[n],b[n];
    ll c[m],d[m];
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,m) cin >> c[i] >> d[i];
    rep(i,n){
        int check;
        ll min_mhtn = INF;
        rep(j,m){
            if((abs(a[i]-c[j])+abs(b[i]-d[j]))<min_mhtn){
                check = j;
                min_mhtn = abs(a[i]-c[j])+abs(b[i]-d[j]);
            }
        }
        cout << check+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
s = list(input())
t = list(input())

maxx = 0

for i in range(len(s) - len(t) + 1):
    ppp = 0
    for j in range(len(t)):
        if s[i + j] == t[j]:
            ppp += 1
    if ppp > maxx:
        maxx = ppp

print(len(t) - maxx)


Measured memory_bytes: 64676
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<int> A(N), acc(N+1);
    for(int i=0; i<N; i++) {
        cin >> A[i];
        A[i] -= (i + 1);
    }

    sort(A.begin(), A.end());
    for(int i=0; i<N; i++) {
        acc[i+1] = acc[i] + A[i];
    }

    int ans = 1LL << 60;
    for(int i=0; i<N; i++) {
        int target = A[i];

        int idx = upper_bound(A.begin(), A.end(), target) - A.begin();
        idx--;

        int tmp = 0;
        tmp += (idx * target - acc[idx]);
        tmp += (acc[N] - acc[idx] - (N - idx) * target);
        chmin(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
import sys

a = [int(i) for i in sys.stdin.readline().split(' ')]

for i in range(0, len(a)):
    for j in range(i+1, len(a)):
        if a[i] > a[j]:
            t = a[i]
            a[i] = a[j]
            a[j] = t

print(' '.join([str(i) for i in a]))

Measured memory_bytes: 6728
#include <stdio.h>
#include <math.h>

typedef struct
{
    double x;
    double y;
    double r;
}circle;

int main(void)
{
    int datasets;
    scanf("%d", &datasets);

    while (datasets--) {
        circle a, b;
        scanf(" %lf %lf %lf", &(a.x), &(a.y), &(a.r));
        scanf(" %lf %lf %lf", &(b.x), &(b.y), &(b.r));

        double dist = pow(a.x - b.x, 2) + pow(a.y - b.y, 2);

        int ans;
        if (dist > pow(a.r + b.r, 2)) {
            ans = 0;
        } else if (dist >= pow(a.r - b.r, 2)) {
            ans = 1;
        } else {
            if (a.r > b.r) {
                ans = 2;
            } else {
                ans = -2;
            }
        }

        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 640
MAX= 101010
is_prime = [ 1 ] * MAX
is_prime[0] = is_prime[1] = 0
for i in range( MAX ):
    if is_prime[ i ] == 0:
        continue
    for j in range( 2 * i, MAX, i ):
        is_prime[ j ] = 0

a = [0] * MAX
for i in range( MAX ):
  if ( is_prime[ i ] ) and ( is_prime[ ( ( i + 1 ) )// 2 ] ):
    a[i] = 1

s = [ 0 ] * MAX
for i in range( 1, MAX ):
  s[ i ] = s[ i - 1 ] + a[ i ]

q = int( input() )
for i in range( q ):
    l, r = map( int, input().split() )
    print( s[r] - s[ l - 1 ] )


Measured memory_bytes: 7924
#include<iostream>

using namespace std;

int main(){
  int d,a,b,c,n;
  cin >> d;
  for(n=0;n<d;n++){
    cin >> a >> b >> c;
    if(a*a==b*b+c*c){
      cout << "YES" << endl;
    }
    else if(b*b==a*a+c*c){
      cout << "YES" << endl;
    }
    else if(c*c==a*a+b*b){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
  }
  return 0;
}




Measured memory_bytes: 3044
def solve():
    x, y, z = list(map(int, input().split(" ")))

    if (x % (y + z) == 0):
        ans = x // (y + z) - 1
    else:
        if (x % (y + z)) >= z:
            ans = x // (y + z)
        else:
            ans = x // (y + z) - 1

    print(ans)
    

solve()

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

int main(){
  string s;
  cin >> s;
  
  for(int i=0;i<3;i++){
    if(s.at(i) == '1'){
      s.at(i) = '9';
    }else if(s.at(i) == '9'){
      s.at(i) = '1';
    }
  }
  
  cout << s <<endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    int n; cin >> n;
    vector<ll> div(n+1);
    for (ll i = 1; i <= n; i++) {
        ll cnt = i;
        while (cnt <= n) {
            div[cnt]++;
            cnt += i;
        }
    }

    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ans += i*div[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string s;
    bool ans=true;
    cin>>s;
    if(s[0]!='A')ans=false;
    if('A'<=s[1]&&s[1]<='Z')ans=false;
    if('A'<=s[s.size()-1]&&s[s.size()-1]<='Z')ans=false;
    s.erase(0,2);
    s.erase(s.size()-1);
    int c=0;
    for(auto i : s){
        if(i=='C')++c;
        else if('A'<=i&&i<='Z')ans=false;
    }
    if(c!=1)ans=false;
    if(ans)cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(){
  int I,J;
  scanf("%d %d\n",&I,&J);
  char buf[J+1];
  int i;
  for(i=0;i<I;i++){
      scanf("%s",buf);
      printf("%s\n%s\n",buf,buf);
  }

  return 0;
}


Measured memory_bytes: 128
program ABC066B
    implicit none
    integer(8)::i
    integer(8)::result=0
    character(200)::S
    read(5,*)S

    do i=1,len_trim(S)/2-1
        if(S(1:i)==S(i+1:2*i))then
            if(i>result)then
                result=i
            end if
        end if
    end do

    print'(i0)',2*result
end program ABC066B

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int N;
    cin >> N;
    vector<int> s(N),a;

    ll sum = 0;
    for (int i = 0; i < N; i++){
        cin >> s[i];
        sum += s[i];
        if (s[i] % 10 != 0){
            a.push_back(s[i]);
        }
    }
    ll ans;
    if (sum % 10 != 0){
        ans = sum;
    } else {
        if ((int)a.size()){
            ans = sum - *min_element(all(a));
        } else {
            ans = 0;
        }
    }

    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(){
  	int N; 
  	std::cin >> N;
  	if (N % 2 == 1) { std::cout << "No"; return 0; }
  	char* S = new char[N];
  	for (int i = 0; i < N; i++) {
    	char temp;
      	std::cin >> temp;
      	S[i] = temp;
    }
  	int halve = (int)(N / 2);
  	for (int i = 0; i < halve ; i++){
    	if (S[i] != S[i + halve]) { std::cout << "No"; return 0; }
    }
  	std::cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
import itertools
import math

n = int(input())
towns = []
indexs = []
for i in range(n):
    tmp = input().split(' ')
    x = int(tmp[0])
    y = int(tmp[1])
    towns.append([x,y])
    indexs.append(i)

sum = 0
c = 0
for index in itertools.permutations(indexs):
    c = c + 1
    for k in range(len(index)-1):
        i = towns[index[k]]
        j = towns[index[k+1]]
        sum = sum + math.sqrt(pow((i[0] - j[0]),2) + pow((i[1] - j[1]), 2))
print(sum/c)



Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();

        if(s.length() + 1 != t.length()){
            System.out.println("No");
            return;
        }
        if(!t.startsWith(s)){
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
    }
}

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

int main()
{

        int N, K;
        cin >> N >> K;

        if (K == 10) {
                cout << 0 << endl;
        }

        int d[K];
        for (int i = 0; i < K; ++i) {
                cin >> d[i];
        }

        for (int i = N; i < 100000; ++i) {

                string s = to_string(i);
                int len = s.length();
                bool ng = false;
                for (int j = 0; j < K; ++j) {
                        char c = 0x30 + d[j];
                        for (int m = 0; m < len; ++m) {
                                if (s[m] == c) {
                                        ng = true;
                                        break;
                                }
                        }
                        if (ng) {
                                break;
                        }
                }
                if (!ng) {
                        cout << i << endl;
                        return 0;
                }
        }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(auto &a:A)cin>>a;
  reverse(ALL(A));
  ll ans=1;
  ll now=A[0];
  ll cnt=1;
  for(int i=1;i<n;i++){
    if(now<=A[i]){
      cnt++;
      now=A[i];
    }else{
      cnt=1;
      now=A[i];
    }
    ans=max(ans,cnt);
  }
  cout<<ans-1<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int A, B;
int main(){
  scanf("%d%d", &A, &B);
  if(A==B){
    printf("Draw\n");
  }else if(A==1){
    printf("Alice\n");
  }else if(B==1){
    printf("Bob\n");
  }else if(A>B){
    printf("Alice\n");
  }else{
    printf("Bob\n");
  }
}


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

int main()
{
  int x,ans;
  cin >> x;
  if(x<600)
    ans=8;
  else if(x<800)
    ans=7;
  else if(x<1000)
    ans=6;
  else if(x<1200)
    ans=5;
  else if(x<1400)
    ans=4;
  else if(x<1600)
    ans=3;
  else if(x<1800)
    ans=2;
  else
    ans=1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N;
    int a[100000];
    cin >> N;
    bool flag = false;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i]%2 == 1) flag = true;
    }
    //sort(a, a+N);
    if(flag == true) cout << "first" << endl;
    else cout << "second" << endl;
}

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

using namespace std;

typedef long long ll;

bool reversecompare(int a, int b)
{
    return a > b;
}

int noofdigit (int a)
{
    int counter = 0;
    if (a == 0)
        return 1;
    else
    {
        while (a > 0)
        {
            a /= 10;
            counter++;
        }
        return counter;
    }
}

int kuadrat [415];

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

    int a, b, c;

    for (int i = 0; i < 400; i++)
        kuadrat[i] = i*i;

    cin >> a >> b;

    c = a * pow(10,(noofdigit(b))) + b;
    // cout << c << endl;
    if (binary_search(kuadrat, kuadrat + 399, c))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main() {
	int a, b, c, x;
	scanf("%d %d %d", &a, &b, &c);

	if (a > b) {
		x = a;
		a = b;
		b = x;
	}
	if (a > c) {
		x = a;
		a = c;
		c = x;
	}
	if (b > c) {
		x = b;
		b = c;
		c = x;
	}
	printf("%d %d %d\n", a, b, c);


	return 0;
}

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

using namespace std;
int const N = 100;
int const K = 100001;
unsigned long long const MOD = 1000000007;
unsigned long long ways[N][K];
int limit[N];

int main(){
    int n, k;
    cin >> n >> k;
    for(int i= 0; i < n; i++)
        cin >> limit[i];
    for(int i = 0; i <= k; i++){
        if (limit[0] >= i)
            ways[0][i] = 1;
        else
            ways[0][i] = 0;
    }
    for(int i= 0; i < n; i++){
            ways[i][0] = 1;
    }
    for(int i = 1; i < n; i++){
        for(int j = 1; j <= k; j++){
            if (limit[i] >= j)
                ways[i][j] = ways[i - 1][j] + ways[i][j-1];
            else 
                ways[i][j] = ways[i - 1][j] + ways[i][j-1] + (MOD - ways[i-1][j - limit[i] - 1]);
            ways[i][j] %= MOD;
        }

    }
    /*for(int i = 0; i < n; i++){
        for(int j = 0; j <= k; j++)
            cout << ways[i][j] << ' ';
        cout << '\n';
    }*/
    
    cout << ways[n-1][k] << '\n';
}

Measured memory_bytes: 81676
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    h = list(map(int, input().split()))
    INF = 10**12
    dp = [INF] * (N+1)
    dp[1] = 0
    for i in range(1,N):
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i-1]-h[i]))
        if i < N-1:
            dp[i+2] = min(dp[i+2],dp[i]+abs(h[i-1]-h[i+1]))
    print(dp[N])

if __name__ == "__main__":
    main()


Measured memory_bytes: 21132
H, W = [int(i) for i in input().split()]
A = [input() for j in range(H)]

DH = []

for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            break
    else:
        DH.append(h)

DW = []

for w in range(W):
    for h in range(H):
        if A[h][w] == '#':
            break
    else:
        DW.append(w)

for h in range(H):
    for w in range(W):
        if h in DH:
            break
        elif w in DW:
            continue
        print(A[h][w], end='')
    else:
        print()

Measured memory_bytes: 4468
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_imports)]

use std::io::stdin;
use std::str::FromStr;
use std::cmp::min;
use std::process::exit;

fn read<T: FromStr>() -> T {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_n_vec<T: FromStr>(n: u64) -> Vec<Vec<T>> {
    let mut v_outer = Vec::new();
    for _ in 0..n {
        let v_inner = read_vec();
        v_outer.push(v_inner);
    }
    v_outer
}

fn main() {
    let line: Vec<u32> = read_vec();
    let a = line[0];
    let b = line[1];

    for i in 1..1251 {
        if (i as f32 * 0.08) as u32 == a && (i as f32 * 0.1) as u32 == b {
            println!("{}", i);
            exit(0);
        }
    }
    println!("-1");
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

int main(){
	ll N;
	cin >> N;
	vector<int> A(N),B(N);
	FOR(i,0,N) cin >> A[i];
	FOR(i,0,N) cin >> B[i];
	//　もともとiにいたカードは位置jmod2 == imod2 のjで赤

	int ans = -1;
	FOR(s,0,(1<<N)){
		vector<int> zero,one;
		vector<pair<int,int>> onex,zerox;
		int invcount = 0;
		FOR(i,0,N)if(s&(1<<i))invcount++;
		if(invcount%2) continue;
		FOR(i,0,N){
			if(s&(1<<i)){//裏返す
				if(i&1){
					zero.push_back(i);
					zerox.push_back({B[i],i});
				}else{
					one.push_back(i);
					onex.push_back({B[i],i});
				}
			}else{//裏返さない
				if(i&1){
					one.push_back(i);
					onex.push_back({A[i],i});
				}else{
					zero.push_back(i);
					zerox.push_back({A[i],i});
				}
			}
		}
		int zl = zerox.size();
		int ol = onex.size();
		if( zl!=ol && zl!=(ol+1) ){
			continue;
		}
		SORT(onex);SORT(zerox);
		bool none = false;
		
		vector<ll> to_this_ind,xxx;
		FOR(i,0,ol){
			xxx.push_back(zerox[i].first);
			xxx.push_back(onex[i].first);
			to_this_ind.push_back(zerox[i].second);
			to_this_ind.push_back(onex[i].second);
		}
		if(zl>ol)to_this_ind.push_back(zerox[ol].second),xxx.push_back(zerox[ol].first);
		FOR(i,0,N-1){
			if(xxx[i]>xxx[i+1])none = true;
		}
		if(none)continue;
		int cnt = 0;
		set<int> se;
		FOR(i,0,N)se.insert(i);
		FOR(i,0,N){
			auto ind = se.lower_bound(to_this_ind[i]);
			int indc = 0;
			auto ite = se.begin();
			while(ite!=ind){ite++;indc++;}
			cnt += indc;
			se.erase(to_this_ind[i]);
		}
		if(ans==-1) ans = cnt;
		ans = min(ans,cnt);
	}

	cout << ans << endl;
}


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

int main(){
  int M=0,N,T=0;
  cin >> N;
  int A[N],B[100001]={0};
  for(int i=0;i<N;i++){
    cin >> A[i];
    B[A[i]]++;
    if(M<A[i]){M=A[i];}
  }
  for(int i=0;i<M+1;i++){
    if(B[i]>1){
      T+=B[i]-1;
    }
  }
  cout << N-(((T+1)/2)*2) << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int first = Integer.parseInt(S.substring(0, 2));
		int second = Integer.parseInt(S.substring(2));
		if (first > 0 && first < 13) {
			if (second > 0 && second < 13) {
				System.out.println("AMBIGUOUS");
			} else {
				System.out.println("MMYY");
			}
		} else {
			if (second > 0 && second < 13) {
				System.out.println("YYMM");
			} else {
				System.out.println("NA");
			}
		}

		sc.close();
	}
}

Measured memory_bytes: 23508
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int h = sc.nextInt();
        System.out.println((a+b)*h/2);
    }
}

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

#define INF 100010

int cost[24][24];
int d[24][24];
int V, E;

int main(){
    cin >> V >> E;

    for(int i=0; i < 24; i++){
        for(int j=0; j < 24; j++){
            cost[i][j] = INF;
        }
        cost[i][i] = 0;
    }

    for(int i=0; i < E; i++){
        int a, b, c, d;
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        a--; b--;
        cost[a][b] = c;
        cost[b][a] = d;
    }

    int start, pillar, money, subtotal;
    scanf("%d,%d,%d,%d", &start, &pillar, &money, &subtotal);
    start--;
    pillar--;

    for(int k=0; k < V; k++){
        for(int i=0; i < V; i++){
            for(int j=0; j < V; j++){
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }

    cout << money - subtotal - cost[start][pillar] - cost[pillar][start] << endl;
}

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

int main() {
	int n, a, b;
	int p[1 << 25], q[1 << 25];
	cin >> n;
	a = n;
	while (a) {
		b += a % 10;
		a /= 10;
	}
	if (n%b == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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


int main() {
    int n;
    cin >> n;
    vector<int> nums(n);
    int a_sum = 0, b_sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> nums.at(i);
    }

    sort(nums.begin(), nums.end());
    reverse(nums.begin(), nums.end());
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) a_sum += nums.at(i);
        else b_sum += nums.at(i);
    }

    cout << abs(a_sum - b_sum) << endl;
    return 0;
}


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


int main(void)
{
    int N, M, C;
    cin >> N >> M >> C;

    vector<int> B(M);
    vector<vector<int>> A(N, vector<int>(M));

    for (int i = 0; i < M; i++)
    {
        cin >> B[i];
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }

    int ans = 0;
    
    for (int i = 0; i < N; i++)
    {
        int sum = C;
        for (int j = 0; j < M; j++)
        {
            sum += A[i][j] * B[j];
        }
        
        if(sum > 0) ans++;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3556
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define MIN -10000000
#define MAX 10000000
#define debug printf("%d",__LINE__)
using namespace std;
int main()
{
	long long a;
	scanf("%lld", &a);
	printf("%lld", a + a * a + a * a * a); 
	return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <numeric>
#include <cstdlib>

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

int main()
{
  string s;
  int n = 800, d;

  cin >> s;

  for (int i = 0; i < s.size() - 2; i++)
  {
    d = abs(753 - stoi(s.substr(i, 3)));
    n = min(n, d);
  }

  cout << n << endl;

  return 0;
}

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

const int INF = 1e9;
int H, W, c_i, c_j, d_i, d_j, cost[1010][1010];
string S[1010];

int main() {

	cin >> H >> W >> c_i >> c_j >> d_i >> d_j;
    for (int i = 0; i < H; ++i){
        cin >> S[i];
    }

    for (int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++j){
            cost[i][j] = INF;
        }
    }

    deque<pair<int, int>> q;
    cost[c_i-1][c_j-1] = 0;
    q.push_front(make_pair(c_i-1, c_j-1));

    while(!q.empty()){
        auto p = q.front();
        q.pop_front();
        int i = p.first;
        int j = p.second;
        
        if (i >= 1 && S[i-1][j] == '.' && cost[i-1][j] > cost[i][j]) {
            cost[i-1][j] = cost[i][j];
            q.push_front(make_pair(i-1, j));
        }
        if (i <= H-2 && S[i+1][j] == '.' && cost[i+1][j] > cost[i][j]){
            cost[i+1][j] = cost[i][j];
            q.push_front(make_pair(i+1, j));
        }
        if (j >= 1 && S[i][j-1] == '.' && cost[i][j-1] > cost[i][j]) {
            cost[i][j-1] = cost[i][j];
            q.push_front(make_pair(i, j-1));
        }
        if (j <= W-2 && S[i][j+1] == '.' && cost[i][j+1] > cost[i][j]){
            cost[i][j+1] = cost[i][j];
            q.push_front(make_pair(i, j+1));
        }

        for (int k = max(0, i-2); k <= min(i+2, H-1); ++k){
            for (int l = max(0, j-2); l <= min(j+2, W-1); ++l){
                if (S[k][l] == '.' && cost[k][l] > cost[i][j]+1){
                    cost[k][l] = cost[i][j]+1;
                    q.push_back(make_pair(k, l));
                }
            }   
        }
    }
    if (cost[d_i-1][d_j-1] == INF){
        cout << -1 << endl;
    } else {
        cout << cost[d_i-1][d_j-1] << endl;
    }
	return 0;
}


Measured memory_bytes: 9552
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()

if x == 1:
    print(0)
    sys.exit()


if n == 100:
    if x <= 50:
        print(0)
        sys.exit()
    else:
        print(101)
        sys.exit()


nun_list = list(map(int, input().split()))
answer = 0

for i in range(0, 210):
    if nun_list.__contains__(i):
        continue
    else :
        if abs(x - answer) >= abs(x - i):
            if abs(x - answer) == abs(x - i):
                if answer > i:
                    answer = i
            else:
                answer = i
if abs(x - answer) <= abs(x - 0):
    print(answer)
else :
    print(0)

Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	string S;
	cin >> S;
	int Pcounter = 0;
	int Mcounter = 0;
	for (int i = 0; i < 4; i++) {
		if (S[i] == '+') {
			Pcounter++;
		}
		else {
			Mcounter++;
		}
	}
	cout << Pcounter - Mcounter << endl;
}

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

void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int l = 0, r = n - 1;
	int cnt = 0;
	while (r - l >= 1) {
		if (s[l] == 'W' && s[r] == 'R') {
			swap(s[l], s[r]);
			cnt++;
			l++; r--;
		}
		else if (s[l] == 'W') {
			r--;
		}
		else {
			l++;
		}
	}
	// stack<char> st;
	// for (int i = 0; i < n; i++) {
	// 	if (s[i] == 'R') {
	// 		st.push(s[i]);
	// 	}
	// 	else {

	// 	}
	// }
	cout << cnt << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) {
		solve();
	}
}

Measured memory_bytes: 3776
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
   int a;
   string s;
   cin >> a >> s;
   if (a >= 3200)
   {
      cout << s << endl;
   }
   else
   {
      cout << "red" << endl;
   }
   
   return 0;
}


Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
v = a * b
x = x / a
if x < v/2:
    c = x * 2 / b
    d = math.sqrt(b * b + c * c)
    print(math.degrees(math.asin(b/d)))
else:
    rest = v - x
    c = rest * 2 / a
    d = math.sqrt(a * a + c * c)
    print(math.degrees(math.acos(a/d)))

Measured memory_bytes: 3060
# ノードの開始が'0'でなく'1'であることに注意!!※※※

import sys
input = sys.stdin.readline

n, m =  map(int, input().split()) # nは頂点の数、mは辺の数
pic = [[] for _ in range(n)] # 隣接リスト_初期化

for _ in range(m): # 隣接リスト_取り込み
    a, b = map(int, input().split())
    pic[a-1].append(b-1) # ※※※
    pic[b-1].append(a-1) # ※※※

from collections import deque

def BFS(u): # 'u'を開始位置として各頂点までの距離を探索する関数
    queue = deque([u]) # dequeオブジェクトとして初期化、初期値は開始位置の'u'のみ
    dis = [None] * n # uからの距離を全ノード分初期化
    dis[u] = 0 # 自分'u'との距離は0
    ans = [-1] * n # 探索元のノードを格納する
    while queue:
        v = queue.popleft() # v:探索元のノード 
        for i in pic[v]: # pic[v]: 探索元のノードに隣接するノードのリスト
            if ans[i] == -1:
                ans[i] = v
            if dis[i] is None:
                dis[i] = dis[v] + 1
                queue.append(i)
    return ans

tmp = BFS(0) # ここは'1'ではなく'0'※※※
print('Yes')
for j in tmp[1:]:
    print(j+1) # ※※※

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

#define int long long
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)  
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rap(i,a,n) for (int i = a; i < (n); i++) 
#define rrap(i,n,a) for (int i = (n)-1; i >= a; i--) 
#define LL_MAX 9223372036854775807

int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}

int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}

typedef vector<int> vi;  
typedef pair<int,int> ii;  
typedef vector<ii> vii;  
typedef list<int> li;  
typedef unordered_map<int,int> mii;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a,b;
    cin >> a >> b;
    cout << lcm(a,b) << '\n';

    return 0;
    //compile: g++ -std=c++14 -O2 -Wall NAME.cpp -o NAME
}

Measured memory_bytes: 256
def div(n):
	a = []
	for i in range(1, int(n**0.5+1)):
		if n % i == 0:
			a.append(i)
			a.append(n//i)
	return sorted(a)
def resolve():
	n = int(input())
	d = div(n)
	v = len(str(max(d[len(d)//2], d[len(d)//2-1])))
	print(v)
resolve()

Measured memory_bytes: 38640
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>

using namespace std;

int main() {
    
    string s;
    cin >> s;
    
    string m;
    
    m = s.substr(5, 2);
    
    int mm = stoi(m);
    
    if (mm > 4)
    {
        cout << "TBD" << endl;
    }
    else
    {
        cout << "Heisei" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])

ret_rev = []

i, j = len(s) - 1, len(t) - 1
while i >= 0 and j >= 0:
    if s[i] == t[j]:
        ret_rev.append(s[i])
        i, j = i - 1, j - 1
    elif dp[i + 1][j] == dp[i][j]:
        i, j = i - 1, j
    else: # i.e. dp[i][j + 1] == dp[i][j]
        i, j = i, j - 1

ret = "".join(ret_rev[::-1])

print(ret)

Measured memory_bytes: 112348
n, m = [int(v) for v in input().split()]
query = [tuple(int(v) for v in input().split()) for _ in range(m)]

res = [None] * n

for s, c in query:
    s -= 1
    if res[s] is None:
        if n > 1 and c == 0 and s == 0:
            res = None
            break
        res[s] = c
    elif res[s] == c:
        pass
    else:
        res = None
        break

if res is None:
    print("-1")
else:
    if n > 1 and res[0] is None:
        res[0] = 1
    res = [0 if v is None else v for v in res]
    print("".join(str(v) for v in res))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;

int main(){
    string s;
    cin>>s;
    int ans=700;
    rep(i,0,s.size())if(s[i]=='o')ans+=100;
    cout<<ans<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    vector<int> x, y;
    int n, m, X, Y, k;
    cin >> n >> m >> X >>  Y;
    for(int i = 0; i < n; i++){
        cin >> k;
        x.push_back(k);
    }
    for(int i = 0; i < m; i++){
        cin >> k;
        y.push_back(k);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if(x[n-1] < y[0] && x[n-1] < Y && X < y[0]) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if(sc.next().equals(a)) {
        	c--;
        }else {
        	d--;
        }
        System.out.println(c + " " + d);
	}
}

Measured memory_bytes: 22996
#include<stdio.h>
int main()
{
	int n,i,max=0,k=0;
	char a;
	scanf("%d",&n);
	for(i=0;i<=n;i++)
	{
		scanf("%c",&a);
		if(a=='I')
		{
			k++;
		}
		if(a=='D')
		{
			k--;
		}
		if(k>max)
		{
			max=k;
		}
	}
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
num=[1]*n
aka=[0]*n
aka[0]=1
for _ in range(m):
  x,y=map(int,input().split())
  if num[x-1]>1 and aka[x-1]==1:
    num[x-1]+=-1
    aka[x-1]=1
    aka[y-1]=1
    num[y-1]+=1
  elif num[x-1]==1 and aka[x-1]==1:
    num[x-1]=0
    aka[x-1]=0
    aka[y-1]=1
    num[y-1]+=1
  elif aka[x-1]==0:
    num[x-1]+=-1
    num[y-1]+=1
print(sum(aka))


Measured memory_bytes: 10472