akhauriyash/Code-Regression huggingface dataset:
n = int(input())
al = [0] + list(map(int, input().split())) + [0]
bl = [0]*(n+1)
for i in range(n+1):
    bl[i] = abs(al[i] - al[i+1])
cost = sum(bl)

for i in range(n):
    print(cost - sum(bl[i:i+2]) + abs(al[i] - al[i+2]))

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

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


	long long n,m,k;
	cin>>n>>m>>k;

	vector<long long>a(n+1),b(m+1);
	a[0]=0;
	b[0]=0;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=m;i++)
		cin>>b[i];

	for(int i=1;i<=n;i++)
		a[i] += a[i-1];

	for(int i=1;i<=m;i++)
		b[i] += b[i-1];	

	int cnt =0;

	for(int i=0;i<=n;i++)
	{
		long long rem = k - a[i];

		if(rem>=0)
		{
			auto l = lower_bound(b.begin(),b.end(),rem);
			int idx = l-b.begin();
			if(idx>m || b[idx]>rem)
				idx--;

			cnt = max(cnt,i+idx);

		}
	}
	cout<<cnt<<"\n";
    return 0;
		
}

Measured memory_bytes: 6356
def solve(string):
    n, k, *a = map(int, string.split())
    x = 0
    p = 2**(len("{:b}".format(k)) - 1)
    while p > 0:
        if sum([1 for _a in a if p & _a]) < n / 2 and x + p <= k:
            x += p
        p //= 2
    return str(sum([x ^ _a for _a in a]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))


