akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

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())

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

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    string s;
    cin >> n >> s;

    int res = 0;
    for (int i = 0; i < n - 2; i++)
    {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
            res++;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
xi = list(map(int, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_l(*numbers):
	ret = numbers[0]
	for n in numbers[1:]:
		ret = gcd(ret, n)
	return ret

xi = map(lambda y:abs(y-x), xi)
print(gcd_l(*xi))

Measured memory_bytes: 14224
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_H = 800, MAX_W = 800;
int H, W, K;
char field[MAX_H][MAX_W];
int dist[MAX_H][MAX_W];

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

  cin >> H >> W >> K;
  rep(i, H) {
      rep(j, W) {
          cin >> field[i][j];
      }
  }

  int sx = 0, sy = 0;
  rep(i, H) {
      rep(j ,W) {
          if (field[i][j] == 'S') {
              sx = i; sy = j;
          }
      }
  }

  queue<Pii> que;
  memset(dist, -1, sizeof(dist));
  dist[sx][sy] = 0;
  que.push(Pii(sx, sy));
  while(!que.empty()) {
      Pii pii = que.front(); que.pop();
      for (int k = 0; k < 4; ++k) {
          int x = pii.fi + dx[k], y = pii.sc + dy[k];
          if (0 <= x && x < H && 0 <= y && y < W && field[x][y] != '#' && dist[x][y] < 0) {
              dist[x][y] = dist[pii.fi][pii.sc] + 1;
              que.push(Pii(x, y));
          }
      }
  }

  int ans = INFINT;
  rep(i, H) {
      rep(j, W) {
          if (0 <= dist[i][j] && dist[i][j] <= K) {
              int d = min(i, min(j, min(H-i-1, W-j-1)));
              ans = min(ans, (d+K-1)/K + 1);
          }
      }
  }

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


Measured memory_bytes: 3456
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, D[101000][2], Mod = 1000000007;
vector<int>E[101000];
void DFS(int a, int pp) {
	D[a][0] = D[a][1] = 1;
	for (auto &x : E[a]) {
		if (x == pp)continue;
		DFS(x, a);
		D[a][0] = 1ll * D[a][0] * D[x][1] % Mod;
		D[a][1] = 1ll * D[a][1] * (D[x][0]+D[x][1]) % Mod;
	}
}
int main() {
	int i, j, k, a, b;
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	DFS(1, 0);
	printf("%d\n", (D[1][0] + D[1][1]) % Mod);
}

Measured memory_bytes: 10752
#include <iostream>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int a[m];
  int sum=0;
  for(int i = 0; i < m; i++){
    cin >> a[i];
    sum+=a[i];
  }
  if(n-sum<0)cout << -1 << endl;
  else cout << n-sum << endl;
  return 0;
}


Measured memory_bytes: 3648
s=str(input())

lists=list(s)
n=len(lists)

ans1=0
ans2=0

for i in range(n):
	if i%2==0:
		if lists[i]=="0":
			ans1=ans1+1
	elif i%2==1:
		if lists[i]=="1":
			ans1=ans1+1
			
for i in range(n):
	if i%2==0:
		if lists[i]=="1":
			ans2=ans2+1
	elif i%2==1:
		if lists[i]=="0":
			ans2=ans2+1

print(min(ans1,ans2))

Measured memory_bytes: 49392
#include <bits/stdc++.h>
using namespace std;
 
main(){
  int N, M;
  cin >> N;
  vector<string> blue(N);
  vector<int> sum(N);
  for(int i=0; i<N; i++){
    cin >> blue.at(i);
  }
  cin >> M;
  vector<string> red(M);
  for(int i=0; i<M; i++){
    cin >> red.at(i);
  }
  for(int i=0; i<N; i++){
    for(int x=0; x<N; x++){
      if(blue.at(i) == blue.at(x)){
        sum.at(i) ++;
      }
    }
    for(int y=0; y<M; y++){
      if(blue.at(i) == red.at(y)){
        sum.at(i) --;
      }
    }
  }
  int ans = sum.at(0);
  for(int i=0; i<N; i++){
    if(ans <= sum.at(i)){
      ans = sum.at(i);
    }
    else{
      continue;
    }
  }
  if(ans < 0){
    cout << 0 << endl;
  }
  else{
    cout << ans << endl;
  }
}

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

int main(int argc, char const *argv[])
{
//    freopen("in.txt", "r", stdin);
    int n, d;
    cin >> n >> d; 
    if(n%(d*2+1) == 0){
        cout << n / (d*2+1) <<endl;
    }else {
        cout << (n / (d*2+1))+1 <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S = [x - ord('A') for x in read().rstrip()]
S = [(x + N) % 26 for x in S]

answer =  ''.join(chr(x + ord('A')) for x in S)
print(answer)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <atcoder/all>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using namespace atcoder;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const int INF = 1e9;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<long double,long double> point;
typedef complex<long double> Point;
const ll MAX = 100005;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q;
    cin >> n >> q;
    dsu d(n);
    rep(i,q){
        ll t,u,v;
        cin >> t >> u >> v;
        if (t == 0) d.merge(u,v);
        else{
            if (d.same(u,v)) PRINT(1);
            else PRINT(0);
        }
    }
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, x;
  while (cin >> a >> b >> x) {
    cout << (a <= x && x <= a + b ? "YES" : "NO") << endl;
  }
  
  return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll mod = 1000000007;

static const ll INF = 1e15;


int main(void)	
{
	ll n;
	cin >> n;
	ll a, b;
	cin >> a >> b;
	ll ab = a + b;
	ll c = n / ab;
	ll d = n % ab;
	d = min(d, a);
	ll sum = a * c + d;
	cout << sum << endl;
	return 0;
}



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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 02:27:58 2018

@author: Yuki
"""

N = int(input())
data  = []
for i in range(N-1):
    c, s, f = map(int, input().split())
    data.append([c, s, f])

def train_time(start_time=0, data_list=[12, 24, 6]):
    if data_list[1] <= start_time:
        return start_time + (data_list[2] - start_time%data_list[2])%data_list[2] + data_list[0]
    else:
        return data_list[1] + data_list[0]

#N = 4
#data = [[12, 24, 6], [52, 16, 4], [99, 2, 2]]

res = []
for i in range(N-1):
    need_time = 0
    for ii in range(i, N-1):
        need_time = train_time(need_time, data[ii])
    res.append(need_time)

for i in range(N-1):
    print(res[i])
print(0)

Measured memory_bytes: 3188
N=int(input())
p=list(int(i) for i in input().split())
p_sorted=sorted(p)
sum=0
for i in range(N):
  if p[i]==p_sorted[i]:
    sum+=1
if sum==N-2 or sum==N:
  print('YES')
else:
  print('NO')
 

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

int main(){
	int N;
	cin>>N;
	long H[N];
	for(int i=0;i<N;++i){
		cin>>H[i];
	}
	int sa = 0;
	bool ans = true;
	for(int i=0;i<N-1;++i){
		if(H[i]-H[i+1]>=0)sa+=H[i]-H[i+1];
		else sa = 0;
		if(sa>1){
			ans=false;
			break;
		}
	}
	if(ans==false)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		//入力の読み込み
		Scanner sc = new Scanner(System.in);
		long num = sc.nextLong();
		long blue = sc.nextLong();
		long red = sc.nextLong();

		//青と赤のセットを置いた際の余りの数で判断
		long remainder = num%(blue+red);  //置いた際の余り
		long countBlue = num/(blue+red)*blue;  //上記の際の青の数

		if(remainder >= blue) {  //余りが青の数よりも多い場合
			countBlue += blue;  //全ての青の数を足す
		}
		else {                      //余りが青よりも少ない場合
			countBlue += remainder;  //余りの分だけ青を足す
		}
		System.out.print(countBlue);
		sc.close();
	}
}


Measured memory_bytes: 23764
/***********************************************
#
#      Filename: d.cpp
#
#        Author: Comsyl - ylsong15@fudan.edu.cn
#   Description: ---
#        Create: 2017-06-09 19:14:05
***********************************************/
#include <bits/stdc++.h>
using namespace std;
int a[100000 + 10];
int N, A, B;

bool could(int times) {
    int rest = times;
    int com = B * times;
    for (int i = 0; i < N; ++ i) {
        if (a[i] <= com) continue;
        int used = (a[i] - com) / A + ((a[i] - com) % A ? 1 : 0);
        rest -= used;
        if (rest < 0) return false;
    }
    return true;
}

int main()
{
    cin >> N >> A >> B;
    A -= B;
    for (int i = 0; i < N; ++ i) {
        cin >> a[i];
    }
    int ans = -1;
    int low = 0, high = (*max_element(a, a+N)) / B + 1;
    while (low <= high) {
        int mid = low + (high - low) / 2;
        if (could(mid)) {
            ans = mid;
            high = mid - 1;
        } else {
            low = mid + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	ll h,w;
	while(true){
		cin >> h >> w;
		if(h==0&&w==0)
			break;
		rep(i,h){
			rep(j,w){
				if(i==0||i==h-1)
					cout << "#";
				else if(j==0||j==w-1)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,S;
int a[25][25];
int dp[2500005];
int t[2500005];
vector<int> f[25];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=1;i<=n;i++) t[1<<(i-1)]=i;
	S=1<<n;
	dp[0]=1;
	for(int i=1;i<S;i++){
		int x=i,y=0;
		while(x){
			x^=x&-x;
			y++;
		}
		f[y].push_back(i);
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<f[i].size();j++){
			int x=f[i][j];
			while(x){
				if(a[i][t[x&-x]]){
					dp[f[i][j]]+=dp[f[i][j]^(x&-x)];
					dp[f[i][j]]%=mod;
				}
				x^=x&-x;
			}
		}
	}
	printf("%d\n",dp[S-1]);
	
	return 0;
}

Measured memory_bytes: 23996
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int N = 1e5 + 1;
const int INF = 1e9;
int dp[N], h[N];

void min_self(int &a, int b) {
	a = min(a, b);
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &h[i]);
	for (int i = 1; i < n; i++) dp[i] = INF;
	for (int i = 0; i < n; i++) {
		if (i + 1 < n) min_self(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
		if (i + 2 < n) min_self(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
	}
	printf("%d\n", dp[n-1]);
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
using namespace std;

int swap(int& a, int& b){
	int c;
	c=a;a=b;b=c;
	return 1;
}

int main(){
	int cup[3] = {1,0,0};
	unsigned char s1='A', s2='A';

	while( ~scanf("%c,%c\n", &s1, &s2) ){
		swap( cup[s1-'A'] , cup[s2-'A'] ) ;
		
	}
	printf("%c\n", cup[0]*'A' + cup[1]*'B' + cup[2]*'C');
	

	return 0;
}

Measured memory_bytes: 0
r, c = map(int, input().split())
num_list = []
for i in range(r):
    l = list(map(int, input().split()))
    l.append(sum(l))
    num_list.append(l)
s_list = []
for j in range(c + 1):
    s = 0
    for l in num_list:
        s += l[j]
    s_list.append(s)
num_list.append(s_list)
for i in range(r + 1):
    print(*num_list[i])



Measured memory_bytes: 6232
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second                                                                                                                                                                                                                                                                                                                
#define f first
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000
#define mod 1000000007
#define inf 1000000000000000000
#define mI2 500000004
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll dp[n+1];
    dp[0]=0;
    for(ll i=1;i<=n;i++){
        dp[i]=inf;
    }
    for(ll i=0;i<n;i++){
        dp[a[i]]=min(dp[a[i]],dp[a[i]-1]+1);
    }
    ll ans=-1;
    for(ll i=1;i<=n;i++){
        //debugg(dp[i]);
        if(dp[i]!=inf){
            ans=max(ans,dp[i]);
        }
    }
    if(ans==-1){
        ans=n+1;
    }
    
    cout<<n-ans<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N;
    vec a(N);
    rep(i,N) cin>>a.at(i);
    mat dp(N,vec(N,0));//0-indexed;
    int t = (N&1)*2 - 1;
    rep(i,N) dp[i][i] = t*a[i];
    for(int i = N-1;i>=0;--i){
        t *= -1;
        int plus = N-i;
        rep(j,i){
            if(t == -1){
                dp.at(j).at(j+plus) = min(dp.at(j).at(j+plus-1)-a.at(j+plus),
                                        dp.at(j+1).at(j+plus)-a.at(j));
            }else{
                dp.at(j).at(j+plus) = max(dp.at(j).at(j+plus-1)+a.at(j+plus),
                                        dp.at(j+1).at(j+plus)+a.at(j));
            }
        }

    }
    /*rep(i,N){
        rep(j,N){
            cout<<dp[i][j]<<' ';
        }
        cout<<endl;
    }*/
    cout<<dp[0][N-1]<<endl;
}

Measured memory_bytes: 70784
#include<stdio.h>
int main()
{
    int i,n,j,p;
    scanf("%d",&n);
    int a[n];
    for(i=1;i<=n;i++)
    {
       scanf("%d",&a[i]);
    }
   int cnt=0;
   for(i=1;i<=n;i++)
   {
       if(i%2!=0)
       {
          if(a[i]%2!=0)
          {
              cnt++;
          }
       }
   }
   printf("%d",cnt);
}


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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  
  int a1 = 1;
  int an = n;
  int answer = ((a1 + an)*n)/2;
  
  cout << answer << "\n";
  
  return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
#define int long long
//#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define prique2(T) priority_queue<T>
struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
const int mod2 = 998244353;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
		fact_memo[i + 1] = ans;
	}
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

map<int, int>factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			n /= i;
			ans[i]++;
		}
	}
	if (n != 1) ans[n]++;
	return ans;
}

P operator+(const P& a, const P& b) {
	return P(a.first + b.first, a.second + b.second);
}
P operator-(const P& a, const P& b) {
	return P(a.first - b.first, a.second - b.second);
}

int n;
double ans;
signed main() {
	cin >> n;
	rep(i, n) {
		double a;
		cin >> a;
		ans += (1.0 / a);
	}
	printf("%.10lf\n", 1.0 / ans);
}


Measured memory_bytes: 256
can = True
e = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(int(input()))]
for a, b in zip(e[1:], e):
    dt = a[0] - b[0]
    dist = abs(a[1] - b[1]) + abs(a[2] - b[2])
    if dt < dist: can = False; break
    if dt % 2 != dist % 2: can = False; break
print(['No', 'Yes'][can])

Measured memory_bytes: 28168
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans = 10000
minnum = float('inf')
for i in range(N):
  if abs(T-H[i]*0.006-A) < minnum:
    minnum = abs(T-H[i]*0.006-A)
    ans = i+1
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(void){
    int n,i,j;
    int a=0,b=0,min;
    char A[150],B[150];

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s %s",A,B);
        if(!strcmp(A,B)){
            //printf("same word a+1 b+1\n");
            a++;
            b++;
        }else{
            if(strlen(A)>strlen(B)) min=strlen(B);
            else min=strlen(A);

            for(j=0;j<min;j++){
                //printf("compare %c vs %c\n",A[j],B[j]);
                if(A[j]>B[j]){
                    //printf("A>B a+3 point\n");
                    a+=3; 
                    break;
                }else{
                    if(A[j]<B[j]){
                        //printf("A<B b+3 point\n");
                        b+=3; 
                        break;
                    }
                }
                if(j==min-1){
                    if(strlen(A)>strlen(B)) a+=3;
                    else b+=3;
                }
                //printf("next word\n");
            }
        }
    }
    printf("%d %d\n",a,b);
    return 0;
}


Measured memory_bytes: 2044
def main():
    N = list(str(input()))
    n = int("".join(N))
    sum_N = sum(list(map(int,N)))
    if n%10 == 0 and sum_N == 1:
        print(10)
    else:
        print(sum_N)


if __name__ == '__main__':
    main()

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

using namespace std;
int main(){
    string S;
    long long N;
    //cin >> S;
    cin >> N;

    long ans = 0;
    for (long i = N-1; i > (N-1)/2; i--)
    {
        if (i+(N-i)==N&&i!=N-i)
        {
            ans++;
        }
        
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)
bi = [0]*(A[0]+1)
for a in A:
  bi[a]+=1
  
cum = [0]*(A[0]+1)
for i in range(1,A[0]+1):
  cum[i]=cum[i-1]+bi[i]

cum_max=cum[-1]
left = 0
right = A[0]*2+1
while right-1!=left:
  x = (right+left)//2
  num = 0
  for a in A:
    b = max(x-a,1)
    if b<=A[0]:
      num += cum_max-cum[b-1]
    
  if num>=M:
    left=x
  else:
    right=x

ans = 0
cum_A = [0]*(N+1)
for i in range(1,N+1):
  cum_A[i]=cum_A[i-1]+A[i-1]
for a in A:
  b = max(right-a,1)
  if b>A[0]:
    break
  c = cum_max-cum[b-1]
  M-=c
  ans+=(a*c)+cum_A[c]
  

ans+=M*left
print(ans)


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

long long segtree[4*200010];


void add(int node,int l,int r, int x,long long val)
{

   if(l>=x && x>=r)
   {

     segtree[node]=val;
     return;

   }
   if(x>r || l>x)
   return;

   int left=node<<1;
   int lr=(l+r)>>1;
   add(left,l,lr,x,val);
   add(left|1,lr+1,r,x,val);


   segtree[node]=max(segtree[left],segtree[left|1]);

}
long long query(int node,int l,int r,int ll,int rr)
{

 if(l>=ll && r<=rr)
 return segtree[node];

 if(r<ll || l>rr)
 return 0;

 int left=node<<1;
   int lr=(l+r)>>1;


   return max(query(left,l,lr,ll,rr),query(left|1,lr+1,r,ll,rr));

}

int main()
{
   int n;
   cin>>n;
   long long height[n+5];
   long long power[n+5];
   for(int i=1;i<=n;i++)
   {
   cin>>height[i];

   }
    for(int i=1;i<=n;i++)
   {
   cin>>power[i];

   }
   long long dp[n+1];
   long long ans=0;
   for(int i=1;i<=n;i++)
   {

       long long q=query(1,1,n,1,height[i]);
       dp[height[i]]=q+power[i];
       ans=max(ans,dp[height[i]]);
       add(1,1,n,height[i],dp[height[i]]);

   }
   cout <<ans<<endl;
}






Measured memory_bytes: 11008
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int a, b;
  scanf("%d %d", &a, &b);

  int ans;
  if(a >= 13)ans = b;
  else if(a >= 6)ans = b/2;
  else ans = 0;

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


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

int main() {
  int N,A,B,ans;
  ans=0;
  cin>>N>>A>>B;
  for(int i=0;i<N+1;i++){
    int total=i%10+(i/10)%10+(i/100)%10+(i/1000)%10+i/10000;
    if(total>=A && total<=B){
      ans+=i;
    }
  }
  cout<<ans<<endl;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n;
    Scd(n);
    int a;
    int ans = 0;
    Rep(i,n){
        Scd(a);
        if( a%2 ) ans = 1;
    }

    if( ans ) printf ("first\n");
    else printf("second\n");

    return 0;
}



Measured memory_bytes: 256
N = int(input())
S = list(map(int, input().split()))
 
final_list = [0 for _ in range(N)]
ans_list = []
for n in reversed(range(N)):
    i = n+1
    quot = N // i
    rem = S[n]
    count = 0
    for j in range(1, quot+1):
        tmp_a = final_list[i*j -1]
        count ^= tmp_a
    if rem != count:
        final_list[n] = 1 
        ans_list.append(i)
        
print(len(ans_list))
print(' '.join(map(str, ans_list)))

Measured memory_bytes: 19820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define input(n) scanf("%d",&n)
#define llinput(n) scnaf("%lld",&n)
set<int> snu;
map<ll,ll> mm;
int main()
{
  int n,m;
  cin>>n>>m;
  ll arr[n];
  for(int i = 0;i<n;i++)
  {cin>>arr[i];mm[i]++;}
  int c = 0;
  while(m--)
  {
    ll a,b;
    cin>>a>>b;
    
    if(arr[a-1]<=arr[b-1]&&mm[a-1]!=-1){c++;mm[a-1]=-1;}
    
    if(arr[b-1]<=arr[a-1]&&mm[b-1]!=-1){c++;mm[b-1]=-1;}
  }
  cout<<n-c;
}


Measured memory_bytes: 10664
#!/usr/bin/env python3

import sys
from collections import namedtuple

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

Item = namedtuple("Item", ("value", "weight"))

def main():
    n, max_w = read_list(int)
    items = []

    for _ in range(n):
        v, w = read_list(int)
        items.append(Item(v, w))
    
    dp = [0] * (max_w + 1)
    for w_i in range(max_w + 1):
        for i in range(len(items)):
            if w_i >= items[i].weight:
                dp[w_i] = max(dp[w_i], dp[w_i - items[i].weight] + items[i].value)
    print(dp[max_w])

if __name__ == "__main__":
    main()



Measured memory_bytes: 6336
a,b,h,m = map(int,input().split())

# 2辺の角度
## 長針は60分かけて360度を回る
l_rad = 360*(m/60)
## 短針は12時間かけて360度を回る+60分かけて360*(1/12)進む
s_rad = 360*(h/12) + 30*(m/60)

## 角度は
x = abs(s_rad-l_rad)
if x > 180:
    x = 360 - x

import math
print (math.sqrt((a**2)+(b**2)-(2*a*b*math.cos(math.radians(x)))))


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

int main()
{
    ll x, n;
    cin >> x >> n;
    vector<bool> flgs(102, false);
    vector<ll> p(n);
    rep(i, n) {
        cin >> p[i];
        flgs[p[i]+1] = true;
    }

    ll min = 10000;
    ll min_i = 10000;
    for(ll i=101;i>=-1;i--){
        if (flgs[i+1]){
            continue;
        }
        if(abs(x - i) <= min)  {
            min = abs(x-i);
            min_i = i;
        }
    }

    cout << min_i << endl;
}


Measured memory_bytes: 3540
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / __gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m) - 1;i>=(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) n.begin(), n.end()
#define allr(n) n.rbegin(), n.rend()
#define sp(n) cout << fixed << setprecision(n)
#define pi 3.14159265358979323846
#define inf 1000000007
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  int n, m;
  ci(n, m);
  ve<pair<int, int>> A(m);
  rep(i, m){
    int a, b;
    ci(a, b);
    A.at(i) = mp(b, a);
  }
  sort(all(A));
  int cnt = 0 , ans = 0;
  rep(i, m){
    if(A.at(i).sc <= cnt && cnt <= A.at(i).ft){
      con;
    }
    else{
      cnt = A.at(i).ft - 1;
      ans++;
    }
  }
  co(ans);
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: isize,
        a: isize
    };
    for x in 0..=n {
        let xx = 10000 * x;
        for y in 0..=(n - x) {
            let z = n - x - y;
            let sum = xx + 5000 * y + 1000 * z;
            if sum == a {
                println!("{} {} {}", x, y, z);
                return;
            }
        }
    }
    println!("-1 -1 -1");
}


Measured memory_bytes: 2172
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <functional>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)					(a).begin(),(a).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(1000 * 1000 * 1000 * 2)
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N, T;
	cin >> N >> T;
	vector<int> t(N);
	REP(i, N) cin >> t[i];

	int ans = T;
	REP(i, N - 1) {
		int sum = min(t[i + 1] - t[i], T);
		ans += sum;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  set<string> word;
  string temp,prev;
  bool flag=true;
  for(int i=0;i<N;++i){
    cin >> temp;
    if(word.count(temp)){
      flag=false;
    }
    word.insert(temp);
    if(i==0){
      prev=temp;
      continue;
    }
    //cout << "now:" << *begin(temp) << " prev:" << *(prev.end()-1) << endl;
    if(*begin(temp)!=*(prev.end()-1)){
      flag=false;
    }
    prev=temp;	
  }

  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3616
N, M = map(int, input().split())
py = []
for i in range(M):
    p, y = map(int, input().split())
    py += [[i, p, y]]
py = sorted(py, key=lambda x:(x[1], x[2]))
cnt = 0
pre = py[0][1]
ans = []
for n, p, y in py:
    if pre != p:
        cnt = 1
        pre = p
    else:
        cnt += 1
        
    ans += [[n, str(p).zfill(6)+str(cnt).zfill(6)]]

ans = sorted(ans, key=lambda x:x[0])
for _, n in ans:
    print(n)


Measured memory_bytes: 96984
import sys
from collections import defaultdict, deque
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve():
    s1 = getS()
    s2 = getS()
    # print("".join(reversed([c for c in s1])))
    if "".join(reversed([c for c in s1])) == s2:
        print("YES")
    else:
        print("NO")
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 65584
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

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

int main(){
  ll n, k;
  cin >> n >> k;
  ll ans = k * pow(k-1, n-1);
  cout << ans << endl;
}



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

signed main() {
  string s, t;
  cin >> s >> t;

  static int next[202020][26];
  for (int i = 0; i < 202020; i++) {
    for (int j = 0; j < 26; j++) {
      next[i][j] = 2 * s.size();
    }
  }

  string temp = s + s;
  for (int i = 2 * s.size() - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      next[i][j] = next[i + 1][j];
    }
    next[i][temp[i] - 'a'] = i + 1;
  }

  int now = 0;
  for (int i = 0; i < t.size(); i++) {
    int c = t[i] - 'a';
    int x = now % s.size();
    if (next[x][c] == 2 * s.size()) {
      cout << -1 << endl;
      return 0;
    }
    now += next[x][c] - x;
  }

  cout << now << endl;
  return 0;
}

Measured memory_bytes: 41856
Sd = input()
T = input()

def check(A, B):
    for a, b in zip(A, B):
        if a != '?' and a != b:
            return False
    return True

for i in range(len(Sd) - len(T) + 1)[::-1]:
    if check(Sd[i:i + len(T)], T):
        print((Sd[:i] + T + Sd[i + len(T):]).replace('?', 'a'))
        break
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
// E - NEQ
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define MOD 1000000007
vl fac{1,1}; // 階乗 n!
vl inv{0,1}; // 逆元 1/n
vl finv{1,1}; // 逆元の階乗 (n^-1)! = (1/n)!

void finv_init(int n){
	int p = MOD;
	for(int i=2; i<=n; ++i){
		fac.push_back( fac.back() * i % p );
		inv.push_back( p - inv[p%i] * (p/i) % p );
		finv.push_back( finv.back() * inv.back() % p );
	}
}

ll nCr(int n, int r){
	int m = MOD;
	if(n<r || n<0 || r<0) return 0;
	return fac[n] * (finv[n-r] * finv[r] % m) % m;
}

ll nPr(ll n, ll r){ return fac[n] * finv[n-r] % MOD; }

int main(){
	int n, m; cin>>n>>m;
	finv_init(m);
	ll ans = 0;
	for(int d=0; d<=n; ++d){
		ll a = nCr(n, d);
		a *= nPr(m-d, n-d); a %= MOD;
		if(d & 1) ans -= a;
		else ans += a;
		ans %= MOD;
	}
	ans *= nPr(m, n);
	ans %= MOD;
	cout<< (ans + MOD) % MOD <<endl;
}


Measured memory_bytes: 15092
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll>v(n * 3);
    ll pre[n + 5] = {};
    ll suf[n + 5] = {};
    for (auto &i : v) {
        cin >> i;
    }
    priority_queue<int,vector<int>,greater<int>>pq;
    ll sum = 0;
    for (int i = 0 ; i < n ; i++) {
        pq.push(v[i]);
        sum += v[i];
    }
    for (int i = 0 ; i <= n ; i++) {
        pre[i] = sum;
        if (v[i + n] > pq.top()) {
            sum -= pq.top();
            pq.pop();
            sum += v[i + n];
            pq.push(v[i + n]);
        }
    }
    priority_queue<int>pq2;
    sum = 0;
    for (int i = n * 2 ; i < n * 3 ; i++) {
        pq2.push(v[i]);
        sum += v[i];
    }
    suf[n] = sum;
    for (int i = n - 1 ; i >= 0 ; i--) {
        if (v[i + n] < pq2.top()) {
            sum -= pq2.top();
            pq2.pop();
            sum += v[i + n];
            pq2.push(v[i + n]);
        }
        suf[i] = sum;
    }
    ll mx = -1e18;
    for (int i = 0 ; i <= n ;i++) {
        mx = max(mx, pre[i] - suf[i]);
    }
    cout << mx << '\n';
}

Measured memory_bytes: 5368
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

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

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

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

	for (int i = 0; i < n; i++) {
		std::cin >> v[i];
	}

	int m;
	std::cin >> m;
	std::vector<int> p(m);
	for (int i = 0; i < m; i++) {
		std::cin >> p[i];
	}

	std::sort(v.begin(), v.end());
	std::sort(p.begin(), p.end());

	int i = 0;
	int j = 0;
	bool ok = true;
	while (ok && i < m && j < n) {
		if (p[i] > v[j]) {
			j++;
		}
		else if (p[i] == v[j]) {
			i++;
			j++;
		}
		else {
			ok = false;
		}
	}
	std::cout << (ok ? "YES" : "NO") << std::endl;


}


Measured memory_bytes: 1792
import math

# N, M
argv = [int(x) for x in input().split(" ")]

#a_1, b_1 to a_N, b_N
student_coordinates = []
for i in range(argv[0]):
    student_coordinates.append([int(x) for x in input().split(" ")])

#c_1, d_1 to c_N, d_N
check_points = []
for i in range(argv[1]):
    check_points.append([int(x) for x in input().split(" ")])

def manhattan_dist(point_1, point_2):
    return math.fabs(point_1[0] - point_2[0]) + math.fabs(point_1[1] - point_2[1])

def select_check_point(student):
    dist_list = []
    for i in range(argv[1]):
        dist_list.append(manhattan_dist(student, check_points[i]))
    return dist_list.index(min(dist_list))

for i in range(argv[0]):
    print(select_check_point(student_coordinates[i]) + 1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
#include "stdlib.h"

#define MAXN 300
#define eps 1e-8

typedef struct {
    double x;
    double y;
} vec2;

vec2 input[MAXN];
uint num_of_input;

uint init() {
    uint N;
    scanf("%u", &N);
    num_of_input = N;


    if (!N)
        return 0;

    for (uint i = 0; i < N; i++) {
        double x, y;
        scanf("%lf%lf", &x, &y);

        input[i].x = x;
        input[i].y = y;
    }


    return 1;


}

double dist(vec2 a, vec2 b) {
    return sqrt(
            (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)
    );
}

vec2 get_center(vec2 a, vec2 b){
    vec2 ret,mid={.x=(a.x+b.x)/2,.y=(a.y+b.y)/2};
    double angle=atan2(a.y-b.y,a.x-b.x);
    double distance_from_mid_to_center=sqrt(1.0-dist(a,b)*dist(a,b)/4.0);

    ret.y=mid.y-distance_from_mid_to_center*cos(angle);
    ret.x=mid.x+distance_from_mid_to_center*sin(angle);

    return ret;
}

int main() {

    while (init()) {
        uint ans = 1;

        for (uint i = 0; i < num_of_input;i++) {
            for (uint j = i + 1; j < num_of_input; j++) {
                vec2 center;
                uint cur_count = 0;
                if (dist(input[i], input[j]) > 2.0) continue;

                center = get_center(input[i], input[j]);

                for (uint k = 0; k < num_of_input; k++) {
                    if (dist(center, input[k]) < 1.0 + eps)
                        cur_count++;
                }
                ans = ans > cur_count ? ans : cur_count;
            }
        }

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

    return 0;
}


Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        if(N % 500 <= A) System.out.println("Yes");
        else System.out.println("No");
    }
}



Measured memory_bytes: 22100
#include <iostream>
#include <vector>
#define T 1001
#define M 1000000007
#define E e[x][i]
#define S e[x].size()
using namespace std;
typedef long long ll;
int N,s,t,j;
string n[T];
vector<int> e[T];

ll func(int x){
  ll r=0,i;
  if(!S){
    if(n[x]=="E") return 1;
    return 2;
  }
  if(n[x][0]=='E'){
    r++;
    for(i=0;i<S;i++) r*=func(E);
    if(n[x]=="E?") r++;
  }
  else if(n[x][0]=='A'){
    for(i=0;i<S;i++) r+=func(E);
    if(n[x]=="A?") r++;
  }else{
    r++;
    for(i=0;i<S;i++) r*=(1+func(E));
    if(n[x]=="R") r--;
  }
  return r%M;
}
 
main(){
  cin>>N;
  for(j=0;j<N;j++) cin>>n[j];
  while(--N) cin>>s>>t,e[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> e(n);
    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        e[s].push_back(t);
    }
    vector<double> dp(n);
    vector<int> best(n);
    for (int u = n - 2; u >= 0; u--) {
        best[u] = e[u][0];
        for (int v : e[u]) {
            dp[u] += dp[v] + 1;
            if (dp[v] > dp[best[u]])
                best[u] = v;
        }
        dp[u] /= e[u].size();
    }
    double ans = dp[0];
    for (int i = 0; i < n; i++) {
        if (e[i].size() <= 1) continue;
        fill(dp.begin(), dp.end(), 0);
        for (int u = n - 2; u >= 0; u--) {
            for (int v : e[u]) {
                if (u == i && v == best[u]) continue;
                dp[u] += dp[v] + 1;
            }
            dp[u] /= (u == i) ? e[u].size() - 1  : e[u].size();
        }
        ans = min(ans, dp[0]);
    }
    cout << setprecision(12) << ans << '\n';
}

Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if(N==2){
        cout << 1 << "\n";
        return 0;
    }
    int r = 0;
    for(int i=0;i<N;i++) if(g[i].size()!=1){
        r = i;
        break;
    }
    int ans = 0;
    auto dfs = [&](auto&& self,int cur,int par)->bool{
        int cnt = 0;
        int c = 0;
        if(g[cur].size()==1){
            return true;
        }
        for(auto& x:g[cur]) if(x!=par){
            c++;
            cnt += self(self,x,cur);
        }
        if(!cnt) return false;
        if(cnt==1 && c==1) return true;
        if(cur==r && c==2 && cnt==1) ans++;
        ans += cnt-1;
        return false;
    };
    dfs(dfs,r,-1);
    cout << ans << "\n";
}

Measured memory_bytes: 8960