akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int MAX_V = 50;
const int MAX_S = MAX_V * 50 + 5;//必要な銀貨の最大
const ll INF = 1e18;

struct Edge{
    int to, a, b;
    Edge(int to, int a, int b):to(to), a(a), b(b){}//コンストラクタ
};

struct Data{
    int v, s;
    ll t;
    Data(int v, int s, ll t):v(v), s(s), t(t){}
    bool operator<(const Data& a)const{
        return t > a.t; //priority queueを昇順にするため
    }
};

vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S + 5];//頂点vで所持金sを持っている時の時間の最小値

int main(){
    int n, m, s; 
    cin >> n >> m >> s;
    rep(i,m){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        //Edge e1 = {v, a, b};
        //Edge e2 = {u, a, b};
        //g[u].emplace_back(e1);
        //g[v].emplace_back(e2);
        g[u].emplace_back(v,a,b);
        g[v].emplace_back(u,a,b);
    } 
    rep(i,n)rep(j,MAX_S+5) dp[i][j] = INF;
    s = min(s, MAX_S);
    priority_queue<Data> q;
    auto push = [&](int v, int s, ll t){//&でlambda式から外側の変数を参照できる
        if(s < 0) return;
        if(dp[v][s] <= t) return;
        dp[v][s] = t;
        q.emplace(v,s,t);
    };
    vector<int> c(n), d(n);
    rep(i,n) cin >> c[i] >> d[i];
    push(0,s,0);
    while(!q.empty()){
        Data hoge = q.top(); q.pop();
        int v = hoge.v, s = hoge.s;
        ll t = hoge.t;
        if(dp[v][s] != t) continue;//出てきた物が最小のはず
        {
            //換金
            int ns = min(s+c[v], MAX_S);
            push(v, ns, t+d[v]);
        }
        for(auto e : g[v]){
            //移動
            push(e.to, s-e.a, t+e.b);
        }
    }
    for(int i = 1; i < n; i++){
        ll ans = INF;
        rep(j, MAX_S){
            ans = min(ans, dp[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include<vector>  
#include<algorithm>
using namespace std;
int main()
{
	
	int w, a, b; 
	cin >> w >> a >> b;
	if (abs(a-b)<=w)
	{
		cout << 0 << endl;
	} 
	else
	{
		cout << abs(a - b) - w << endl;
	}
	
}



Measured memory_bytes: 256
def factorization(n):
    s = set()
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            s.add(cnt)

    if temp!=1:
        s.add(1)

    if s==set():
        s.add(1)

    return s
  
n = int(input())
if n < 4:
  print(1)
else:
  for i in range(n, 0, -1):
    s = factorization(i)
    if len(s)==1 and s.pop()>=2:
        print(i)
        break

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

int n, x, y, cnt[4000];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> x >> y;
	int a = x, b = y;
	x = min(a, b), y = max(a, b);
	for(int i = 1; i <= n - 1; i++)
		for(int j = i + 1; j <= n; j++){
			int mn = min(abs(i - j), min(abs(i - x) + abs(y - j), abs(i - y) + abs(x - j)) + 1);
			cnt[mn]++;
		}
	for(int i = 1; i < n; i++) cout << cnt[i] << "\n";
	return 0;
}


Measured memory_bytes: 256
s = raw_input()

def if_even(str):
    len_ = len(str)
    if len_ % 2:
        return 0
    str1 = str[:len_/2]
    str2 = str[len_/2:]
    if str1 == str2:
        # print str
        return 1
    else:
        return 0

strlen = len(s)
for i in range(strlen):
    s = s[:-1]
    if if_even(s):
        break

print len(s)


Measured memory_bytes: 2568
#include<stdio.h>
#include<string.h>

int sum(char s[1001]){
	int a[1000], i, n = strlen(s);
	for (i = 0; i < n; i++){
		a[i] = (int)(s[i]-'0');
	}
	int answer = 0;
	for (i = 0; i < n; i++)
		answer = answer + a[i];

	return answer;
}

int main(void){
	char s[1000][1001];
	int i = 0;
	do{
		scanf("%s", s[i]);
		i++;
	} while (*(s[i - 1]) != '0');

	int n = i-1;
	for (i = 0; i < n; i++)
		printf("%d\n", sum(s[i]));


	return 0;
}


Measured memory_bytes: 2076
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
using namespace std;

const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main()
{
  int N;
  while (cin >> N) {
    if (N == 0)
      break;

    string s;
    cin >> s;

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

    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    for (int i = 0; i < N; ++i) {
      int diff = b[i] - a[i];
      s[a[i]-1] = alpha[(s[a[i]-1] - 'a' + diff) % alpha.size()];
      s[b[i]-1] = alpha[(s[b[i]-1] - 'a' + diff) % alpha.size()];
      swap(s[a[i]-1], s[b[i]-1]);
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 0
n,k = map(int,input().split())
x = list(map(int,input().split()))
positive = []
negative = []
cnt_zero = 0
for i in x:
    if i<0:
        negative.append(abs(i))
    elif i==0:
        cnt_zero +=1
    else:
        positive.append(i)
negative.sort()

m = k -cnt_zero
if m==0:
    print(0)
    exit()

ans = float('inf')

for i in range(m):
    if (0<=i<=len(negative)-1) and (0<= m - i -2 <=len(positive)-1):
        ans = min(ans,negative[i]*2+positive[m-i-2])
    if (0<=i<=len(positive)-1) and (0<= m - i -2 <=len(negative)-1):
        ans = min(ans,positive[i]*2+negative[m-i-2])
if m<=len(positive):
    ans = min(ans,positive[m-1])
if m<=len(negative):
    ans = min(ans,negative[m-1])
    
print(ans)

    
    

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int nxt[20][100010];
int inp[100010];
int main(){
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>inp[i];
    }
    int l;
    cin>>l;
    for(int j=0;j<20;j++){
        for(int i=0;i<100010;i++){
            nxt[j][i]=100005;
        }
    }
    int lst = n-1;
    for(int i=n-2;i>=0;i--){
        while(inp[lst]-inp[i]>l){
            lst--;
        }
        nxt[0][i]=lst;
    }



    for(int j=1;j<20;j++){
        for(int i=0;i<n;i++){
            nxt[j][i]=nxt[j-1][nxt[j-1][i]];
        }
    }

    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        a--;b--;
        if(a==b){
            cout<<0<<endl;
            continue;
        }
        if(a>b) swap(a,b);
        int ans = 0;
        int j;

            for(j=19;j>=0;j--){
                if(nxt[j][a]<b){
                    a=nxt[j][a];
                    ans+=(1<<j);
                }
                else if(nxt[j][a]==b){
                    ans+=(1<<j);
                    break;
                }
            }
            if(j==-1) ans++;
        cout<<ans<<endl;

    }

    return 0;

}


Measured memory_bytes: 9088
#include <stdio.h>

#define MAX 600

int function(int d)
{
	d = d * d;
	return d;
}

int main()
{
	int d,cnt;
	int sum;
	while ((scanf("%d", &d)) != EOF)
	{
		sum = 0;
		cnt = MAX / d;
		for (int i = 1; i < cnt; i++)
		{
			sum += function(d*i)*d;
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

const int MAX_N = 101;
const int MAX_V = 100010;
const long long INF = 1LL<<60;
long long  N,W;

long long  dp[MAX_N][MAX_V];

int main(){
	for(int i=0;i<MAX_V;i++){
		dp[0][i]=INF;
	}
	dp[0][0]=0;

	cin>>N>>W;
	int ans=0;
	for(int i=1;i<N+1;i++){
		long long  w,v;
		cin >> w >> v;
		for(int j=0;j<MAX_V;j++){
			if(v>j) dp[i][j]=dp[i-1][j];
			else dp[i][j] = min(dp[i-1][j],dp[i-1][j-v]+w); 
			if(dp[i][j]<=W) ans = max(ans,j);
		}
	}

	cout << ans << endl;
}

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

int main(void)
{
	double x1,y1,x2,y2;
	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	printf("%f\n",hypot(x2-x1,y2-y1));
	return 0;
}


Measured memory_bytes: 2144
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	vector<string> ret(H, string(W, '.'));
	int a = 0, b = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (ret[i][j] != '.') continue;
			if (j != W - 1) {
				ret[i][j] = '<';
				ret[i][j + 1] = '>';
				++a;
			}
			else if(i != H - 1) {
				ret[i][j] = '^';
				ret[i + 1][j] = 'v';
				++b;
			}
		}
	}
	for (int i = 0; i < H - 1; i += 2) {
		for (int j = 0; j < W - 1; j += 2) {
			if (b < B && a - 2 >= A) {
				ret[i][j] = '^';
				ret[i][j + 1] = '^';
				ret[i + 1][j] = 'v';
				ret[i + 1][j + 1] = 'v';
				b += 2;
				a -= 2;
			}
		}
	}
	if (H >= 3 && W >= 3 && H % 2 == 1 && W % 2 == 1 && b < B && ret[H - 3][W - 3] == '<') {
		ret[H - 3][W - 3] = '<'; ret[H - 3][W - 2] = '>'; ret[H - 3][W - 1] = '^';
		ret[H - 2][W - 3] = '^'; ret[H - 2][W - 2] = '.'; ret[H - 2][W - 1] = 'v';
		ret[H - 1][W - 3] = 'v'; ret[H - 1][W - 2] = '<'; ret[H - 1][W - 1] = '>';
		--a;
		++b;
	}
	if (a < A || b < B) {
		cout << "NO\n";
	}
	else {
		vector<string> ans(H, string(W, '.'));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				if (A > 0 && ret[i][j] == '<') {
					ans[i][j] = '<';
					ans[i][j + 1] = '>';
					--A;
				}
				if (B > 0 && ret[i][j] == '^') {
					ans[i][j] = '^';
					ans[i + 1][j] = 'v';
					--B;
				}
			}
		}
		cout << "YES\n";
		for (int i = 0; i < H; ++i) {
			cout << ans[i] << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char c;
    cin >> c;
    c++;

    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
ll N;
vvll g;

ll dfs(ll u, ll v) {
	vll lis;
	for (ll w : g[v]) {
		if (u == w) { continue; }
		lis.push_back(dfs(v, w));
	}

	ll k = 30;
	for (ll i = 30; i >= 0; i--) {
		ll count = 0;
		for (ll x : lis) { if ((x >> i) & 1) { count++; } }
		if (count >= 2) { break; }
		if (count == 0) { k = i; }
	}

	ll ret = 1<<k;
	for (ll x : lis) { ret |= x; }
	ret &= ~((1 << k) - 1);

	//cout << v << " " << ret << endl;
	return ret;
}

int main() {
	cin >> N;
	g.resize(N + 1);
	repn(i, N-1) {
		ll x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	ll t = dfs(0, 1);
	//cout << t << endl;

	ll ans = 0;
	rep(i, 30) {
		if ((t >> i) == 0) { ans = i - 1; break; }
	}
	cout << ans << endl;
}


Measured memory_bytes: 15580
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll h, n;
    cin >> h >> n;
    vector<ll> a(n), b(n);
    rep(i, n)cin >> a.at(i) >> b.at(i);
    vector<ll> dp(h+1);
    dp[0] = 0;
    REP(i, h){
        ll now = inf;
        rep(j, n){
            now = min(dp[max(0LL, i-a[j])]+b[j], now);
        }
        dp[i] = now;
    }
    cout << dp[h] << endl;
}
    

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

using namespace std;

typedef long long ll;

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

	string s[3];
	rep(i, 3) cin >> s[i];

	string ans;
	rep(i, 3) ans.push_back(s[i][i]);
	
	cout << ans << endl;

}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(n);
  SCIN(s);
  int x = 0;
  int ans = 0;
  REP(i, s.size()) {
    if (s[i] == 'I') x++;
    else if (s[i] == 'D') x--;

    ans = max(ans, x);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
def main():
    n = int(input())
    s = [0]*n
    for i in range(n):
        s[i] = int(input())

    ans = sum(s)
    if ans % 10 != 0:
        print(ans)
        exit()

    s = sorted(s)

    for i in s:
        if i % 10 == 0:
            continue
        else:
            print(ans -i)
            exit()

    print(0)



if __name__ == "__main__":
        main()


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#define MAX 1000000
using namespace std;
int main(){
	bool num[MAX] = {false,false};
	for(int i=2;i<MAX;i++){
		num[i] = true;
	}
	for(int i=2; i<sqrt(MAX); i++){
		if(num[i]){
			for(int l=i*2;l<MAX;l+=i){
				num[l] = false;
			}
		}
	}
	int n;
	while(cin >>n){
		int ans = 0;
		for(int i=0;i<=n;i++){
			if(num[i]){ans++;}
		}
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define int long long
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'

const int N = 55;
const int dx[4] = {1,-1,0,0};
const int dy[4] = {0,0,1,-1};
int H,W;
char board[N][N];
int dist[N][N];

int bfs(){
    queue<P> que;
    que.push(make_pair(0,0));
    dist[0][0] = 1;
    while(!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        if(x == H - 1 && y == W - 1) break;
        for(int i = 0; i < 4; i++){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx >= 0 && nx < H && ny >= 0 && ny < W && board[nx][ny] != '#' && dist[nx][ny] == -1){
                que.push(make_pair(nx,ny));
                dist[nx][ny] = dist[x][y] + 1;
            }
        }
    }
    return dist[H-1][W-1];
}

signed main() {
    cin >> H >> W;
    int black = 0;
    memset(dist,-1,sizeof(dist));
    rep(i,H) rep(j,W) {
        cin >> board[i][j];
        if(board[i][j] == '#') black++;
    }

    int cnt = bfs();
    if(cnt == -1) {
        cout << -1 << endl;
        return 0;
    }

    cout << H * W - black - cnt << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>

int main(){
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int N,Y;
  std::cin >> N >> Y;
  Y=Y/1000;
  int x,y,z=0;
  for(int x=0;x<=N;x++){
    for(int y=0;y<=N;y++){
      if(9*x+4*y==Y-N&&N-x-y>=0){
        std::cout << x << ' ' << y << ' ' << N-x-y << std::endl;
        return 0;
      }
    }
  }
  std::cout << -1 << ' ' << -1 << ' ' << -1 << std::endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define ll long long
#define mst(a) memset(a, 0, sizeof a)

const int mod = 1e9+7;
const int maxn = 2e5+50;
const int inf = 1e9;

vector<int> g[maxn];
int a[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; ++i)
    {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int tmp = 0;
    long long sum = 0;
    for (int i = 1; i <= n; ++i)
    {
        int cnt = 0;
        for (int j = 0; j < g[i].size(); ++j)
        {
            int to = g[i][j];
            if (to < i) cnt ++;
        }
        tmp -= cnt - 1;
        a[i] = tmp;
        sum += tmp;
    }
    long long ans = sum;
    //printf("%lld\n", sum);
    for (int i = 1; i <= n; ++i)
    {
        vector<int> nei;
        nei.push_back(i);
        nei.push_back(n+1);
        for (int j = 0; j < g[i].size(); ++j)
        {
            int v = g[i][j];
            if (v > i) nei.push_back(v);
        }
        sort(nei.begin(), nei.end());
        for (int j = 1; j < nei.size(); ++j)
        {
            sum += (j - 2) * (nei[j] - nei[j-1]);
        }
        ans += sum;
        //printf("%lld\n", sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17088
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,q,ans=0;
	vector<int> S,T;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		S.push_back(x);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int x;
		cin>>x;
		T.push_back(x);
	}
	for(int i=0;i<q;i++){
		for(int j=0;j<n;j++){
			if(T[i]==S[j]){
				ans++;
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3240
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < n ; i++ ) {
			
			int a = scanner.nextInt();
			
			list.add(a);
			
			
		
		}
	Collections.reverse(list);
	
	System.out.print(list.get(0));
	
		for (int i = 1; i < list.size(); i++ ) {
			
			System.out.print(" " + list.get(i));
		}
	System.out.println();
	}
	
	
}



Measured memory_bytes: 26340
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000
int n,x,num=0;
int main()
{
	scanf("%d%d",&n,&x);
	if(x==1||x==2*n-1){printf("No\n");return 0;}
	printf("Yes\n");
	for(int i=1;i<=2*n-1;i++)
	{
		if(i>=n-1&&i<=n+1)printf("%d\n",n-i+x);
		else 
		{
			num++;if(num==x-1)num=x+2;
			printf("%d\n",num);
		}
	}
}

Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
    char a[9];
    char b[9];
    int i,j,k,l,s,d,f;
    scanf("%d%d",&k,&l);
    for(i=0;i<l;i++){
      a[i]=k;
    }
     printf("\n");
    for(i=0;i<k;i++){
      b[i]=l;
    }
    s=strlen(a);
     d=strlen(b);
     if(s>d){
            for(i=0;i<l;i++){
                printf("%d",a[i]);
            }
     }
     else{
        for(i=0;i<k;i++){
            printf("%d",b[i]);
        }
     }
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
    int n,k;
    char a[100005];
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(i==k)
        {
            char s=a[i]+32;
            cout<<s;
        }
        else 
        {
            cout<<a[i];
        }
    }
    return 0;
}

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

using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    string A[50], B[50];
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    rep(i, N - M + 1) rep(j, N - M + 1) {
        bool f = true;
        rep(k, M) rep(l, M) {
            if (A[i + k][j + l] != B[k][l]) f = false;
        }
        if (f) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto s = readln.chomp;
  int cnt;
  foreach (i; 0..n) {
    if (i+3 > s.length) break;
    if (s[i..i+3] == "ABC") {
      cnt++;
    }
  }
  cnt.writeln;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int n,k,i,a;
	int ans = 0;
	int buf = 0;
	scanf("%d %d", &n, &k);
	
	for(i = 0; i < n; i++){
		scanf("%d", &a);
	}
	ans = (n - 1) / (k - 1);
	if((n - 1) % (k - 1) != 0){
		ans++;
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
import java.util.PriorityQueue
import kotlin.comparisons.compareByDescending
fun main(arg: Array<String>) {
    val (N, M) = listOfInt()
    val jobs = Array<MutableList<Int>>(M) { mutableListOf() }
    repeat(N) {
        val (A, B) = listOfInt()
        if (A <= M) jobs[M - A].add(B)
    }
    val q = PriorityQueue<Int>(1, compareByDescending { it })
    var ans = 0L
    for (n in (0 until M).reversed()) {
        jobs[n].forEach { q.add(it) }
        if (q.size > 0) {
            ans += q.poll()!!
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


Measured memory_bytes: 68624
A, B, C, D = map(int, input().split())

start = 100
stop = 0

for i in range(101):
    if A <= i <= B and C <= i <= D:
        start = min(start, i)
        stop = max(stop, i)

if start == 100 and stop == 0:
    ans = 0
else:
    ans = stop - start

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define mod 838627288460106
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    fast_io
    ll n,y,i,j,c10k=0,c5k=0,c1k=0;
    cin>>n>>y;
    bool ok=1;
    for(i=0; i<=n; i++)
    {
        for(j=0; j<=n; j++)
        {
            if(n-i-j>=0)
            {
                if(i*1000+j*5000+(n-i-j)*10000==y)
                {
                    cout<<n-i-j<<" "<<j<<" "<<i<<endl;
                    ok=0;
                    break;
                }
            }
        }
        if(!ok)
            break;
    }
    if(ok)
    {
        cout<<"-1 -1 -1"<<endl;
    }
    return 0;
}





Measured memory_bytes: 3572
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = (int.Parse(str[0]) + 11) % 13;
        int b = (int.Parse(str[1]) + 11) % 13;
        Console.WriteLine(a > b ? "Alice" : b > a ? "Bob" : "Draw");
    }
}

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

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

  vector<int> d(n);
  rep(i, n) cin >> d[i];

  int sum = 0;
  rep(i, n) rep(j, n){
    if(i == j) continue;
    sum += d[i] * d[j];
  }

  cout << sum / 2 << endl;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define print(x) cout << #x << " = " << x << endl;

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;


int main() {
	int X, Y;
	scanf("%d %d", &X, &Y);

	if (X % Y == 0) {
		printf("-1\n");
	}
	else {
		for (int i = X * 2; i < 1e18; i += X) {
			if (i % Y != 0) {
				printf("%d\n", i);
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int h, w;
    cin >> h >> w;

    int diff[h][w];
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> diff[i][j];
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        int b;
        cin >> b;
        diff[i][j] = abs(diff[i][j] - b);
    }

    int center = (h + w - 2) * 80;
    bool dp[h][w][center * 2 + 1];
    fill(dp[0][0], dp[h - 1][w - 1] + center * 2 + 1, 0);
    dp[0][0][center + diff[0][0]] = dp[0][0][center - diff[0][0]] = 1;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k <= center * 2; k++) {
                if (i && dp[i - 1][j][k]) {
                    dp[i][j][k + diff[i][j]] = 1;
                    dp[i][j][k - diff[i][j]] = 1;
                }
                if (j && dp[i][j - 1][k]) {
                    dp[i][j][k + diff[i][j]] = 1;
                    dp[i][j][k - diff[i][j]] = 1;
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= center; i++) {
        if (dp[h - 1][w - 1][center + i]) {
            ans = i;
            break;
        }
        if (dp[h - 1][w - 1][center - i]) {
            ans = i;
            break;
        }
    }

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

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()


int main() {
	int n,l;
	cin >> n >> l;
	vector<pair<int, int>> aji(n+1);
	FOR(i, 1, n) {
		aji[i].second = l + i - 1;
		aji[i].first = abs(aji[i].second);
	}
	sort(aji.begin()+1,aji.end());
	int sum = 0;
	FOR(i, 2, n) {
		sum += aji[i].second;
	}
	pv(sum)
	return(0);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>

int n, m, q;
using namespace std;
vector<int>a,b,c,d;
int ans;
void w(vector<int>p,int N,int x) {
    if (p.size() == N+1 ) {
        int T = 0;
        for (int i = 0; i < p.size(); i++) {
        //    cout << p[i] << " ";
        }
        
        for (int i = 0; i < q; i++) {
            if (p[b[i]] - p[a[i]] == c[i])T += d[i];
        }
        ans = max(ans, T);
      //  cout << ans << endl;;
        return;
    }
    p.push_back(p.back());
    while (p.back() <= m) {
        w(p, N, x);
        p.back()++;
    }
}


int main()
{
    

    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];

    }
    vector<int>r;
    r.push_back(1);

    ans = 0;
    w(r,n, ans);
    cout << ans << endl;
   

    return 0;

}

Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;
const lint INF = 1LL << 60;

const double PI = acos(-1);
const double Rad2Deg = 180.0 / PI;
const double Deg2Rad = PI / 180.0;

int main() {
    int N;
    cin >> N;
    int a[200050];
    for (int i = 0; i < N; i++) cin >> a[i];

    int ans = -1;
    int toF = 1;
    int c = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] == toF) {
            toF++;
        }
        else {
            c++;
        }
    }

    if (c != N) {
        ans = c;
    }

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


Measured memory_bytes: 1024
# coding: utf-8
N = int(input())
l = []
def dfs(v, N):
    if int(v)<= N:
        flag = True
        if v.count("3") <= 0:
            flag = False
        if v.count("5") <= 0:
            flag = False
        if v.count("7") <= 0:
            flag = False
        if flag:
            l.append(1)
    else:
        return
    dfs(v + "7", N)
    dfs(v + "5", N)
    dfs(v + "3", N)
dfs("0", N)
print(sum(l))

Measured memory_bytes: 3188
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def main():
    #A, B, T = map(int, input().split())
    N = int(input())
    A_list = [int(a) for a in input().split()]

    min_val = 10 ** 10
    neg_num = 0
    total = 0
    for a in A_list:
        abs_a = a if a > 0 else -a
        if abs_a < min_val:
            min_val = abs_a
        if a < 0:
            neg_num += 1
        total += abs_a

    if neg_num % 2 != 0:
        total -= 2 * min_val
    print(total)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14936
# %% constants or libraries
# -------------------------

# adapted:
# - from https://github.com/JuliaLang/julia/blob/805b6597e05256059a5d412d615a6486406f74c0/base/sort.jl
# - by @aviatesk, 2020/03/26
#
# NOTE:
# This file extends `searchsorted`, `searchsortedfirst` and `searchsortedlast` so that
# they can accept a "converter" function as their first argument

import Base.Sort: searchsorted, searchsortedfirst, searchsortedlast

using Base.Order
@static if VERSION < v"1.4"
    # This implementation of `midpoint` is performance-optimized but safe
    # only if `lo <= hi`.
    midpoint(lo::T, hi::T) where T<:Integer = lo + ((hi - lo) >>> 0x01)
    midpoint(lo::Integer, hi::Integer) = midpoint(promote(lo, hi)...)
else
    import Base.Sort: midpoint
end

for s in [:searchsortedfirst, :searchsortedlast, :searchsorted]
    @eval begin
        $s(f, v::AbstractVector, x, o::Ordering) = (inds = axes(v, 1); $s(f, v,x,first(inds),last(inds),o))
        $s(f, v::AbstractVector, x;
           lt=isless, by=identity, rev::Union{Bool,Nothing}=nothing, order::Ordering=Forward) =
            $s(f,v,x,ord(lt,by,rev,order))
    end
end

function searchsortedfirst(f, v::AbstractVector, x, lo::T, hi::T, o::Ordering) where T<:Integer
    u = T(1)
    lo = lo - u
    hi = hi + u
    @inbounds while lo < hi - u
        m = midpoint(lo, hi)
        if lt(o, f(v[m]), x)
            lo = m
        else
            hi = m
        end
    end
    return hi
end

function searchsortedlast(f, v::AbstractVector, x, lo::T, hi::T, o::Ordering) where T<:Integer
    u = T(1)
    lo = lo - u
    hi = hi + u
    @inbounds while lo < hi - u
        m = midpoint(lo, hi)
        if lt(o, x, f(v[m]))
            hi = m
        else
            lo = m
        end
    end
    return lo
end

function searchsorted(f, v::AbstractVector, x, ilo::T, ihi::T, o::Ordering) where T<:Integer
    u = T(1)
    lo = ilo - u
    hi = ihi + u
    @inbounds while lo < hi - u
        m = midpoint(lo, hi)
        y = f(v[m])
        if lt(o, y, x)
            lo = m
        elseif lt(o, x, y)
            hi = m
        else
            a = searchsortedfirst(f, v, x, max(lo,ilo), m, o)
            b = searchsortedlast(f, v, x, m, min(hi,ihi), o)
            return a : b
        end
    end
    return (lo + 1) : (hi - 1)
end


# %% body
# -------

function main(io = stdin)
    readto(target = '\n') = readuntil(io, target)
    readnum(T::Type{<:Number} = Int; dlm = isspace, kwargs...) =
        parse.(T, split(readto(), dlm; kwargs...))

    # handle IO and and stuff
    N, K = readnum()
    A = readnum()
    println(solve(N, K, A))
end

function solve(N, K, A)
    return searchsortedfirst(1:maximum(A), K; rev = true) do target
        return sum(ceil.(Int, A ./ (target)) .- 1)
    end
end

@static if @isdefined(Juno) || @isdefined(VSCodeServer)
    main(open(replace(@__FILE__, r"(.+)\.jl" => s"\1.in")))
else
    main()
end


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}


const int MOD = 1E9 + 7, N = 2001;
ll fact[N];
ll exp(int a, int n) {
        if (n == 0) return 1;
        ll b = exp(a, n / 2);
        (b *= b) %= MOD;
        if (n & 1) (b *= a) %= MOD;
        return b;
}

ll C(int n, int k) {
        if (k > n) return 0;
        return fact[n] * exp(fact[k], MOD - 2) % MOD * exp(fact[n - k], MOD - 2) % MOD;
}


void _main() {
        fact[0] = 1;
        int blue, n; cin >> n >> blue;
        int red = n - blue;
        for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
        for (int i = 1; i <= blue; i++) {
                cout << C(red + 1, i) *  C(blue - 1, i - 1) % MOD << '\n';
        }

}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3624
object Main extends App {
  import scala.io.StdIn._
  val n = readLine.trim.toInt
  val num = readLine.trim.split(' ').map(_.toInt)
  val oddCount = Array.tabulate(100001){_ ⇒ 0}
  val evenCount = Array.tabulate(100001){_ ⇒ 0}
  for (i ← num.indices){
    if (i % 2 == 0){
      evenCount(num(i)) += 1
    }else {
      oddCount(num(i)) += 1
    }
  }
  val oddSorted = oddCount.zipWithIndex.sortBy{case (v, _) ⇒ v}.reverse
  val evenSorted = evenCount.zipWithIndex.sortBy{case (v, _) ⇒ v}.reverse
  println(
    if (oddSorted.head._2 == evenSorted.head._2) {
      if (oddSorted(0)._1 + evenSorted(1)._1 > oddSorted(1)._1 + evenSorted(0)._1) n - (oddSorted(0)._1 + evenSorted(1)._1) else n - (oddSorted(1)._1 + evenSorted(0)._1)
    }else n - (oddSorted.head._1 + evenSorted.head._1)
  )
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int32_t main()
{   fastio;

    int n;
    cin>>n;

    string s;
    cin>>s;

    int p = count(s.begin() , s.end() , 'R');
    int cnt=0;
    for(int i=p; s[i]; i++) {
        if(s[i] == 'R') cnt++;
    }

    cout<<cnt<<"\n";

}

Measured memory_bytes: 3740
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    ll gotiusa; cin>>gotiusa;
    ll ujimatsu_tiya=gotiusa/11;
    if(gotiusa%11<=6&&gotiusa%11)cout<<2*ujimatsu_tiya+1<<endl;
    else if(gotiusa%11>6)cout<<2*ujimatsu_tiya+2<<endl;
    else cout<<2*ujimatsu_tiya<<endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll a, b, c, a_buf, b_buf;

int main(){
	cin >> a >> b >> c;
	ll cnt = 0;
	while(!(a == b && b == c) && a%2 == 0 && b%2 == 0 && c%2 == 0){
		a_buf = b/2+c/2;
		b_buf = a/2+c/2;
		c = a/2+b/2;
		a = a_buf;
		b = b_buf;
		cnt++;
	}
	if(a%2 == 0 && a == b && b == c){cnt = -1;}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    int k[n], a[n][30];
    for(int i = 0; i < n; i++){
        scanf("%d", &k[i]);
        for(int j = 0; j < k[i]; j++){
            scanf("%d", &a[i][j]);
        }
    }

    int f[m];
    for(int i = 0; i < m; i++){
        f[i] = 0;
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < k[i]; j++){
            f[a[i][j] - 1]++;
        }
    }

    int count = 0;
    for(int i = 0; i < m; i++){
        if(f[i] == n){
            count++;
        }
    }

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

    return 0;
}

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

using namespace std;

#define MOD 1000000007

int n, c[200200], lst[200200], nxt[200200], dp[200200];

int solve(int ind) {
	if (dp[ind] != -1) return dp[ind];
	if (ind == n) return 1;
	
	int ret = 0;
	if (nxt[ind] != -1) ret += solve(nxt[ind]);
	if (ind+1 == n || (ind+1 < n && c[ind+1] != c[ind])) ret += solve(ind+1);
	
	return dp[ind] = ret % MOD;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)	
		scanf("%d", &c[i]);
		
	memset(lst, -1, sizeof lst);
	for (int i = n-1; i >= 0; i--) {
		nxt[i] = lst[c[i]];
		lst[c[i]] = i;
	}
	
	memset(dp, -1, sizeof dp);
	printf("%d\n", solve(0));
	return 0;
}



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

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

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

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

const char newl = '\n';

const ll mod = 1000000007;
//const ll mod = 998244353;

const int MAX_N = 200010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    int n,m = 0;
    cin >> n;
    init(n);
    map<P,int> mp;
    set<P> st;
    for (int i = 0;i < n;++i) {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        if (a == 0 && b == 0) {
            m++;
            continue;
        }
        ll g = gcd(a,b);
        a /= g;
        b /= g;
        if (a < 0 || (a == 0 && b < 0)) {
            a *= -1;
            b *= -1;
        }
        mp[make_pair(a,b)]++;
    }
    ll ans = 1;
    for (auto p : mp) {
        P q = make_pair(p.first.second,-p.first.first);
        if (q.first < 0 || (q.first == 0 && q.second < 0)) {
            q.first *= -1;
            q.second *= -1;
        }
        if (st.find(p.first) != st.end()) continue;
        (ans *= pow_mod(2,p.second)+pow_mod(2,mp[q])-1) %= mod;
        st.insert(p.first);
        st.insert(q);
    }
    cout << (ans+m+mod-1)%mod << endl;
}

Measured memory_bytes: 58268
import Control.Applicative

main :: IO ()
main = solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve [a, b, x] = min (q * a) (2 * q * b) + min a (i * b)
  where
    (q, r) = divMod x 1000
    i = (r + 499) `div` 500



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

using namespace std;

const int MAXN = 100000 + 10;
const int INF = (int)(1e9);
const int MOD = (int)(1e9) + 7;

int n;
long long a, b;
long long s[MAXN];
int la[MAXN], lb[MAXN], pa[MAXN], pb[MAXN];
long long fa[MAXN], fb[MAXN], sfa[MAXN], sfb[MAXN];

void run() {
    cin >> n >> a >> b;
    for(int i = 1; i <= n; ++i) cin >> s[i];

    la[1] = lb[1] = 1;
    int ia = 0, ib = 0;
    for(int i = 2; i <= n; ++i) {
        if (s[i] - s[i - 1] >= a) la[i] = la[i - 1]; else la[i] = i;
        if (s[i] - s[i - 1] >= b) lb[i] = lb[i - 1]; else lb[i] = i;
        while ((ia + 1 < i) && (s[i] - s[ia + 1] >= a)) ++ia;
        while ((ib + 1 < i) && (s[i] - s[ib + 1] >= b)) ++ib;
        pa[i] = ia; pb[i] = ib;
    }

    fa[1] = fb[1] = 1;
    sfa[1] = sfb[1] = 1;
    for(int i = 2; i <= n; ++i) {
        fa[i] = 0;
        if (lb[i - 1] <= min(i - 1, pa[i] + 1))
            fa[i] = (sfb[min(i - 1, pa[i] + 1)] - sfb[lb[i - 1] - 1] + MOD) % MOD;
        sfa[i] = (sfa[i - 1] + fa[i]) % MOD;

        fb[i] = 0;
        if (la[i - 1] <= min(i - 1, pb[i] + 1))
            fb[i] = (sfa[min(i - 1, pb[i] + 1)] - sfa[la[i - 1] - 1] + MOD) % MOD;
        sfb[i] = (sfb[i - 1] + fb[i]) % MOD;

        //cout << i << " " << s[i] << " " << fa[i] << " " << fb[i] << endl;
    }

    long long res = 0;
    for(int i = 1; i <= n; ++i) {
        if (la[n] <= i) res = (res + fa[i]) % MOD;
        if (lb[n] <= i) res = (res + fb[i]) % MOD;
    }

    cout << res << endl;
}

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

    int ntests = 1;
    //cin >> ntests;
    for(int tc = 1; tc <= ntests; ++tc) {
        run();
    }
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
#define pa pair<int,int>
using namespace std;
int n,a[55],tot;
pa ans[105];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int z=1,f=1;
	for (int i=2;i<=n;i++){
		if (a[i]>a[z]) z=i;
		if (a[i]<a[f]) f=i;
	}
	if (a[z]==a[f])
		return puts("0"),0;
	if (a[z]+a[f]>=0){
		ans[++tot]=pa(z,n);
		ans[++tot]=pa(z,n);
		for (int i=1;i<n;i++)
			ans[++tot]=pa(n,i);
		for (int i=2;i<=n;i++)
			ans[++tot]=pa(i-1,i);
	}
	else{
		ans[++tot]=pa(f,1);
		ans[++tot]=pa(f,1);
		for (int i=2;i<=n;i++)
			ans[++tot]=pa(1,i);
		for (int i=n-1;i;i--)
			ans[++tot]=pa(i+1,i);
	}
	printf("%d\n",tot);
	for (int i=1;i<=tot;i++)
		printf("%d %d\n",ans[i].first,ans[i].second);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  cin >> x;

  int a, b;
  a = x / 500;
  b = (x - 500 * a) / 5;

  cout << 1000 * a + 5 * b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007
 
int main(){
  int n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  ll ans1=0,ans2=0;
  ll s=0;
  for(int i=0;i<n;i++){
    s+=a[i];
    if(i%2==0){
      if(s<=0){
        ans1+=abs(1-s);
        s=1;
      }
    }else{
      if(s>=0){
        ans1+=abs(-1-s);
        s=-1;
      }
    }
  }
  s=0;
  for(int i=0;i<n;i++){
    s+=a[i];
    if(i%2==1){
      if(s<=0){
        ans2+=abs(1-s);
        s=1;
      }
    }else{
      if(s>=0){
        ans2+=abs(-1-s);
        s=-1;
      }
    }
  }
  cout<<min(ans1,ans2)<<endl;
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
data = list(map(lambda x: int(x),input().split(" ")))
same_value = 0

for i in range(1, n+1):
  if i == data[i-1]:
    same_value += 1
  else:
    pass

if same_value >= n - 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
using System;

class Plogram
{
    static void Main()
    {
        int S = int.Parse(Console.ReadLine());

        int pre = S / 100;
        int last = S % 100;

        int p = 0;
        int l = 0;

        if(1<=pre && pre<=12)
        {
            p = 1;
        }
        if(1 <= last && last <= 12)
        {
            l = 1;
        }

        if (p == 1 && l == 1)
        {
            Console.WriteLine("AMBIGUOUS");
        }
        else if(p==0 && l ==1)
        {
            Console.WriteLine("YYMM");
        }
        else if(p==1 && l==0)
        {
            Console.WriteLine("MMYY");
        }
        else
        {
            Console.WriteLine("NA");
        }   
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
int Max(int &a,int b){return a=max(a,b);}
int Min(int &a,int b){return a=min(a,b);}
int n,A,B,stone[N];
 
signed main(){
  cin>>n>>A>>B;
  for(int i=0;i<n;i++) cin>>stone[i];
  sort(stone,stone+n);
 
  int ans = 0;
  if( A == B || stone[n-1]<=min(A,B)) for(int i=0;i<n;i++) ans ^= stone[i]%(A+1);
  else if( A > B ) ans = 1;
  else if(stone[n-1]-A > A || stone[n-2] > A || n == 1) ans = 0;
  else {
    int sum = 0;
    for(int i=0;i<n-1;i++) sum ^= stone[i];
    if(sum == 0) sum = A;
    int x = stone[n-1] - sum;
    ans = sum >= stone[n-1]-A && stone[n-1]-x <= A;

  }
  
  cout<<(ans? "Hanako":"Jiro")<<endl;
  return 0;
}

Measured memory_bytes: 3928
# coding: utf-8
# Your code here!
N=int(input())
A = list(map(int,input().split()))

flag = 1

ans =1
for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        if flag == 1:
            flag = 0
        ans = 1
        

if ans == 0:
    print(0)
elif flag == 0:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 21600