Measured memory_bytes: 16028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

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

    int ans = INT_MAX;
    for (int i = 0; i < (1 << N); ++i) {
        int ctmp = 0;
        vector<int> tmp(M);
        for (int j = 0; j < N; ++j) {
            if (i & (1 << j)) {
                for (int k = 0; k < M; ++k)
                    tmp[k] += A[j][k];
                ctmp += C[j];
            }
        }

        bool isok = true;
        for (int j = 0; j < M; ++j)
            if (tmp[j] < X)
                isok = false;

        if (isok)
            ans = min(ans, ctmp);
    }

    cout << (ans == INT_MAX ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<set>
#include<vector>
#define INF 100000000

#define MAX_N 100
#define MAX_set 200

typedef long long int ll;
using namespace std;


int main(){

	int N;
	int a,b,c;
	scanf("%d", &N);

	for(int i = 0; i < N; i++){
		scanf("%d %d %d", &a, &b, &c);
		if(a*a + b*b == c*c || a*a + c*c == b*b || b*b + c*c == a*a)
			printf("YES\n");
		else
			printf("NO\n");
	}

}

Measured memory_bytes: 1168
c = [list(map(int, input().split())) for _ in range(3)]
flg = all(
    c[0][i + 1] - c[0][i] == c[1][i + 1] - c[1][i] == c[2][i + 1] - c[2][i]
    and c[i + 1][0] - c[i][0] == c[i + 1][1] - c[i][1] == c[i + 1][2] - c[i][2]
    for i in range(2)
)
print(["No", "Yes"][flg])

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> c[i];
  rep(i, n) p[i]--;

  ll ans = -1e18;
  rep(si, n) {
    int x = si;
    vector<int> s;
    ll tot = 0;
    while (1) {
      x = p[x];
      s.push_back(c[x]);
      tot += c[x];
      if (x == si) break;
    }
    int l = s.size();
    ll t = 0;
    rep(i, l) {
      t += s[i];
      if (i + 1 > k) break;
      ll now = t;
      if (tot > 0) {
        ll e = (k - (i + 1)) / l;
        now += tot * e;
      }
      ans = max(ans, now);
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3672
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<998244353>;

#include <vector>

void f(std::vector<mint> &a) {
  int n = a.size();
  for (int k = 1; k < n; ++k) {
    for (int i = k * 2; i < n; i += k) {
      a[k] += a[i];
    }
  }
}

void inv_f(std::vector<mint> &a) {
  int n = a.size();
  for (int k = n - 1; k >= 1; --k) {
    for (int i = k * 2; i < n; i += k) {
      a[k] -= a[i];
    }
  }
}

#include <iostream>

int main() {
  constexpr int Max = 1000000;
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int &e : a) {
    std::cin >> e;
  }

  std::vector<mint> x(Max + 1);
  for (const int e : a) {
    x[e] += mint(e);
  }

  f(x);

  std::vector<mint> y(Max + 1);
  for (int i = 1; i <= Max; ++i) {
    y[i] = x[i] * x[i];
  }

  inv_f(y);

  // i=j を除去
  for (const int e : a) {
    y[e] -= mint(e) * mint(e);
  }
  // i>j を除去
  for (int i = 1; i <= Max; ++i) {
    y[i] /= mint(2);
  }

  mint ans = 0;
  for (int i = 1; i <= Max; ++i) {
    ans += y[i] / mint(i);
  }

  std::cout << ans.value() << std::endl;

  return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

ll modpow(ll a,ll n,ll mod){
  ll res=1;
  while(n){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a,ll mod){
  return modpow(a,mod-2,mod);
}

const int MAX=5000000;
const int mod=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];

void init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  rep(i,MAX){
    if(i>1){
      fac[i]=fac[i-1]*i%mod;
      inv[i]=mod-inv[mod%i]*(mod/i)%mod;
      finv[i]=finv[i-1]*inv[i]%mod;
    }
  }
}

ll com(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  init();
  ll ans=com(C+D+2,C+1)+com(A+B,B);
  ans%=mod;
  (ans+=mod-com(A+D+1,A))%=mod;
  (ans+=mod-com(B+C+1,B))%=mod;
  cout<<ans<<endl;
}

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

int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    for(int i=1;i<=n;++i){
        if(s.substr(s.size()-i) == t.substr(0,i))cnt = i;
    }

    cout << n * 2 - cnt << endl;

    return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //std::numeric_limits<int>::max();
    int a,b,c,cnt1=0,cnt2=0;
    cin>>a;
    for(b=0;b<a;b++)
    {
    	cin>>c;
    	if(c%2==0)
    	{
    		cnt1++;
    		if(c%3==0 || c%5==0)
    			cnt2++;
		}
		
	}
	if(cnt1==cnt2)
		cout<<"APPROVED"<<endl;
	else
		cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, s, i, flag = 0;
    
    scanf("%d %d", &a, &b);
    if(9>=b){
        s = a * 10 + b;
    } else if(10<=b && 100>b){
        s = a * 100 + b;
    } else if(100 == b){
        s = a * 1000 + b;
    }
    for(i = 0; i <= 100100; i++){
        if(i * i == s){
            flag = 1;
            //printf("Yes\n");
        }
    }
    if(flag == 1){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

using pint = pair<int, int>;
using ppint = pair<pint, pint>;

int main() {
	int h, w;
	cin >> h >> w;

	int odd = 0;
	vvi a(h, vi(w));
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
			if (a[i][j] & 1) ++odd;
		}
	}

	vector<ppint> res;
	int num = 0;
	int x = 0, y = 0;
	rep(_, w* h) {
		if (a[x][y] & 1) ++num;

		int nx = x, ny = y;
		if (x % 2 == 0) {
			if (ny == w - 1) ++nx;
			else ++ny;
		}
		else {
			if (ny == 0) ++nx;
			else ny--;
		}

		if (num & 1) {
			if (num < odd) {
				res.push_back(ppint(ii(x, y), ii(nx, ny)));
			}
		}
		x = nx, y = ny;
	}
	cout << res.size() << endl;
	for (auto p : res) {
		cout << p.first.first + 1 << " " << p.first.second + 1 << " " << p.second.first + 1 << " " << p.second.second + 1 << endl;
	}

}

Measured memory_bytes: 5232
N = gets.to_i
L = gets.split.map(&:to_i).sort

result = 0
L.combination(3).each do |a,b,c|
    if a == b || a == c || b == c
        next
    end
    if a < b + c && b < a + c && c < a + b
        result += 1
    end
end

puts result

Measured memory_bytes: 14344
#include <iostream>
 
using namespace std;
 
int main(void)
{
  char hoge;
  int v, h, a, b, tmp;
  cin >> v;
  cin >> h;
    
  int bar[v];
  for (int i = 0; i < v; i++)
    bar[i] = i+1;
      
  for (int i = 0; i < h; i++) 
  {
    cin >> a >> hoge >> b;
    tmp = bar[a-1];
    bar[a-1] = bar[b-1];
    bar[b-1] = tmp;
  }
    
  for (int i = 0; i < v; i++)
    cout << bar[i] << endl;
   
  return 0;
}

Measured memory_bytes: 1156
//C - たくさんの数式
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
int main()
{
  long Num;
  std::cin >> Num;
  std::ostringstream oss;
  oss << Num;
  std::string S = oss.str();
  size_t sizeS = S.length();
  long coefNum[sizeS];
  
  coefNum[sizeS - 1] = 1 * std::pow(2, sizeS - 1);
  int coefNumAdd = coefNum[sizeS - 1]/2;
  for(int i = sizeS - 2; i >= 0; i--) coefNum[i] = 10*coefNum[i + 1]/2 + coefNumAdd;
  
  long sumS = 0;
  for(int i = 0; i < sizeS; i++) sumS += coefNum[i]*(S[i] - '0');
  
  std::cout << sumS << std::endl;
  return 0;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i, Ai in enumerate(A):
    tmp = sum([Aij * Bj for Aij, Bj in zip(Ai, B)]) + C
    if tmp > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3064
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <math.h>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
#define CIN(s) int (s);cin>>(s);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF =1e18;
ld sum;
 ld a,b,x;
bool Judge(ld k){
    if(a*b*(b/tan(k))/2>sum){
        return true;
    }else{
        return false;
    }
}
bool Judge1(ld k){
    if(a*a*(a/tan(k))/2>sum){
        return true;
    }else{
        return false;
    }
}
int main(){
   
    cin>>a>>b>>x;
    if(a*a*b==2*x){
        cout<<45<<endl;
    }else{
        
        if(a*a*b>x*2){
        sum=x;
        ld Max=90;
        ld Min=0;
        rep(i,1000){
            ld Half=(Max+Min)/2;
            ld k=(Half/180.0)*M_PI;
            if(!Judge(k)){
                Max=Half;
            }else{
                Min=Half;
            }
        }
        cout<<setprecision(20)<<Min<<endl;
        }else{
            sum=a*a*b-x;
            ld Max=90;
        ld Min=0;
        rep(i,1000){
            ld Half=(Max+Min)/2;
            ld k=(Half/180.0)*M_PI;
            if(!Judge1(k)){
                Max=Half;
            }else{
                Min=Half;
            }
        }
        cout<<setprecision(20)<<90-Min<<endl;
        }
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;

int main(){
    int N,M;
    cin >> N >> M;
    bool a[N][N];
    memset(a,false,sizeof(a));
    for(int i=0;i<M;i++){
        int x,y;
        cin >> x >> y;
        x--; y--;
        a[x][y]=true;
        a[y][x]=true;
    }
    int v[N];
    for(int i=0;i<N;i++) v[i]=i;
    int ans=0;
    do{
        if(v[0]!=0) continue;
        for(int i=0;i<N-1;i++){
            if(a[v[i]][v[i+1]]==false) break;
            if(i==N-2) ans++;
        }
    }while(next_permutation(v,v+N));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = 0
wa = defaultdict(lambda: 0) # wa = {} だと 存在しないkeyにおいて wa[key] = ○ で代入できない
already = set()
sum_wa = 0
for line in range(m):
    p, s = input().split() # forでその都度入力を受け取る
    p = int(p)
    if p in already: # acを見つけたときのみalreadyにpをいれるので、ac後のwaのカウントを避けている。
        continue
    if s == 'AC':
        ac += 1
        already.add(p) # acするとalreadyにpを追加 集合への値追加はaddを用いる。
        sum_wa += wa[p]
    else:
        wa[p] += 1 #{1: 3, 2: 2, 3: 0, 4: 5 ...}のように辞書が作られていく。

# print(ac, sum(wa[i] for i in wa.keys())) のようにするとac出来ていないwaについても数えてしまうので×
print(ac, sum_wa)

Measured memory_bytes: 19620
#include<iostream>
using namespace std;
int main(){
	int a, b, c,x,y;

	cin >> a   >> b  >> c;

	y = 0;
	for (int p = a; p <= b; p++)

	{
		x = c%p;

		if (x == 0)
		{
			
			y = y + 1;
		}


	}

	cout << y << endl;

	return 0;
}

Measured memory_bytes: 3100
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

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

Measured memory_bytes: 3608
#include <assert.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

const int maxn = 100 + 10;
char s[maxn];
int main(int argc, char **argv) {
    int n;
    scanf("%d", &n);
    scanf("%s", s);
    int cnt = 0;
    int best = 0;
    for (int i = 0; i < n; i++) 
        if (s[i] == '(') cnt++;
        else {
            cnt--;
            if (cnt < best) best = cnt;
        }
    for (int i = 0; i < -best; i++) putchar('(');
    cnt -= best;
    printf("%s", s);
    for (int i = 0; i < cnt; i++) putchar(')');
    puts("");
    return 0;
}


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

int main() {
  int s[4];
  bool yymm, mmyy;
  for ( int i = 0; i < 4; i++ ) {
    char t;
    cin >> t;
    s[i] = t - '0';
  }
  yymm = mmyy = false;

  if (s[0] == 0 && s[1] != 0 ) { mmyy = true; }
  if ( s[0] == 1 ) {
    mmyy = (0<= s[1] && s[1] <= 2) ? true : false;
  }
  if (s[2] == 0 && s[3] != 0 ) { yymm = true; }
  if ( s[2] == 1 ) {
    yymm = (0<= s[3] && s[3] <= 2) ? true : false;
  }


  if ( yymm && mmyy ) { cout << "AMBIGUOUS" << endl; } else
  if ( yymm ) { cout << "YYMM" << endl; } else
  if ( mmyy ) { cout << "MMYY" << endl; } else
  { cout << "NA" << endl; }
  

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
#define ll long long
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define f first
#define s second

const int maxn = 200010;

int A[maxn];

int main() {
	int X; cin >> X;
	if (X >= 30) cout << "Yes";
	else cout << "No";
	
}


Measured memory_bytes: 3596
(defun table-tennis-training ()
  (let ((n (read))
        (a (read))
        (b (read))
        (ans 0))
    (if (evenp (- b a))
        (setf ans (/ (- b a) 2))
        (if (< (- a 1) (- n b))
            (setf ans (+ (- a 1) 1 (/ (- b a 1) 2)))
            (setf ans (+ (- n b) 1 (/ (- b a 1) 2)))))
    ans))

(format t "~d~%" (table-tennis-training))


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

bool sunuke[100];

int main(){
    int n,k;
    cin >> n >> k;
    /**/
    for(int i = 0;i < n;i++){
        sunuke[i] = 0;
    }
    for(int i = 0;i < k;i++){
        int d;
        cin >> d;
        for(int j = 0;j < d;j++){
            int a;
            cin >> a;
            sunuke[a - 1] = 1;
        }
    }
    /**/
    int ans = 0;
    for(int i = 0;i < n;i++){
        if(sunuke[i] == 0){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
const int maxn = 2e5+100;

const ll inf = 1e18;
vector < int > g[maxn];
int arr[maxn];
int n , m ;
map < int , bool > mp;
int visit[maxn];
int visit2[maxn];
int ans = 0;

void dfs(int u){
    if(visit[u] == true)return;
    visit[u] = true;
    mp[arr[u]] = true;
    for(auto v : g[u])dfs(v);
}

void coun(int u){
    if(visit2[u] == true)return;
    if(mp[u] == true)ans++;
    visit2[u] = true;
    for(auto v : g[u])coun(v);
}


int main()
{
    cin >> n >> m;
    for(int i = 1; i<=n; i++)cin >> arr[i];
    for(int j = 1; j<=m; j++){
        int u , v ; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i<=n; i++){
        dfs(i); coun(i);
        mp.clear();
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 19328
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
#define MAXNUM 100000
using namespace std;
typedef long long ll;

int main(){
  int n, k; cin >> n >> k;
  int a[MAXNUM], ans = 0;
  REP(i, n)   cin >> a[i];

  while(n > k){
    ans++;
    n++;
    n -= k;
  }
  ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x;
	for(int i=1;cin>>x;i++) {
		if(x==0) break;
		cout<<"Case "<<i<<": "<<x<<'\n';
	}
	return 0;
}



Measured memory_bytes: 3152
#include<stdio.h>  // ??????????????????ASCII??§?§£??????ver
int main(){
    char moji;
    int num, sum = 0, count = 0;
    for(;;){
        scanf("%c", &moji);
        if( moji == '0' && count == 0){
            break;
        }else{

            num = moji - 48;
            if( moji == '\n' ){
                printf("%d\n", sum);
                sum = 0;
                count = 0;
                continue;
            }
            sum += num;
            count += 1;
        }

    }
    return 0;
}

Measured memory_bytes: 536
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
char test[3001][3001]; int O[3001][3001], I[3001][3001];
int main() {
	long long n, w, ans = 0; char a; cin >> n >> w;
	for (int h = 1; h <= n; h++) {
		for (int i = 1; i <= w; i++) {
			cin >> a; test[h][i] = a;
		}
	}
	for (int h = 1; h <= n; h++) {
		int s = 0;
		for (int i = w; i > 0; i--) {
			if (test[h][i] == 'O') {
				s++; O[h][i] = s;
			}
			else {
				O[h][i] = s;
			}
		}
	}
	for (int h = 1; h <= w; h++) {
		int t = 0;
		for (int i = n; i > 0; i--) {
			if (test[i][h] == 'I') {
				t++; I[i][h] = t;
			}
			else {
				I[i][h] = t;
			}
		}
	}
	for (int h = 1; h <= n; h++) {
		for (int i = 1; i <= w; i++) {
			if (test[h][i] == 'J') {
				ans += O[h][i] * I[h][i];
			}
		}
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 82240
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();
		System.out.println(a % 2 == 0 || b % 2 == 0 ? "Even" : "Odd");
	}
}


Measured memory_bytes: 22996
package main

import (
	"fmt"
)

func main(){
	var A, B, K int
	qtd := 0
	fmt.Scanf("%d %d %d", &A, &B, &K)
	if A > K {
		fmt.Println(0)
		return
	}
	for i:=1; i<=K; i++ {
		if i%A == 0 {
			qtd += B
		}
	}
	fmt.Println(qtd)
}

Measured memory_bytes: 512
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n, k, *a = map(int, read().split())

    cur_town = 0
    tran_time = defaultdict(int)
    cnt = 0
    while True:
        if k == 0:
            print(cur_town + 1)
            sys.exit()
        if cur_town in tran_time:
            break
        else:
            tran_time[cur_town] = cnt
            cur_town = a[cur_town] - 1
            cnt += 1
            k -= 1
    k2 = k % (cnt - tran_time[cur_town])
    while k2 > 0:
        k2 -= 1
        cur_town = a[cur_town] - 1
    print(cur_town + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 33320
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	cout << a * b / 2 << endl;
	return 0;
}

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

int main(){
  ll n,k;
  cin>>n>>k;
  ll p[n];
  rep(i,n){
    cin>>p[i];
  }
  ll s[n+1];
  s[0]=0;
  rep(i,n){
    s[i+1]=s[i]+p[i];
  }
  long double ans=0;
  rep(i,n-k+1){
    ll kotae=s[k+i]-s[i];
  if(kotae>ans){
    ans=kotae;
  }
}
cout<<fixed<<setprecision(7)<<(ans+double(k))/2<<endl;
}

Measured memory_bytes: 3328
'''input
3 5
1 2 1
2 3 0
'''
# connected components
from sys import stdin, setrecursionlimit
from bisect import bisect_left
import sys, threading
#


def get_cost(m, h):
    if m == 'r':
        if h == 'p':
            return paper
    elif m == 's':
        if h == 'r':
            return rock
    else:
        if h == 's':
            return scissor
    return 0


def make(first, second):
    return str(first) + ' ' + str(second)


def brute(string, index, last, dp):
    if index == len(string):
        return 0
    x = -float('inf'); y = -float('inf'); z = -float('inf')
    if make(index, last) in dp:
        return dp[make(index, last)]
    if index != 0:
        if last != 'p':
            x = get_cost(string[index], 'p') + brute(string, index + 1, 'p', dp)
        if last != 's':
            y = get_cost(string[index], 's') + brute(string, index + 1, 's', dp)
        if last != 'r':
            z = get_cost(string[index], 'r') + brute(string, index + 1, 'r', dp)

    else:
        x = get_cost(string[index], 'p') + brute(string, index + 1, 'p', dp)
        y = get_cost(string[index], 's') + brute(string, index + 1, 's', dp)
        z = get_cost(string[index], 'r') + brute(string, index + 1, 'r', dp)
    dp[make(index, last)] = max(x, y, z)
    return max(x, y, z)

#
# def solve(string):
#     dp = [[0 for x in range(3)] for y in range(len(string))]
#     if string[0] == 'r':
#         dp[0] = [0, 0, paper]
#     elif string[0] == 's':
#         dp[0] = [rock, 0, 0]
#     else:
#         dp[0] = [0, scissor, 0]
#
#     for i in range(1, len(string)):
#         if string[i] == 'r':
#             dp[i][0] = max(dp[i - 1][1], dp[i - 1][2])
#             dp[i][1] = max(dp[i - 1][0], dp[i - 1][2])
#             dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + paper
#         elif string[i] == 's':
#             dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + rock
#             dp[i][1] = max(dp[i - 1][0], dp[i - 1][2])
#             dp[i][2] = max(dp[i - 1][0], dp[i - 1][1])
#         else:
#             dp[i][0] = max(dp[i - 1][1], dp[i - 1][2])
#             dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + scissor
#             dp[i][2] = max(dp[i - 1][0], dp[i - 1][1])
#     # print(dp)
#     return max(dp[-1])

# main starts
paper = 0
scissor = 0
rock = 0
def main():
    global paper, rock, scissor
    n, k = list(map(int, stdin.readline().split()))
    rock, scissor, paper = list(map(int, stdin.readline().split()))
    string = stdin.readline().strip()
    cost = 0
    for i in range(k):
        temp = []
        j = i
        while j < n:
            temp.append(string[j])
            j += k
        dp = dict()
        cost += brute(temp, 0, '$', dp)
    print(cost)

if __name__ == "__main__":
    sys.setrecursionlimit(200005)
    threading.stack_size(1 << 27)
    thread = threading.Thread(target=main)
    thread.start()

Measured memory_bytes: 123676
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

int cntDiv2(i64 n) {
    int cnt = 0;
    while (n > 0 && n % 2 == 0) ++cnt, n /= 2;
    return cnt;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    i64 N, M;
    read(N, M);

    vector<i64> a(N);
    vector<i64> p(N);
    rep(i, N) {
        read(a[i]);
        p[i] = cntDiv2(a[i]);
    }
    if (count(all(p), p[0]) != N) {
        print(0);
        return 0;
    }

    const auto lcm = [](i64 a, i64 b) {
        return a / __gcd(a, b) * b;
    };
    i64 m = 1;
    rep(i, N) {
        m = lcm(m, a[i] / 2);
        if (m > M) {
            m = -1;
            break;
        }
    }

    if (m == -1) {
        print(0);
    } else {
        print((M / m + 1) / 2);
    }

    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int a;
    int b;
    cin >> a >> b;
    int n;
    cin >> n;
    vector<int> s(n);
    vector<int> f(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
        cin >> f[i];
    }
    for(int i = 0; i < n; i++){
        if(b > s[i] && a < f[i]){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


Measured memory_bytes: 3120
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var m = int.Parse(line[0]);
        var n = int.Parse(line[1]);
        var k = int.Parse(Console.ReadLine().Trim());
        var mapJ = new int[m, n];
        var mapO = new int[m, n];
        for (int i = 0; i < m; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s[0] == 'J') mapJ[i, 0] = 1;
            else if (s[0] == 'O') mapO[i, 0] = 1;
            for (int j = 1; j < n; j++)
            {
                mapJ[i, j] = mapJ[i, j - 1];
                mapO[i, j] = mapO[i, j - 1];
                if (s[j] == 'J') mapJ[i, j]++;
                else if (s[j] == 'O') mapO[i, j]++;
            }
        }
        for (int i = 0; i < k; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line2[0]) - 1;
            var b = int.Parse(line2[1]) - 1;
            var c = int.Parse(line2[2]) - 1;
            var d = int.Parse(line2[3]) - 1;
            var cJ = 0; var cO = 0;
            var t = (c - a + 1) * (d - b + 1);
            for (int j = a; j <= c; j++)
                if (b - 1 >= 0)
                {
                    cJ += mapJ[j, d] - mapJ[j, b - 1];
                    cO += mapO[j, d] - mapO[j, b - 1];
                }
                else
                {
                    cJ += mapJ[j, d];
                    cO += mapO[j, d];
                }
            Console.WriteLine("{0} {1} {2}", cJ, cO, t - (cJ + cO));
        }
    }
}


Measured memory_bytes: 21728
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var s = nextCharArray();
	var map = {};
	for(var i = 0; i < s.length; i++){
		if(map[s[i]] == null){
			map[s[i]] = 0;
		}else{
			map[s[i]]++;
		}
	}
	var output = s.length * (s.length + 1) / 2;
	output -= s.length;
	output++;
	var keys = Object.keys(map);
	for(var i = 0; i < keys.length; i++){
		output -= map[keys[i]] * (map[keys[i]] + 1) / 2;
	}
	myout(output);
}


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

int main()
{
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    vector<string>ss(n);
    int mn=100;
    for(int i=0;i<n;i++)
        cin >> ss[i];
    
    string ans="";

    vector<int>cnts(26,100);

    for(int j=0;j<n;j++){
        int l=ss[j].length();
        vector<int>temp(26,0);
        for(int k=0;k<l;k++)
            temp[ss[j][k]-'a']++;
        for(int i=0;i<26;i++)
            cnts[i]=min(cnts[i],temp[i]);
    }
    
    for(int i=0;i<26;i++){
        for(int j=0;j<cnts[i];j++)
            cout << (char)(i+'a');
    }

    return 0;
}

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

#define SQ(a) (a)*(a)

#define F0R(i, a) for(int i = 0; i < (a); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define R0F(i, a) for(int i = (a) - 1; i >= 0; i--)
#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); i--)

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define UB upper_bound
#define LB lower_bound
#define X real()
#define Y imag()
#define MAXN 100000

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<ld> point;

int n, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    F0R(i, n) cin >> a[i];
    int res = 0;
    F0R(i, n - 1) {
        if(a[i] == i + 1) {
            swap(a[i], a[i + 1]);
            res++;
        }
    }
    if(a[n - 1] == n) res++;
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();
		int dist = b - a;
		if(dist <= 0){
			System.out.println("delicious");
		}else if(dist <= x){
			System.out.println("safe");
		}else{
			System.out.println("dangerous");
		}
		in.close();
	}
}


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

int MOD =1000000007;
int com[8]={1,1,2,3,5,8,13,21}; //i個のあみだ1段で何通り作れるか

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    //dp[i][j]
    //H=i, K=jのときのsubproblem
    //

    long long dp[110][10];
    for(int i=0; i<110; i++){
        for(int j=0; j<10; j++){
            dp[i][j]=0;
        }
    }
    dp[0][1]=1;

    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(j!=1){ //j-1からくるパターンを足す
                dp[i][j] += dp[i-1][j-1]*com[j-2]*com[W-j];
                dp[i][j]  = dp[i][j] % MOD;
            }
            if(j!=W){
                dp[i][j] += dp[i-1][j+1]*com[j-1]*com[W-j-1];
                dp[i][j]  = dp[i][j] % MOD;
            }
            dp[i][j] += dp[i-1][j]*com[j-1]*com[W-j];
            dp[i][j]  = dp[i][j] % MOD;
        }
    }

    cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> h(n);
    cin >> h;
    int ans = 1;
    for(int i = 1; i < n; i++) {
        ans += h[i] >= *max_element(h.begin(), h.begin() + i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            HashMap<String, String> map = new HashMap<>();
            for (int j = 1; j < s.length(); j++) {
                String f = s.substring(0, j);
                String l = s.substring(j, s.length());
                map.put(f+l,"");
                map.put(f+r(l),"");
                map.put(r(f)+l,"");
                map.put(r(f)+r(l),"");
                map.put(l+f,"");
                map.put(l+r(f),"");
                map.put(r(l)+f,"");
                map.put(r(l)+r(f),"");
            }
            System.out.println(map.size());
        }
    }
    
    public static String r(String s) {
        return new StringBuffer(s).reverse().toString();
    }
}

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

int main() {
  int n,m,point[101] = {0};
  int x,top,topnum;
  while(cin >> n >> m) {
    int point[101] = {0};
    if((n ==0)&&(m == 0)) break;
    for(int i=1;i<n+1;i++) {
      for(int j=1;j<m+1;j++) {
        cin >> x;
        point[j] += x;
      }
    }

    for(int i=1;i<m+1;i++) {
      top = -1;
      topnum = 0;
      for(int j=1;j<m+1;j++) {
        if(point[j] > top) {
          top = point[j];
          topnum = j;
        }
      }
      if(i == m) {
        printf("%d",topnum);
        break;
      }
      printf("%d ",topnum);
      point[topnum] = -2;
    }
    printf("\n");
  }
}

Measured memory_bytes: 876
using System;

namespace ConsoleApplication26
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int n = int.Parse(N);
            string[] xinput = Console.ReadLine().Split(' ');
            string[] yinput = Console.ReadLine().Split(' ');
            //p=1.2??????
            for (int j = 0; j < 3; j++)
            {
                double sum = 0;
                double D = 0;
                double p = j + 1;
                for (int i = 0; i < n; i++)
                {
                    double x = double.Parse(xinput[i]);
                    double y = double.Parse(yinput[i]);
                    double zettai = Math.Abs(x - y);
                    double jou = Math.Pow(zettai, p);
                    sum += jou;
                }
                D = Math.Pow(sum, 1 / p);
                Console.WriteLine(D);
            }
            //p??????
            double z = 0;
            for (int i = 0; i < n; i++)
            {
                double x = double.Parse(xinput[i]);
                double y = double.Parse(yinput[i]);
                double zettai = Math.Abs(x - y);
                z = Math.Max(z, zettai);
            }
            Console.WriteLine(z);

        }
    }
}

Measured memory_bytes: 9500
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

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

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> v(n);

    rep(i,n) cin >> v[i];
    rep(i,n) {
        int c; cin >> c;
        v[i] -= c;
    }
    int ans = 0;
    rep(i,n) {
        if (v[i]>0) ans += v[i];
    }
    cout << ans << endl;
    return 0;
}







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

