akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  vector<string> c(2);
  rep(i,6){cin >> c[i];}
  
  reverse(c[1].begin(), c[1].end());
  
  if(c.at(0) == c.at(1)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

int H[100010];
priority_queue<int> G[100010];

int main()
{
    int N, M; cin>>N>>M;
    for(int i=0; i<N; ++i) cin>>H[i];
    for(int i=0; i<M; ++i) {
        int a, b; cin>>a>>b;
        --a, --b;
        G[a].push(H[b]);
        G[b].push(H[a]);
    }
    int res=0;
    for(int i=0; i<N; ++i) {
        if (G[i].empty() or H[i]>G[i].top()) {
            ++res;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 9860
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	rep(snip_i, n) cin >> x.at(snip_i);
	sort(x.begin(), x.end());
	int ans = 1001001001;
	rep(i, n-k+1){
		int l = x.at(i);
		int r = x.at(i+k-1);
		int add;
		if(r < 0){
			add = fabs(l);
		}else if(l < 0){
			if(fabs(l) < fabs(r)){
				add = 2*fabs(l) + fabs(r);
			}else{
				add = 2*fabs(r) + fabs(l);
			}
		}else{
			add = fabs(r);
		}
		// cerr << "t" << add << endl;
		ans = min(ans, add);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
import sys
s=sys.stdin.readline().strip()

q=int(input())

p=1
front=''
back=''

for i in range(q):
    slst=input().split()

    if len(slst)==1:
        p*=-1
    else:
        t,f,c=slst

        f=int(f)

        if (f*2-3)*p==1:
            back=back+c
        else:
            front=c+front

s=front+s+back

if p==-1:
    s=s[::-1]

print(s)

Measured memory_bytes: 4452
//#pragma GCC optimize(2)
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int a[MAXN+5];
int main(){
	int n=read();
	for(int i=1;i<=n;i++)
		a[read()]=i;
	for(int i=1;i<n;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n]);
	return 0;
}

Measured memory_bytes: 1152
<?php
list($a,$b,$h,$m)=explode(" ",trim(fgets(STDIN)));
$hr=$h*30+$m*0.5;
$mr=$m*6;
$r=abs($hr-$mr);
$r=min(360-$r,$r);
$ans=$a*$a+$b*$b-2*$a*$b*cos(deg2rad($r));
echo sprintf("%.12f",sqrt($ans));

Measured memory_bytes: 16564
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
using namespace std;

int main() {
  int n;
  cin>>n;
  fr(i,0,101) {
    fr(j,0,101) {
      if(4*i+7*j==n) {
        cout<<"Yes";
        return 0;
      }
    }
  }
  cout<<"No";
}

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

#define ri register int
#define sid 105
#define mod 1000000007

int n;
char S[3][sid];

int main() {
    cin >> n >> S[1] + 1 >> S[2] + 1;
    ri i = 1, ans;
    if(S[1][i] == S[2][i]) i = 1, ans = 3;
    else i = 2, ans = 6;
    for(i = i + 1; i <= n; i ++) {
        int p1 = S[1][i] == S[2][i];
        int p2 = S[1][i - 1] == S[2][i - 1];
        if(!p1) i ++;
        if(p1 && p2) ans = (1ll * ans * 2) % mod;
        if(!p1 && !p2) ans = (1ll * ans * 3) % mod;
        if(!p1 && p2) ans = (1ll * ans * 2) % mod;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr ll MOD = 67280421310721;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
long long com[51][51];
ll calcComb(ll a, ll b) { return com[a][b]; }

//大きい順にA個えらんだとき，それらの値がすべて同じの時V個数からA~Bえらぶ
//そうでないとき最小の値をvとしてvの値を持つ数値がV個,
// A個の中からvの値をもつものがa個あったとするとV個からa個選ぶ
int main() {
    int A, B, N;
    cin >> N >> A >> B;
    // A個以上B個以下
    com[0][0] = 1;
    for(int i = 1; i < 51; ++i) {
        for(int j = 0; j <= i; ++j) {
            //新しく追加されたのを選ばない
            com[i][j] += com[i - 1][j];
            if(j > 0) {
                //新しく追加されたのを選ぶ
                com[i][j] += com[i - 1][j - 1];
            }
        }
    }
    vector<ll> v(N);
    map<ll, int> all_cnt;
    REP(i, N) {
        cin >> v[i];
        all_cnt[v[i]]++;
    }
    sort(v.begin(), v.end());
    double s = 0;
    map<ll, int> cnt;
    REP(i, A) {
        s += (double)v[N - i - 1];
        cnt[v[N - i - 1]]++;
    }

    cout << fixed << setprecision(10) << s / (double)A << endl;
    int c = cnt[v[N - A]];
    if(c == A) {
        ll ans = 0;
        for(int i = A; i <= B; i++) {
            ll diff = calcComb(all_cnt[v[N - A]], i);
            ans += diff;
            // cout << diff << "comb" << all_cnt[v[N - A]] << ";" << i << endl;
        }
        // cout << "hoge" << endl;
        cout << ans << endl;
        return 0;
    }
    if(c == 1) {
        cout << all_cnt[v[N - A]] << endl;
    } else {
        cout << calcComb(all_cnt[v[N - A]], c) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
	static int N,K,L;
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		N=sc.nextInt();
		K=sc.nextInt();
		L=sc.nextInt();
		UnionFind.init(N);
		int[] den=new int[N];
		for(int i=0;i<K; i++) {
			int f=sc.nextInt()-1;
			int t=sc.nextInt()-1;
			UnionFind.unite(f,t);
		}
		for(int i=0; i<N; i++) {
			den[i]=UnionFind.find(i);
		}
		UnionFind.init(N);
		int[] dou=new int[N];
		for(int i=0;i<L; i++) {
			int f=sc.nextInt()-1;
			int t=sc.nextInt()-1;
			UnionFind.unite(f,t);
		}
		for(int i=0; i<N; i++) {
			dou[i]=UnionFind.find(i);
		}
		HashMap<Long,Integer> num = new HashMap<Long,Integer>();
		long[] id=new long[N];
		for(int i=0; i<N; i++) {
			id[i]=((long)(den[i])*((long) N)+((long)(dou[i])));
			if(num.containsKey(id[i])) {
				num.put(id[i], num.get(id[i])+1);
			}
			else {
				num.put(id[i], 1);
			}
		}
		for(int i=0; i<N; i++) {
			if(i<N-1) {
				p(num.get(id[i])+" ");
			}
			else {
				p(num.get(id[i]));
			}
		}
		pl();
	}
	static class UnionFind {
		static int N;			//頂点数
		static int par[];		//親ノード
		static int rank[];		//ランク　UnionFind木の高さがrankみたい
		public static void init(int n) {		//初期化
			N = n;
			par = new int[N];
			rank = new int[N];
			for(int i = 0; i < N; i++) {		//0処理
				par[i] = i;
				rank[i] = 0;
			}
		}
		public static int find(int x) {		//木の根を求める
			if(par[x] == x) {
				return x;
			} else {
				return par[x] = find(par[x]);
			}
		}
		public static void unite(int x, int y) {		//xとyの属する集合を併合	xにyをという意味合いが強そう		集合に含めるときに unite(114,514);のようにするみたい
			x = find(x);
			y = find(y);
			if(x == y) return;
			if(rank[x] < rank[y]) {
				par[x] = y;
			} else {
				par[y] = x;
				if(rank[x] == rank[y]) rank[x]++;
			}
		}
		public static boolean same(int x, int y) {		//x,yが同じ集合に属するか否か
			return find(x) == find(y);
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 80200
// Last Change: 03/22/2020 21:02:21.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, M;
  cin >> N >> M;
  auto func = [](ll a) { return a * (a - 1) / 2; };
  cout << func(N) + func(M) << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(void){
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            cout << i << "x" << j << "=" << i*j << endl;
        }
    }
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	string n;
	cin>>n;
	int sum=0;
	for(int i=0;i<n.size();i++) sum+=(n[i]-'0');
	if(sum%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

#define inf 0x3f3f3f3f
typedef long long LL;
#define cls(x) memset(x,0,sizeof(x))
#define For(i,j,k) for(register int i=(j);i<=(k);++i)
#define Rep(i,j,k) for(register int i=(j);i>=(k);--i)
#define rint register int
#define il inline

il int read(int x=0,int f=1,char ch='0')
{
    while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
    while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return f*x;
}

const int N=5e3+5,M=200+5;
int a[N][M],L[N][M],R[N][M],q[N];
LL s[N],add[N][N];
int n,m;
/*
暴力n^2m:枚举用餐券的餐馆的区间，每种餐券都用在区间内收益最大的餐馆即可

考虑： a[i,j]能对那些区间产生贡献：
找到第一个l<i,a[l,j]>=a[i,j],第一个r>i,a[r,j]>=a[i,j]
显然a[i,j]只对在[l+1,r+1]内的包含i的区间产生贡献，差分一下即可
*/
int main()
{
    n=read(); m=read();
    For(i,2,n) s[i]=s[i-1]+read();
    For(i,1,n) For(j,1,m) a[i][j]=read();
    For(i,1,m)
    {
        int r=0;
        For(j,1,n)
        {
            while(r&&a[q[r]][i]<a[j][i]) --r;
            L[j][i]=q[r]+1; q[++r]=j;
        }
        r=0;
        Rep(j,n,1)
        {
            while(r&&a[q[r]][i]<a[j][i]) --r;
            R[j][i]=(r?q[r]-1:n); q[++r]=j;
        }
    }
    // For(i,1,n) For(j,1,m) printf("%d %d\n",L[i][j],R[i][j]);
    For(i,1,n) For(j,1,m)
    {
        add[L[i][j]][i]+=a[i][j];
        add[L[i][j]][R[i][j]+1]-=a[i][j];
        add[i+1][i]-=a[i][j];
        add[i+1][R[i][j]+1]+=a[i][j];
    }
    For(i,1,n) For(j,1,n) add[i][j]+=add[i][j-1];
    For(j,1,n) For(i,1,n) add[i][j]+=add[i-1][j];
    // for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j) printf("%d ",add[i][j]); puts(""); }
    LL ans=0;
    For(i,1,n) For(j,i,n) ans=max(ans,add[i][j]-(s[j]-s[i]));
    printf("%lld\n",ans);
    return 0;
}

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

struct UF {
	UL N; vector<UL> V;
	UL Z;
	void init(UL n) {
		N = n;
		V.resize(N);
		Z = N;
		rep(i, N) V[i] = i;
	}
	UL root(UL a) {
		if (V[a] == a) return a;
		return V[a] = root(V[a]);
	}
	void unite(UL a, UL b) {
		a = root(a), b = root(b);
		if (a != b) Z--;
		V[a] = b;
	}
};

struct Problem {
public:

	LL N, M, Q;
	UF F;
	vector<pair<UL, UL>> Q1;
	vector<pair<UL, UL>> Q2;

	void Solve() {
		scanf("%lld%lld%lld", &N, &M, &Q);
		F.init(N);
		rep(i, Q) {
			UL a, b, c; scanf("%u%u%u", &a, &b, &c);
			if (c == 0) Q1.push_back({ a, b });
			else Q2.push_back({ a, b });
		}
		for (auto& p : Q1) F.unite(p.first, p.second);
		for (auto& e : Q2) if (F.root(e.first) == F.root(e.second)) { printf("No"); return; }
		LL X = F.Z;
		if (M > (N - 1) + (X - 2) * (X - 1) / 2) { printf("No"); return; }
		if (M < (N - 1)) { printf("No"); return; }
		if (Q2.size()) {
			if (M < (N)) { printf("No"); return; }
			if(F.Z <= 2) { printf("No"); return; }
		}
		printf("Yes");
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll a,b;
	cin>>a>>b;
	if(b>=a)
		cout<<"unsafe\n";
	else
		cout<<"safe\n";
	return 0;
}

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

class union_find {
private:
	vector<int> uf;

	int find(int x) {
		return uf[x] < 0 ? x : uf[x] = find(uf[x]);
	}

public:
	union_find(int n):uf(n, -1) {}

	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y) return false;

		if(uf[x] > uf[y]) swap(x, y);
		else if(uf[x] == uf[y]) --uf[x];

		uf[y] = x;
		return true;
	}

	int number_of_sets() {
		return count_if(uf.begin(), uf.end(), [](const int &x){return x < 0;});
	}
};

typedef tuple<int, char, int, int> edge; // cost, color, u, v

pair<int, int> kruskal(const int n, vector<edge> &edges, const int offset_a) {
	union_find uf(n);
	int num_a = 0;
	int res = 0;

	const auto calc = [&](const edge &e) { return make_pair(get<0>(e) + (get<1>(e) == 'A' ? offset_a : 0), -get<1>(e)); };
	sort(begin(edges), end(edges), [&](const edge &a, const edge &b) { return calc(a) < calc(b); });

	for(const auto &e : edges) {
		if(uf.unite(get<2>(e), get<3>(e))) {
			res += calc(e).first;
			if(get<1>(e) == 'A') ++num_a;
		}
	}

	return make_pair(num_a, res);
}

int solve(const int n, const int m, const int k) {
	vector<edge> edges;
	edges.reserve(m);

	union_find uf(n);
	for(int i = 0; i < m; ++i) {
		int u, v, w;
		char l;
		cin >> u >> v >> w >> l;
		--u; --v;

		edges.emplace_back(w, l, u, v);
		uf.unite(u, v);
	}

	if(uf.number_of_sets() > 1) return -1;

	constexpr int INF = (1 << 20);
	int L = -INF, R = INF;
	while(L + 1 < R) {
		const int M = (L + R) / 2;
		if(kruskal(n, edges, M).first <= k) {
			R = M;
		}
		else {
			L = M;
		}
	}

	const auto result_R = kruskal(n, edges, R);
	const auto result_L = kruskal(n, edges, L);

	if(!(result_R.first <= k && k <= result_L.first)) return -1;
	return result_R.second - R * k;
}


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

	for(int n, m, k; cin >> n >> m >> k && n;) {
		cout << solve(n, m, k) << endl;
	}

	return EXIT_SUCCESS;
}

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

int main() {
    string N;
    cin >> N;
    int cnt = 0; 
    for (int i=0; i<N.length(); i++) {
        int n = N[i] - '0';
        cnt += n;
    }
    if (cnt % 9 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N, M; cin >> N >> M;
    vector<vector<int>> G(N+1);
    REP(i, M) {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> ord(N+1), low(N+1);
    vector<bool> vis(N+1);
    vector<pair<int, int>> bridges;
    function<int (int,int,int&)> dfs;
    dfs = [&](int node, int prev, int& k) {
        vis[node] = true;
        low[node] = ord[node] = k++;
        for (int t : G[node]) {
            if (!vis[t]) {
                low[node] = min(low[node], dfs(t, node, k));
                if (ord[t] == low[t]) bridges.push_back({node, t});
            } else if (t != prev) {
                low[node] = min(low[node], low[t]);
            }
        }
        return low[node];
    };
    int k = 0;
    dfs(1, 0, k);
    cout << bridges.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;
inline int f(long long x) {
    if (x % 4 == 0) return x;
    if (x % 4 == 1) return 1;
    if (x % 4 == 2) return x ^ 1;
    return 0;
}
signed main(){
    int a,b; cin>>a>>b;
    cout<<(f(a-1)^f(b))<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  　var n = input[0].length;
	var count = 0;
	if(n%2 == 0){
      for(var i=0; i<n/2; i++){
        if(input[0].charAt(i) != input[0].charAt(n-i-1)){
        	count++;
           }
      }
       console.log(count);
    }else{
      for(var i=0; i<n/2-1; i++){
      		if(input[0].charAt(i) != input[0].charAt(n-i-1)){
               count++;
               }
      }
       console.log(count);
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
N = gets.to_i
ary = gets.split.map(&:to_i)
budget = 1000
stock = 0
(N-1).times do |n|
    budget += stock * ary[n]
    stock = 0
    if ary[n] < ary[n+1]
        stock = budget.div(ary[n])
        budget = budget - stock * ary[n]
    end
end
budget += stock * ary[N-1]
puts budget

Measured memory_bytes: 14272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int mod = 1e9 + 7;

vector<int> f(1000001, 0);

void getf(int a) {
  for (int i = 2; i * i <= a; i++) {
    int cnt = 0;
    while (a % i == 0) {
      cnt++;
      a /= i;
    }
    if (cnt > f.at(i)) f.at(i) = cnt;
  }
  if (a > 1) f.at(a) = max(f.at(a), 1);
}

ll modinv(ll a, ll m) {
  ll b = m;
  ll u = 1;
  ll v = 0;

  while (b > 0) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }

  u %= m;
  if (u < 0) u += m;
  return u;
}

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    getf(A.at(i));
  }

  ll lcm = 1LL;
  for (int i = 2; i <= 1000000; i++) {
    if (f.at(i) == 0) continue;
    lcm = (lcm * (ll)pow(i, f.at(i)) % mod) % mod;
  }

  ll ans = 0LL;
  for (int i = 0; i < N; i++) {
    ans = (ans + lcm * modinv(A.at(i), mod) % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4224
def main():
    S = input()
    ans = 0
    for i in range(1 << (n := len(S) - 1)):
        T = ''
        for j in range(n):
            if i >> j & 1:
                T += S[j] + '+'
            else:
                T += S[j]
        T += S[n]
        ans += eval(T)
    print(ans)

if __name__ == '__main__':
    main()


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

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

    // m = 0 のとき
    if(m == 0) {
        if(n == 1) {
            cout << "0" << endl;
            return 0;
        } else {
            cout << pow(10, n - 1) << endl;
            return 0;
        }
    }

    int s[m], c[m];

    for(int i = 0; i < m; i++) {
        cin >> s[i] >> c[i];
    }

    // 被り
    for(int i = 0; i < m - 1; i++) {
        for(int j = i + 1; j < m; j++) {
            if(s[i] == s[j] && c[i] != c[j]) {
                cout << "-1" << endl;
                return 0;
            }
        }
    }

    // 一桁目0
    for(int i = 0; i < m; i++) {
        if(s[i] == 1 && c[i] == 0 && n != 1) {
            cout << "-1" << endl;
            return 0;
        }
    }
    
    
    int ans[n] = {0};
    for(int i = 0; i < m; i++) {
        ans[s[i] - 1] = c[i];
    }

    // 一桁目の処理
    if(ans[0] == 0 && n != 1) ans[0] = 1;

    for(int i = 0; i < n; i++) {
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
vector<ll> pfvec;
//pfvecは各約数についての指数を格納
ll iflediv=0,ledivexsit=0,sqrtX;
//ifledivはsqrtNより大きい、存在してもただ一つの約数
//ledivexsitはifledivが存在するなら1、存在しないのならば0
//sqrtXはxの平方根
void pf(ll x){
  ll xcopy=x;
  sqrtX=sqrt(x);
  pfvec.resize(sqrtX);
  for(ll i=1;i*i<=xcopy;i++){
    while(x%i==0 && x>1 && prime(i)==1){
      x/=i;
      pfvec.at(i-1)++;
      if(x==1){break;}
    }
    if(xcopy%i==0 && prime(xcopy/i)==1 && x%(xcopy/i)==0 && x>1){
      x/=(xcopy/i);
      ledivexsit++;
      iflediv=xcopy/i;
      break;
    }
  }
}
int main(){
  ll M,N;
  cin>>M>>N;
  pf(N);
  ll ans=1;
  for(ll i=0;i<sqrtX;i++){
    if(pfvec.at(i)>=M){
      for(ll j=0;j<(pfvec.at(i)/M);j++){
        ans*=(i+1);
      }
    }
  }
  if(ledivexsit>=M){
    ans*=iflediv;
  }
  cout<<ans<<endl;
}

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

#define ll   	long long
#define pb	    push_back
#define F   	first
#define S	    second
#define B   	begin()
#define E	    end()
#define FASTIO   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


using namespace std ;



int main()
{
    FASTIO
    int r , d , x ;
    cin >> r >> d >> x ;
    for ( int i = 0 ; i < 10 ; i++ )
    {
        x = r*x - d ;
        cout << x << "\n" ;
    }
    return 0 ;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
inline int newline() { putchar('\n'); return 0; }

ll textCount, aimCount, threshold;
vector<ll> prices(12);
vector<vector<ll>> a(12, vector<ll>(12));
ll result = LLONG_MAX;

bool ok(vector<ll> skills) {
    bool flag = true;
    rep2(i, aimCount) {
        if (skills[i] < threshold) {
            flag = false;
            break;
        }
    }
    return flag;
}

void dfs(ll sum, vector<ll> skills, ll position) {

    if (ok(skills)) {
        if (sum < result) result = sum;
        return;
    }

    if (position == textCount) return;

    dfs(sum, skills, position + 1);

    ll p = prices[position];
    rep2(i, aimCount) {
        skills[i] += a[position][i];
    }
    dfs(sum + p, skills, position + 1);
}

int main() {
    cin(textCount);
    cin(aimCount);
    cin(threshold);

    rep2(i, textCount) {
        cin(prices[i]);

        rep2(j, aimCount) {
            cin(a[i][j]);
        }
    }

    dfs(0, vector<ll>(aimCount, 0), 0);

    if (result == LLONG_MAX) {
        print(-1);
    } else {
        print(result);
    }
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
int a[4],ans;
int main()
{
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	ans=(a[3]-a[1])/2;
	a[1]+=ans*2;
	ans+=(a[3]-a[2])/2;
	a[2]+=(a[3]-a[2])/2*2;
	sort(a+1,a+4);
	if(a[3]==a[2]&&a[2]==a[1]+1)
		ans+=2;
	if(a[3]==a[2]+1&&a[2]==a[1])
		ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(void) {
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
	if(op=='?')break;
		if(op=='+'){
			printf("%d\n",a+b);
		}else if(op=='-'){
			printf("%d\n",a-b);
		}else if(op=='*'){
			printf("%d\n",a*b);
		}else if(op=='/'){
			printf("%d\n",a/b);
		}
	}
	
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vll X(N), Y(N);
	map<Pl, ll> idx;
	
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
		idx[Pl(Y[i], X[i])] = i;
	}

	ll minv = N;
	for (int a = 0; a < N; a++) {
		for (int b = 0; b < N; b++) {
			if (a == b) continue;
			ll p = X[b] - X[a], q = Y[b] - Y[a];
			bitset<55> used;
			ll cnt = 0;
			for (int i = 0; i < N; i++) {
				if (!used[i]) {
					used[i] = true;
					cnt++;
					ll x = X[i], y = Y[i];
					while (true) {
						x += p, y += q;
						if (idx.find(Pl(y, x)) == idx.end()) break;
						used[idx[Pl(y, x)]] = true;
					}
					while (true) {
						x -= p, y -= q;
						if (idx.find(Pl(y, x)) == idx.end()) break;
						used[idx[Pl(y, x)]] = true;
					}
				}
			}
			chmin(minv, cnt);
		}
	}
	cout << minv << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int e;
int m, a;
int main()
{
	while(cin >> e && e!=0)
	{
		m=e;
		for(int z=0; (z*z)*z<=e; z++)
		{
			for(int y=0; (y*y)+((z*z)*z)<=e; y++)
			{
				a=y;
			}
			m=min(m, a+z+e-a*a-z*z*z);
		}
		cout << m << endl;
	}
	return 0;
}

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

const int64_t INF = 1LL << 60;

int main() {
    int N; cin >> N;
    vector<pair<int, int>> A(N);
    for(int i = 0; i < N; ++i) {
        int a; cin >> a;
        A[i] = make_pair(a, i);
    }
    sort(A.begin(), A.end(), greater<pair<int, int>>());

    vector<vector<int64_t>> dp(N + 1, vector<int64_t>(N + 1, -INF));
    dp[0][0] = 0;

    auto score = [&](int a, int b) -> int64_t { return (int64_t)abs(A[a].second - b) * A[a].first; };

    auto f = [&](auto &&f, int l, int r) -> int64_t {
        if(dp[l][r] != -INF) return dp[l][r];
        int n = l + r - 1;
        if(l) dp[l][r] = max(dp[l][r], f(f, l - 1, r) + score(n, l - 1));
        if(r) dp[l][r] = max(dp[l][r], f(f, l, r - 1) + score(n, N - r));
        return dp[l][r];
    };
    int64_t ans = -INF;
    for(int i = 0; i <= N; ++i) {
        ans = max(ans, f(f, i, N - i));
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 34892
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, a[10100], b[10100], sum1, sum2;

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sum1 += a[i];
    }
    for(int i = 0; i < N; i++){
        cin >> b[i];
        sum2 += b[i];
    }
    if(sum2 < sum1){
        printf("No\n");
        return 0;
    }
    int sa = sum2 - sum1;
    int x = sa;
    for(int i = 0; i < N; i++){
        if(a[i] < b[i]){
            x -= (b[i] - a[i] + 1) / 2;
            a[i] += ((b[i] - a[i] + 1) / 2) * 2;
        }
    }
    if(x < 0){
        printf("No\n");
        return 0;
    }
    int y = sa;
    for(int i = 0; i < N; i++){
        y -= a[i] - b[i];
    }
    if(x * 2 == y){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }




    return 0;
}
/*



*/


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	string s;
	cin >> s;

	if (s[0] == 'R' && s[0] == s[1] && s[1] == s[2]) {
		cout << "3\n";
	} else if (s[1] == 'R' && (s[0] == s[1] || s[1] == s[2])) {
		cout << "2\n";
	} else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
		cout << "1\n";
	} else {
		cout << "0\n";
	}

	return 0;
}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N;
int A[100000];

signed main()
{
	cin >> N;
	REP(i, N)
	{
		cin >> A[i];
	}
	ARY_SORT(A, N);

	int n = A[N - 1];
	double half = n / 2.0;

	double min = DBL_MAX;
	int r = -1;
	REP(i, N - 1)
	{
		double a = abs(half - A[i]);
		if (min > a)
		{
			min = a;
			r = A[i];
		}
	}
	cout << n << " " << r << endl;
}







Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>

using namespace std;

int main(){
  int n;
  int a[1111111];
  cin>>n;
  for(int i = 0,end = 3 * n;i<end;i++){
    cin>>a[i];
  }
  sort(a,a+3*n);
  long long ans = 0;
  for(int i = 0;i<n;i++){
    //cout<<"num:"<<3*n-2*(i+1)<<"\t"<<a[3*n-2*(i+1)]<<endl;
    ans += a[3*n-2*(i+1)];
  }
  cout<<ans<<endl;

  return 0;
}


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

int main() {
	string s;
	cin >> s;

	int len = s.size();
	int res = len;
	for (int i = 0; i < len - 1; i++) {
		if (s[i] == s[i + 1]) continue;

		res = min(res, max(i + 1, len - i - 1));
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Array.IO

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

primes = primes' [2..50021]
  where
    primes' [] = []
    primes' (p:l) = (p : primes' [x | x <- l, mod x p /= 0])

f n = [last $ takeWhile (<n) primes, head $ dropWhile (<=n) primes]

main = do
    map readInt . lines <$> getContents >>= mapM_ (putStrLn . sjoin . f)

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

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int N;
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> r(N+1);
  vector<int> l(N+1);
  r[0] = 0;
  l[N] = 0;

  REP(i, N){
    r[i+1] = r[i]+A[i];
  }
  RREP(i, N){
    l[i] = l[i+1]+A[i];
  }

  int ans = INF;
  REP(i, N+1){
    chmin(ans, abs(r[i]-l[i]));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4992
def main():
    chars = dict()
    for c in input():
        if not c in chars:
            chars[c] = 1
        else:
            chars[c] += 1

    if all(v % 2 == 0 for v in chars.values()):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const int INFI = 1000000000;
 const ll INFL = (1LL << 60);

 int main() {
   int N; cin >> N;
   string S1, S2; cin >> S1 >> S2;

   int cnt = 0;
   ll ans;
   bool state;

   if (S1.at(0) == S2.at(0)) {
     ans = 3;
     cnt = 1;
     state = true;
   }
   else {
     ans = 6;
     cnt = 2;
     state = false;
   }

   while (cnt < N) {
     if (S1.at(cnt) == S2.at(cnt)) {
       if (state) ans = ans * 2 % MOD;
       cnt++;
       state = true;
     }
     else {
       if (state) ans =  ans * 2 % MOD;
       else ans = ans * 3 % MOD;
       cnt += 2;
       state = false;
     }
   }

   cout << ans << endl;
 }


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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N;
    cin >> N;
    vector<ll> a(N), b(N);
    rep(i, N) cin >> a[i] >> b[i];
    ll ans = 0;
    for(int i = N-1; i >= 0; i--){
        a[i] += ans;
        if(a[i] % b[i] == 0) continue;
        else{
            ll v = a[i] / b[i];
            ans += (b[i] * (v+1) - a[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4824
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << fixed << setprecision(20);
    int n,m; cin >> n >> m;
    int sum = 0;
    rep(i,m){
        int x; cin >> x;
        sum += x;
    }
    if(n < sum) cout << -1 << endl;
    else cout << n-sum << endl;
    return 0;
}

Measured memory_bytes: 3628
from math import floor
import numpy as np

N = int(input())
K = floor((N * 2) ** 0.5)
if K * (K + 1) // 2 != N:
    print('No')
    exit()
else:
    print('Yes')
    print(K + 1)

grid = np.ones((K, K), np.int64)
grid[1:, 0] = np.arange(1, K)
grid[:, 0] = np.cumsum(grid[:, 0])
grid = np.cumsum(grid, axis=1)
answer = []
answer.append([K] + np.diag(grid).tolist())
answer.append([K] + grid[:, 0].tolist())
for i in range(1, K):
    answer.append([K] + grid[i, :i].tolist() + grid[i:, i].tolist())

for i in answer:
    print(' '.join(map(str, i)))


Measured memory_bytes: 23092
function parseInt(x) parse(Int, x) end

function main()
	a = parseInt.(split(readline()))
	if a[1] < a[3]
		if a[2] < a[4]
			print(max(a[2]-a[3], 0))
		else
			print(a[4]-a[3])
		end
	else
		if a[4] < a[2]
			print(max(a[4]-a[1], 0))
		else
			print(a[2]-a[1])
		end
	end
end

main()

Measured memory_bytes: 172176
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define INF 1000000000000000ll
using namespace std;
typedef long long ll;
int n,m;
vector<int> a[MAXN];
vector<ll> val[MAXN];
ll sum[MAXN];
int tim[MAXN];
bool vis[MAXN],flag;
ll minl,maxl,now;
void upd(ll x,int ts){
	if(ts<0)
		maxl=min(maxl,x-1);
	else
		minl=max(minl,-x+1);
}
void updx(ll valx,ll valy,ll sumv,int tims){
	//PF("{%lld %lld %lld %d}",valx,valy,sumv,tims);
	if(tims>0){
		if(sumv-valx-valy<=0||(sumv-valx-valy)%2ll!=0)
			flag=1;
		else{
			if(now!=-1&&now!=(sumv-valx-valy)/2ll)
				flag=1;	
			else
				now=(sumv-valx-valy)/2ll;
		}
	}
	else{
		if(-sumv+valx+valy<=0||(-sumv+valx+valy)%2ll!=0)
			flag=1;
		else{
			if(now!=-1&&now!=(-sumv+valx+valy)/2ll)
				flag=1;	
			else
				now=(-sumv+valx+valy)/2ll;
		}
	}
}
void dfs(int x){
	vis[x]=1;
	//PF("{%d %lld %d}\n",x,sum[x],tim[x]);
	for(int i=0;i<a[x].size();i++){
		int u=a[x][i];
		upd(val[x][i]-sum[x],-tim[x]);
		if(vis[u]==1){
			if(tim[x]!=tim[u]){
				if(sum[x]+sum[u]!=val[x][i])
					flag=1;	
			}
			else{
				updx(sum[x],sum[u],val[x][i],tim[x]);
			}
		}
		else{
			sum[u]=val[x][i]-sum[x];
			tim[u]=-tim[x];
			dfs(u);	
		}
	}
}
int main(){
	now=-1;
	SF("%d%d",&n,&m);
	int u,v;
	ll w;
	for(int i=1;i<=m;i++){
		SF("%d%d%lld",&u,&v,&w);	
		a[u].push_back(v);
		a[v].push_back(u);
		val[u].push_back(w);
		val[v].push_back(w);
	}
	sum[1]=0;
	tim[1]=1;
	minl=1,maxl=INF;
	dfs(1);
	//PF("{%lld %lld %lld}",now,minl,maxl);
	if(flag==1)
		PF("0");
	else if(now!=-1){
		if(now>=minl&&now<=maxl)
			PF("1");
		else
			PF("0");	
	}
	else 
		PF("%lld",max(0ll,maxl-minl+1));
}


Measured memory_bytes: 20224
#include <bits/stdc++.h>
using namespace std;
const int mx = 112;
int w[mx], v[mx];
long long dp[112345];
int main() {
  int n, W;
  cin >> n >> W;
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = W; j >= 0; j--) {
      if (j-w[i] >= 0) dp[j] = max(dp[j], v[i] + dp[j-w[i]]);
    }
  }
  long long ans = 0;
  for (int j = 0; j <= W; j++) ans = max(ans, dp[j]);
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = k / 2;
        int b = k / 2 + ((k % 2 == 1) ? 1 : 0);

        System.out.println(a * b);
    }

}


Measured memory_bytes: 22868
S = input()
Q = int(input())
r = False
F = []
B = []
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    if r:
      r = False
    else:
      r = True
  else:
    if (q[1] == '1' and not r) or (q[1] == '2' and r):
      F.append(q[2])
    else:
      B.append(q[2])

if r:
  print(''.join(B[::-1]+list(reversed(S))+F))
else:
  print(''.join(F[::-1]+list(S)+B))


Measured memory_bytes: 83800
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int main(void){
  int N;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  int count = 0;
  for(int i=0;i<N;i++){
    if((i+1)%2==1 && a[i]%2==1) count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 3760
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {
	int a;
	cin >> a;
	cout << a + a * a + a * a * a;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

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


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


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


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


int main(){
    ll N;
    cin>>N;
    ll sum = 0;
    rep(i,1,N+1){
        sum += (i + ((N)/i)*i) * ((N)/i)/2;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3616
#![allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

trait Monoid {
   fn unit() -> Self;
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
enum MinInt {
   Val(i64),
   Maximal,
}
impl MinInt {
   fn unwrap(self) -> i64 {
      if let Self::Val(x) = self {
         x
      } else {
         panic!();
      }
   }
}
impl std::ops::Mul for MinInt {
   type Output = Self;
   fn mul(self, other: Self) -> Self {
      if self < other {
         self
      } else {
         other
      }
   }
}
impl Monoid for MinInt {
   fn unit() -> Self { MinInt::Maximal }
}

use MinInt::*;

#[fastout]
fn main() {
   input! {
      n: usize,
      m: usize,
      s: Bytes,
   }

   let mut st = SegmentTree::new(n + 1, Maximal, |a, b| a * b);
   st.update(0, Val(0));
   for i in 1..=n {
      if s[i] == b'0' {
         let x = if i <= m {
            st.get(0, i)
         } else {
            st.get(i - m, i)
         };
         if let Val(x) = x {
            st.update(i, Val(x + 1));
         }
      }
   }

   if st.get(n, n + 1) == Maximal {
      println!("-1");
      return;
   }
   let mut x = vec![-1; n + 1];
   for i in 0..=n {
      if let Val(y) = st.get(i, i + 1) {
         x[i] = y;
      }
   }

   let k = st.get(n, n + 1).unwrap();
   let mut pos = vec![n; k as usize + 1];
   pos[0] = 0;
   for k in (1..k).rev() {
      let mut p = pos[k as usize + 1] - 1;
      while p > 0 && p + m >= pos[k as usize + 1] {
         if x[p] == k {
            pos[k as usize] = p;
         }
         p -= 1;
      }
   }
   for i in 0..k as usize {
      print!("{} ", pos[i + 1] - pos[i]);
   }
   println!("");
}

struct SegmentTree<T> {
   n: usize,
   tree: Vec<T>,
   identity: T,
   op: fn(T, T) -> T,
}
impl<T: Clone + Copy> SegmentTree<T> {
   fn new(_n: usize, identity: T, op: fn(T, T) -> T) -> Self {
      let mut n = 1;
      while n < _n {
         n *= 2;
      }
      let t = vec![identity; 2 * n - 1];
      SegmentTree {
         n: n,
         tree: t,
         identity: identity,
         op: op,
      }
   }
   fn update(&mut self, i: usize, v: T) {
      let mut now = self.n - 1 + i;
      let op = self.op;
      self.tree[now] = v;
      while now != 0 {
         now = (now - 1) / 2;
         self.tree[now] = op(self.tree[2 * now + 1], self.tree[2 * now + 2]);
      }
   }
   fn __get(&self, l: usize, r: usize, ln: usize, rn: usize, now: usize) -> T {
      if rn <= l || r <= ln {
         self.identity
      } else if l <= ln && rn <= r {
         self.tree[now]
      } else {
         let mid = (ln + rn) / 2;
         let op = self.op;
         op(
            self.__get(l, r, ln, mid, now * 2 + 1),
            self.__get(l, r, mid, rn, now * 2 + 2),
         )
      }
   }
   /// range => [l, r)
   fn get(&self, l: usize, r: usize) -> T { self.__get(l, r, 0, self.n, 0) }
}


Measured memory_bytes: 7668