int main(){
  int a,b;
  string S;
  cin >> a >> b >> S;
  for(int i=1;i<=a;i++){
    if(i==b){
      if(S.at(i-1)=='A'){
        S.at(i-1)='a';
      }
      else if(S.at(i-1)=='B'){
        S.at(i-1)='b';
      }
      else{
        S.at(i-1)='c';
      }
    }
    cout << S.at(i-1);
  }
  cout << endl;
}


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

int main(){
    vector<int> a(5),b(5);int ans=0;
    for(int i=0;i<5;i++) {
        cin>>a.at(i);
        b.at(i)=a.at(i)%10;
        if(b.at(i)==0) ans+=a.at(i);
        else ans+=a.at(i)-b.at(i)+10;
    }
    sort(b.begin(),b.end());
    for(int i=0;i<5;i++){
        if(b.at(i)>0) {
            ans+=b.at(i)-10;
            break;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

LL dp[ 31 ];
LL ans, day, n, cnt;

LL solve( int now ) {
	if ( now < 0 ) {
		return 0;
	}
	if ( dp[ now ] >= 0 ) {
		return dp[ now ];
	}
	if ( now == 0 ) {
		return dp[ now ] = 1;
	}
	LL res = 0;
	for ( int i = 1; i <= 3; i++ ) {
		res += solve( now - i );
	}
	return dp[ now ] = res;
}

int main() {
	memset( dp, -1, sizeof( dp ) );
	while ( ~scanf( "%d", &n ) && n ) {
		day = solve( n );
		ans = day / 3650 + !!( day % 3650 );
		printf( "%lld\n", ans );
	}
	return 0;
}

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

#define NOFILE 1
#define NOARG 2
#define NCOINS 25
#define SMAX 50005

const int inf = (1 << 31) - 1;

int solve (int sum, int *coins, int n)
{
    int min_to_obtain [SMAX];
    int i, j;

    min_to_obtain [0] = 0; //we need 0 coins to obtain the sum 0
    ///initialising the array with an infinite value
    for (i = 1; i <= sum; ++ i)
        min_to_obtain [i] = inf;

    for (i = 0; i < n; ++ i)
    {
        for (j = 1; j <= sum; ++ j)
        {
            if (j >= coins [i])
            {
                if (min_to_obtain [j] > 1 + min_to_obtain [j - coins [i]])
                {
                    min_to_obtain [j] = 1 + min_to_obtain [j - coins [i]];
                }
            }
        }
    }

    return min_to_obtain [sum];

}

int main()
{

    int sum, n, v [NCOINS], i, min_coins = inf;

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

    min_coins = solve (sum, v, n);

    printf ("%d\n", min_coins);


    return 0;
}

Measured memory_bytes: 1216
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
xy = [read_int() for _ in range(N)]

def solve():
    pq = defaultdict(lambda: int())
    res = []
    M = 0
    for i in range(N):
        for j in range(N):
            if i == j: continue
            p, q = xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]
            count = 0
            # print(p,q)
            for ii in range(N):
                for jj in range(N):
                    if ii == jj: continue
                    if xy[ii][0] - xy[jj][0] == p and xy[ii][1] - xy[jj][1] == q:
                        count += 1
            # res.append(count)
            M = max(M, count)
    # print(res)
    ans = N - M
    return ans

if __name__ == "__main__":
    print(solve())

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

int main(){
    string A, B, C;
    cin >> A >> B >> C;

    if(A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
import math
H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

factorial = [1]
inv_factorial = [1]


for i in range(1, H+W+1):
    factorial.append(factorial[-1] * i % MOD)
    inv_factorial.append(pow(factorial[-1], MOD-2, MOD))


def f(h, w):
    return (factorial[h+w-2] * inv_factorial[h-1] * inv_factorial[w-1]) % MOD


answer = 0
for i in range(B+1, W+1):
    answer += f(H-A, i) * f(A, W-i+1)
    answer %= MOD

print(int(answer))


Measured memory_bytes: 18964