akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__",", __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

class UnionFind {
public:
  vector<int> par, rank; // parent(negative := its root and abs-value is its size), depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;  // already belong to same tree
    if(rank[x] < rank[y]){  // y becomes parent node
      par[y] += par[x];
      par[x] = y;
    } else {  // x becomes parent node
      par[x] += par[y];
      par[y] = x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int size(int x){ return -par[find(x)]; }
};

int main(){
  int n;
  cin>>n;
  vector<int> a(n+1,0), b(n+1,0);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) a[n] ^= a[i];
  rep(i,n) b[n] ^= b[i];

  vector<int> sa(a),sb(b);
  sort(all(sa));
  sort(all(sb));
  if(sa!=sb){
    cout << -1 << endl;
    return 0;
  }

  sa.erase(unique(all(sa)), sa.end());
  UnionFind uf(sa.size());

  int cnt = 0;
  rep(i,n){
    if(a[i]==b[i]) a[i] = b[i] = -1;
    else {
      a[i] = lower_bound(all(sa), a[i]) - sa.begin();
      b[i] = lower_bound(all(sa), b[i]) - sa.begin();
      uf.unite(a[i], b[i]);
      cnt++;
    }
  }

  if(cnt==0){
    cout << 0 << endl;
    return 0;
  }

  vector<bool> checked(sa.size(), false);
  rep(i,n) if(a[i]>=0 && !checked[uf.find(a[i])]){
    cnt++;
    checked[uf.find(a[i])] = true;
  }

  int last = lower_bound(all(sa), a[n]) - sa.begin();
  if(checked[uf.find(last)]) cnt--;

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 2560
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int n,q;
const int N=1e6;
#define l first
#define r second
vector<int> a;
vector<int> last(N,-1);
vector<pair<int,pair<int,int>>> p;

bool cmp(pair<int,pair<int,int>> a, pair<int,pair<int,int>> b)
{
	return a.r.r<b.r.r;
}
int tree[N];
void add(int val, int idx)
{
	while(idx<=n)
	{
		tree[idx]+=val;
		idx+=(idx&(-idx));
	}
}
int qu(int id)
{
	int sum=0;
	while(id>=1)
	{
		sum+=tree[id];
		id-=(id&-id);
	}
	return sum;
}
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	cin>>n>>q;
	a=vector<int>(n+1);
	vector<int> ans(q);
	for(int i=1;i<=n;i++)cin>>a[i];

	p=vector<pair<int,pair<int,int>>>(q);
	for(int i=0;i<q;i++)
	{
		cin>>p[i].r.l>>p[i].r.r;
		p[i].l=i;
	}
	sort(p.begin(),p.end(),cmp);
	int cur=0;
	for(int i=1;i<=n;i++)
	{
		if(last[a[i]]==-1)
		{
			last[a[i]]=i;
			add(1,i);
		}
		else
		{
			add(-1,last[a[i]]);
			last[a[i]]=i;
			add(1,last[a[i]]);
		}

		while(p[cur].r.r==i and cur<q)
		{
			//cout<<cur<<" "<<i<<"\n";
			ans[p[cur].l]=qu(p[cur].r.r)-qu(p[cur].r.l -1);
			cur++;
		}
	}

	for(int i=0;i<q;i++)cout<<ans[i]<<"\n";


	
	
}

Measured memory_bytes: 35064
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!
struct Node {
  int org_id;
  int new_id;
  vi children;
};
// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n,q; cin>>n>>q;
  vvi g(n);
  vi order(n);
  vi a_(n);
  vi b_(n);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b; a--; b--;
    dump(a,b);
    g[a].push_back(b);
    g[b].push_back(a);
    a_[i] = a; b_[i] = b;
  }

  dump(g);

  // DFS して番号をつけ直す
  int o = 0;
  stack<int> s; s.push(0);
  vector<bool> used(n, false);
  while(!s.empty()){
    int from = s.top(); s.pop();
    order[from] = o++;
    used[from] = true;
    for(auto to : g[from]){
      if(!used[to]) s.push(to);
    }
  }
  dump(order);

  vvi G(n);
  rep(i,n) {
    if(a_[i]==b_[i]) continue;
    if(order[a_[i]]<order[b_[i]]) G[a_[i]].push_back(b_[i]);
    else  G[b_[i]].push_back(a_[i]);
  }

  dump(G);

  vi val(n,0);
  rep(i,q){
    int p, x;
    cin >>p>>x;
    val[p-1] += x;
  }

  stack<int> ss;
  ss.push(0);
  while(!ss.empty()){
    int from = ss.top(); ss.pop();
    for(auto to : G[from]){
      val[to] += val[from];
      ss.push(to);
    }
  }

  rep(i,n){
    cout << val[i] << " ";
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 27520
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n;
  cin>>n;
  int ans = 0;
  rep(i,n){
    int l,r;
    cin>>l>>r;
    ans += r-l+1;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
num = int(input())
values = [int(i) for i in input().split( )]

result = []
for i in range(num-1):
  #print(values[0:i+1])
  #print(values[i+1:num])
  #print()
  result.append(abs(sum(values[0:i+1]) - sum(values[i+1:num])))
  
result.sort()
print(result[0])

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

using ll = long long;

int main() {
    int n;
    std::cin >> n;
    int cnt = 0;
    ll res = 0, min = 1LL << 55;
    for (int i = 0; i < n; i++) {
        ll a;
        std::cin >> a;
        if (a < 0) {
            cnt += 1;
            a = -1LL * a;
        }
        res += a;
        min = std::min(min, a);
    }

    if (cnt % 2 == 1) {
        min *= 2LL;
        res -= min;
    }

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


Measured memory_bytes: 384
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
	int H,W,n;
	cin>>H>>W>>n;
	vector<int> a(n);
	vector<vector<int>> s(H,vector<int>(W));
	rep(i,n) cin>>a[i];
	int i=0;
	bool flag=true;
	rep(j,H*W){
		if(a[i]==0) i++;
		if(flag) s[j/W][j%W]=i+1;
		else s[j/W][W-1-j%W]=i+1;
		if(j%W==W-1) flag = (!flag);
		a[i]--;
	}
	rep(i,H) rep(j,W) cout<<s[i][j]<<" \n"[j==W-1];
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int count = 0;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    if(h >= K) {
      count++;
    }
  }
  cout << count << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

map<ll, ll> whole;

void fact(ll x, map<ll, ll> &out) {
    ll temp = x;
    if(x == 1) {
        out[1]++;
        whole[1]++;
        return;
    }
    for(ll i = 2;i * i <= x;i++) {
        while(temp % i == 0) {
            temp /= i;
            whole[i]++;
            out[i]++;
        }
    }
    if(temp > 1) {
        whole[temp]++;
        out[temp]++;
    }
}

int main(void) {
    ll N;
    ll maxi = 0;
    ll count = 0;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
        maxi = max(maxi, A[i]);
    }
    vector<ll> table(maxi + 1);
    rep(i, N) {
        table[A[i]]++;
        if(table[A[i]] == 1) {
            for(ll j = A[i] + A[i];j <= maxi;j += A[i]) table[j]++;
        }
    }
    rep(i, N) {
        if(table[A[i]] == 1) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 12696
N = str(input())

ans = "No"

first_string = N[0]
first_string_count = 0
last_string  = N[-1]
last_string_count = 0

if first_string == N[1] and first_string == N[2]:
  ans = "Yes"
elif last_string == N[1] and last_string == N[2]:
  ans = "Yes"
else:
  ans = "No"

print(ans)


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

using namespace std;

#define int long long

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)

//--------

int COUNT[50];

signed main(){
    int N, M;
    cin >> N >> M;
    REP(m, N)
    {
        int K;
        cin >> K;
        REP(i, K)
        {
            int A;
            cin >> A;
            A--;
            COUNT[A]++;
        }
    }

    int ans = 0;

    REP(i, M)
    {
        if(COUNT[i] == N) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define cases long long test;cin>>test;while(test--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;



int main()
{
    f_io;
    string s,t;
    cin >> s >> t;
    ll l1 = (ll)s.length(),l2=(ll)t.length();
    vector<vector<ll> > dp(l1+1,vector<ll>(l2+1));
    foi(1,l1+1)
    {
        foj(1,l2+1)
        {
            if(s[i-1]==t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string ans = "";
    ll i = l1,j=l2;
    while(i>0 and j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans = s[i-1]+ans;
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 74104
N = int(input())
L = list(map(int, input().split()))
count = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            condition = L[i] != L[j] and L[i] != L[k] and L[j] != L[k]
            condition = condition and L[i] < L[j] + L[k]
            condition = condition and L[j] < L[k] + L[i]
            condition = condition and L[k] < L[i] + L[j]
            if condition:
                count += 1
print(count)


Measured memory_bytes: 9196
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    
    while(cin >> a >> b){
        c = a + b;
        int num = 0;
        while(c>0){
            c = c / 10;
            num++;
        }
        cout << num << endl;
    }
    return 0;
}



Measured memory_bytes: 3004
ac = 0
wa = 0
tle = 0
re = 0
t  = int(input())
while t:
    k = input()
    if k == "AC":
        ac += 1
    elif k == "WA":
        wa += 1
    elif k == "TLE":
        tle += 1
    elif k == "RE":
        re +=1
    t = t-1
print("AC","x",ac)
print("WA","x",wa)
print("TLE","x",tle)
print("RE","x",re)

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


int main(void){
    int h,w,i,j,dp[103][103]={};
    string s[103];
    
    cin >> h >> w;
    for (i=0;i<h;i++) cin >> s[i];
    
    if (s[0][0]=='#') dp[0][0]=1;
    for (i=0;i<h;i++) for (j=0;j<w;j++){
        if (i==0 && j==0) continue;
        int v1,v2;
        v1=v2=1e9;
        if (i>0){
            v1=dp[i-1][j];
            if (s[i][j]=='#' && s[i-1][j]=='.'){
                v1++;
            }
        }
        if (j>0){
            v2=dp[i][j-1];
            if (s[i][j]=='#' && s[i][j-1]=='.'){
                v2++;
            }
        }
        dp[i][j]=min(v1,v2);
    }
    
    cout << dp[h-1][w-1] << endl;
    
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {
  int n, d;
  cin >> n >> d;
  vvi x(n, vi(d));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < d; j++)
      cin >> x[i][j];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int sum = 0;
      for (int k = 0; k < d; k++) {
        sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      bool f = false;
      for (int k = 0; k * k <= sum; k++) {
        if (k * k == sum) {
          f = true;
        }
      }
      if (f) cnt += 1;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
int GCD(int a, int b) {
	return b ? GCD(b, a%b) : a;
}
//sort(a, a + N, greater<int>())   // descend
//sort(a, a+N)                    //  ascend

using ll = long long;
using namespace std;



int main() {
	
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	
	bool ppx = true;

	for (int i = a-1; i < d; i++) {
		if (s[i] == '#' && s[i + 1] == '#') {
			ppx = false;
		}
	}

	// a<c<b<d 成功了

	if (b < d && d < c && ppx==true) {
		if (s[b - 2] == '#' || s[b] == '#') {
			if (s[d - 2] == '#' || s[d] == '#') {
				ppx = false;
				for (int i = b-2; i < d-2; i++) {
					if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
						ppx = true;
						break;
					}
				}
			}
		}
	}

	if (ppx == true) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(read())
cnt = 0
for i in range(1, n + 1):
    if len(str(i)) % 2 == 1:
        cnt += 1
print(cnt)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;


int main(){
   int n;
   string s;
   string s1,s2;
   map<string,bool> Index;
   cin >> n;
   while(n-- > 0){
      cin >> s;
      for(int i=1;i<s.length();i++){
	 s1 = s.substr(0,i);
	 s2 = s.substr(i,s.length()-i);	 
	 //cout <<s1 << " " << s2 << endl;
	 Index[s1+s2] = true;
	 Index[s2+s1] = true;
	 reverse(s1.begin(),s1.end()) ;
	 Index[s1+s2] = true;
	 Index[s2+s1] = true;
	 reverse(s1.begin(),s1.end()) ;
	 
	 reverse(s2.begin(),s2.end()) ;
	 Index[s1+s2] = true;
	 Index[s2+s1] = true;
	 reverse(s1.begin(),s1.end()) ;
	 Index[s1+s2] = true;
	 Index[s2+s1] = true;
      }

      cout<< Index.size() << endl;
      Index.clear();
   }
   return 0;
}

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

int main(void){
int i;
int len;
char s[4096];
scanf("%s", s);

  len = strlen(s);
  for(i = 1; i <= len;i++) {
    s[i];
  }
  for(i = len-1; i >= 0; i--){

  printf("%c",s[i]);
}
printf("\n");
return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1e9 + 7;
Int B[2001][2001];
int main()
{
    int N, M; cin >> N >> M;
    vector<int> S(N), T(M);
    for (auto &s : S) cin >> s;
    for (auto &t : T) cin >> t;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            B[i][j] = (
                B[i][j-1] + B[i-1][j] + MOD - B[i-1][j-1] +
                (S[i-1] == T[j-1] ? B[i-1][j-1] + 1 : 0)
            ) % MOD;
        }
    }
    cout << (B[N][M] + 1) % MOD << '\n';
    return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

struct Info{ll v; ll c; ll t;};
struct DP{
	ll v; ll c; ll t;
	bool operator<(const DP& o) const{
		return t > o.t;
	}
};

int mainsolve(){

	ll n,m,s;
	cin >> n >> m >> s;
	vector<ll> a(m), b(m);
	vector<vector<Info>> to(n);
	rep(i,m){
		ll u,v;
		cin >> u >> v >> a[i] >> b[i];
		--u; --v;
		to[u].push_back(Info{v,a[i],b[i]});
		to[v].push_back(Info{u,a[i],b[i]});
	}
	vector<ll> c(n), d(n);
	rep(i,n) cin >> c[i] >> d[i];

	ll INF = 1e18;
	ll maxc = n*50; // 銀貨の枚数はこれだけあれば十分
	vector<vector<ll>> dp(n,vector<ll>(maxc,INF)); // dp[v][c]: 銀貨c枚持ってvにいる状態にするためにかかる時間 

	priority_queue<DP> q;
	q.push(DP{0,min(maxc-1,s),0});

	while(!q.empty()){
		DP now = q.top(); q.pop();
		if(now.c >= 0 && now.t >= 0 && now.t < dp[now.v][min(maxc-1,now.c)] ){
			dp[now.v][min(maxc-1,now.c)] = now.t;

			for(Info next : to[now.v]){
				q.push(DP{next.v,now.c - next.c, now.t + next.t}); // 移動
			}
			q.push(DP{now.v,now.c + c[now.v], now.t + d[now.v]}); // 換金
		}
	}
	
	rep(i,n){
		if(i==0) continue;
		ll res = INF;
		rep(j,maxc) res = min(res, dp[i][j]);
		cout << res << endl;
	}
	
	return 0;
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 16524
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
int mod = (int) 1e9 + 7;

int main(){
    
    int n;
    cin >> n;
    
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    
    multiset<P> s1, s2;
    
    int count = 0;
    rep(i,n){
        int ac = 0, bc = 0, acm = 0, bcm = 0, l = s[i].size();
        
        rep(j,l){
            
            if(s[i][j] == '(') ac--;
            if(s[i][j] == ')') ac++;
            acm = max(acm, ac);
        }
        
        rep(j,l){
            
            if(s[i][l - 1 - j] == '(') bc++;
            if(s[i][l - 1 - j] == ')') bc--;
            bcm = max(bcm, bc);
        }
        
        if(bcm - acm >= 0){
            s1.emplace(P(acm, bcm));
        } else {
            s2.emplace(P((-1 * bcm),acm));
        }
        
    }
    
    count = 0;
    
    for(auto i:s1){
        count -= i.first;
        if(count < 0){
            cout << "No" << "\n";
            return 0;
        }
        count += i.second;
    }
    
    for(auto i:s2){
        count -= i.second;
        if(count < 0){
            cout << "No" << "\n";
            return 0;
        }
        count -= i.first;
    }
    
    if(count > 0){
        cout << "No" << "\n";
        return 0;
    }
    
    cout << "Yes" << "\n";
    
    return 0;
}



Measured memory_bytes: 72992
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>

#define INF 1000000000;
#define MOD 1000000007;
typedef long long ll;
using namespace std;

int main()
{
    int N; cin >> N;
    string ans;
    if (N < 1200) {
        ans = "ABC";
    }
    else if (N < 2800) {
        ans = "ARC";
    }
    else {
        ans = "AGC";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n,i,w=0,r=0,ans=0;
    cin>>n;
    string s;
    cin>>s;
    for(i=0;i<n;i++)
    {
    	if(s[i]=='R')
    	r++;
    	else
    	w++;
	}
    for(i=0;i<r;i++)
    {
    	if(s[i]=='W')
    	ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <cctype>

using namespace std;

int main(){
	int alphabet[26] = {};
	char ch;

	while(cin >> ch){
		if(isalpha(ch)){
			int n = tolower(ch) - 'a';
			alphabet[n]++;
		}
	}

	for(int i = 0; i < 26; i++){
		cout << static_cast<char>('a' + i) << " : " << alphabet[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1140
K = int(input())
ans = 1
X = 7
cnt = K
while(cnt > 0):
#     print('rem={}'.format(X%K))
    rem = X % K
    if rem == 0:
        print(ans)
        break
    else:
        ans += 1
        X = rem*10 + 7 
        cnt -= 1

if rem != 0:
    print(-1)

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

using namespace std;

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		cout << (n+1)/2 << "\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

using namespace std;

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

    int n;
    char str[11];
    map<string, int> item;

    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%s", str);
        item[str]++;
    }

    printf("%d\n", item.size());

    return 0;
}

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

#define INF 100000000;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const double eps = 1.0e-14;
const double PI = (acos(-1));
int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double space = b - (x / (a*a));
    //cout << space << endl;
    double ans = atan( a / ( 2 * space ));
    if(2 * space > b){
        double c = (2 * x) / (b * a);
        ans = atan(c / b);
    }
    ans *= 180 / PI;
    ans = 90 - ans;
    printf("%.10f",ans + eps);
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}

//小文字=大文字+32

int main() {
	int s;
	cin >> s;
	if ((s % 100 > 12 && s / 100 > 12)||(s%100==0&&s/100==0)|| (s % 100 > 12 && s / 100==0)|| (s % 100 ==0&& s / 100 > 12)) {
		cout << "NA";
	}
	else if (s % 100 > 12||s%100==0) {
		cout << "MMYY";
	}
	else if (s / 100 > 12||s/100==0) {
		cout << "YYMM";
	}
	else{
		cout << "AMBIGUOUS";
	}
}
	



Measured memory_bytes: 3604
import sys

s = str(raw_input())

for i in range(len(s)):
    if i%2==0:
        if s[i]=="L":
            print("No")                                                           
            sys.exit()
    else:
	if s[i]=="R":
            print("No")                                                          
            sys.exit()

print("Yes")


Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <complex>
#include <cstdlib>
#include <cctype>
using namespace std;

int p;
string str;
bool v;

complex<int> expr();
complex<int> factor();
complex<int> term();

bool isValid(complex<int> c)
{
	if(abs(c.real()) > 10000 || abs(c.imag()) > 10000) return false;
	return true;
}

complex<int> parseInt()
{
	int res = 0;
	while(isdigit(str[p])) {
		res *= 10;
		res += str[p] - '0';
		p++;

		v &= isValid(complex<int>(res, 0));
	}

	return complex<int>(res, 0);
}

complex<int> expr()
{
	complex<int> l = factor();
	while(str[p] == '+' || str[p] == '-') {
		char op = str[p++];

		complex<int> r = factor();
		if(op == '+') l += r;
		if(op == '-') l -= r;

		v &= isValid(l);
	}

	return l;
}


complex<int> factor()
{
	complex<int> l = term();
	while(str[p] == '*') {
		p++;

		complex<int> r = term();

		l *= r;
		v &= isValid(l);
	}

	return l;
}

complex<int> term()
{
	complex<int> l;
	if(str[p] == '(') {
		p++;
		l = expr();
		p++;
	}
	else if(str[p] == 'i') {
		l = complex<int>(0, 1);
		p++;
	}
	else {
		l = parseInt();
	}

	v &= isValid(l);

	return l;
}



int main()
{
	while(cin >> str) {
		v = true;
		str += '$';
		p = 0;

		complex<int> res = expr();

		if(v == false) cout << "overflow" << endl;
		else {
			if(res.real() == 0 && res.imag() == 0) {
				cout << res.real() << endl;
			}
			else if(res.real() == 0) {
				cout << res.imag() << "i" << endl;
			}
			else if(res.imag() == 0) {
				cout << res.real() << endl;
			}
			else {
				cout << res.real() << (res.imag() > 0 ? "+" : "-") << abs(res.imag()) << "i" << endl;
			}
		}
	}
}

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

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a).size()
#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define endl "\n"

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
//K-th smallest
//cout << k << "rd smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;


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

ll mod=1000000007;

ll power(ll x, ll y) 
{
	ll temp;
	if( y == 0)
		return 1;
	temp = power(x, y/2);
	if (y%2 == 0)
		return (temp*temp)%mod;
	else
		return (((x*temp)%mod)*temp)%mod; 
}

ll dp[1005][1005];
ll h,w;
ll mat[1005][1005];

ll rec(ll i,ll j)
{
	if(i>=h || j>=w)
		return 0;
	if(i<0 || j<0)
		return 0;
	if(mat[i][j]==1)
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	dp[i][j]=(rec(i-1,j)+rec(i,j-1))%mod;
	return dp[i][j];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w;
	ll i,j;
	for(i=0;i<=1000;i++)
		for(j=0;j<=1000;j++)
			dp[i][j]=-1;
	dp[0][0]=1;
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			char c;
			cin>>c;
			if(c=='.')
				mat[i][j]=0;
			else
				mat[i][j]=1;
		}
	}
	cout<<rec(h-1,w-1)<<endl;
	return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long N,K,x;
 cin >> N >> K;
 if(N > K){
  x = N / K;
  N -= K*x;
  if(abs(N - K) < N){
   cout << abs(N - K) << endl;
  }else{
   cout << N << endl;
  }
 }else{
  if(N*2 > K){
   cout << abs(N - K) << endl;
  }else{
   cout << N << endl;
  }
 }
}

Measured memory_bytes: 3600
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,w;
    cin >> n >> w;
    pair<int,int> arr[n];
    for (int i=0;i<n;i++){
        cin >> arr[i].first >> arr[i].second;
    }
    vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));
    for (int i=1;i<=n;i++){
        for (int j=0;j<=w;j++){
            if (j - arr[i-1].first>=0){
                dp[i][j] = maxl(dp[i-1][j - arr[i-1].first] + arr[i-1].second,dp[i-1][j]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    ll ans = 0;
    for (int i=0;i<=n;i++){
        for (int j=0;j<=w;j++){
            ans = maxl(ans,dp[i][j]);
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 83032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) throws IOException {
    	Scanner s = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String[] input = reader.readLine().split(" ");
		int n = Integer.parseInt(input[0]), k = Integer.parseInt(input[1]);
		input = reader.readLine().split(" ");
		long[] a = new long[n];
		for(int i = 0; i < n; i++) {
			a[i] = Long.parseLong(input[i]);
		}
		double mul = 0;
		for(int i = 0; i < k; i++) {
			mul += Math.log(a[i]);
		}
		double prev = mul;
		for(int i = k; i < n; i++) {
			mul += Math.log(a[i]);
			mul -= Math.log(a[i - k]);
			out.println(mul > prev ? "Yes" : "No");
			prev = mul;
		}
		out.flush();
		out.close();
    }
}


Measured memory_bytes: 65020
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(input())

dp = makelist(10, 10)
for n in range(1, N+1):
    s = str(n)
    dp[int(s[-1])][int(s[0])] += 1

ans = 0
for a in range(1, 10):
    for b in range(1, 10):
        ans += dp[a][b] * dp[b][a]

print(ans)


Measured memory_bytes: 40428
/**	epsileer 03 December 2019  18:29:26  **/	
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()

int mn = INT_MAX;
vector<int> x,y,z;

void cal(int n, vector<int> &brr, vector<int> &arr, int i){
	if(i == n){
		if(x.size()>0 && y.size()>0 && z.size()>0){
			int cost = 0;
			cost += (x.size()-1)*10;
			cost += (y.size()-1)*10;
			cost += (z.size()-1)*10;
			vector<int> temp(3);
			for(int i=0;i<x.size();i++)
				temp[0] += x[i];
			for(int i=0;i<y.size();i++)
				temp[1] += y[i];
			for(int i=0;i<z.size();i++)
				temp[2] += z[i];
			cost += abs(brr[0] - temp[0]);
			cost += abs(brr[1] - temp[1]);
			cost += abs(brr[2] - temp[2]);
			mn = min(mn, cost);
		}
		return;
	}

	cal(n, brr, arr, i+1);

	x.push_back(arr[i]);
	cal(n, brr, arr, i+1);
	x.pop_back();

	y.push_back(arr[i]);
	cal(n, brr, arr, i+1);
	y.pop_back();

	z.push_back(arr[i]);
	cal(n, brr, arr, i+1);
	z.pop_back();
}

void solve(){
	int n, a, b, c; cin >> n >> a >> b >> c;
	vector<int> arr(n), brr(3);
	for(int i=0;i<n;i++) cin>>arr[i];
	brr[0] = a;
	brr[1] = b;
	brr[2] = c;
	sort(brr.begin(), brr.end());
	cal(n, brr, arr, 0);
	cout<<mn<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST; return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0; i<N; i++) cin >> d.at(i);
    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    int ans = 1;
    int m = d.at(0);
    for(int i=1; i<N; i++){
        if( m > d.at(i) ) {
            ans++;
            m = d.at(i);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3600
fun main(args: Array<String>) {
    readLine()
    val hl = readLine()!!.split(" ").map { it.toLong() }
//    val hl = "1 2 1 1 3".split(" ").map { it.toLong() }

    var curMax = 0L
    var modified = false

    hl.forEach { h ->
        val distance = h - curMax
//        println("$curMax, $h, $distance, $modified")
        if (distance <= -2L) {
            print("No")
            return
        } else if (distance == -1L) {
            if (modified) {
                print("No")
                return
            } else {
                modified = true
                curMax = h
            }
        } else if (distance >= 1L) {
            if (modified) {
                if (distance >= 2L) {
                    curMax = h
                    modified = false
                }
            } else {
                curMax = h
            }
        }
    }
    print("Yes")
}


Measured memory_bytes: 59416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N;
  cin >> A;
 
  if (A - (N % 500) >= 0){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }

}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        k: i64,
        x: i64
    }
    print!("{}", x - k + 1);
    for i in 1..2 * k - 1 {
        print!(" {}", x - k + 1 + i as i64);
    }
    println!("");
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

string S;
int w;

signed main()
{
    cin >> S >> w;
    int cnt = 0;
    string ans = "";
    REP(i, S.length()) {
        if(cnt == 0) { ans += S[i]; }
        cnt++;
        if(cnt >= w) { cnt = 0; }
    }
    printf("%s\n", ans.c_str());
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  long int k,a,b,ck=1;
  scanf("%ld%ld%ld",&k,&a,&b);
  while(k>0){
    if(b-a>2&&ck>=a&&k>=2){
      ck=ck+b-a;
      k=k-2;
    }
    else {
      ck++;
      k--;
    }
  }
  printf("%ld",ck);
  return 0;
}

Measured memory_bytes: 128
n = int(input())
arr = [int(x) for x in input().split()]
balls = {}
result = []
reslen = 0

for i in range(n, n // 2, -1):
  if arr[i - 1] == 1:
    balls[i - 1] = 1
    result.append(str(i))
    reslen += 1
  else:
    balls[i - 1] = 0

for i in range(n // 2, 0, -1):
  s = sum([balls[i * m - 1] for m in range(2, n // i + 1)])
  if arr[i - 1] == 1:
    if (s % 2) == 1:
      balls[i - 1] = 0
    else:
      balls[i - 1] = 1
      result.append(str(i))
      reslen += 1
  if arr[i - 1] == 0:
    if (s % 2) == 0:
      balls[i - 1] = 0
    else:
      balls[i - 1] = 1
      result.append(str(i))
      reslen += 1

print(reslen)
if reslen != 0:
  print(' '.join(result))


Measured memory_bytes: 38440
from sys import stdin

n = int(stdin.readline())

d = {}
for i in range(n):
    cmd = stdin.readline()
    if cmd.startswith('insert'):
        s = cmd[7:-1]
        d[s] = True
    elif cmd.startswith('find'):
        s = cmd[5:-1]
        print('yes' if s in d else 'no')


Measured memory_bytes: 33436
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define BR cout<<endl;
#define LEN(s) s.length();
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod=1000000007;

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%mod;
    }
    return res;
}

int main(){
    int n, x = 0, num = 0;
    cin >> n;
    int ans[n];
    rep(i,n)ans[i] = 0;

    string s[n], tem[n];
    rep(i,n){
        cin >> s[i];
        tem[i] = "";
    }
    sort(s, s+n);

    rep(i,n){
        if(i == 0){
            tem[0] = s[0]; 
            ans[x] += 1;
        }
        else{
        if(tem[x] == s[i]){
            ans[x] += 1;
        }
        else{
            x++;
            tem[x] = s[i];
            ans[x] += 1;
        }
        }
        chmax(num, ans[x]);
    }

   
    rep(i,n){
        if(ans[i] == num){
            cout << tem[i] << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 16848
#include <bits/stdc++.h>
#define nmax 100010

using namespace std;
int a[nmax];
bool cmp(int a,int b){
    return a>b;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i<n;++i) scanf("%d",&a[i]);
    sort(a,a+n,cmp);
    int wide = -1,len = -1;
    int now = a[0],pre = a[0];
    int pos = 1;
    int i;
    for(i = 1;i<n;++i){
        if(a[i-1] == a[i]){
            wide = a[i];
            i+=2;
            break;
        }
    }
    for(;i<n;++i){
        if(a[i-1] == a[i]){
            len = a[i];
            break;
        }
    }
    long long ans = (long long )wide * (long long )len;
    if(wide == -1 && len == -1) printf("0\n");
     else printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 640
/*May The Force Be With Me*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define MOD 1000000007
#define endl "\n"
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define pb push_back
#define f first
#define s second
#define inf INT_MAX
#define size_1d 10000000
#define size_2d 1000
#define rep(i,v,n) for(ll i = v; i < n; i++)
//Snippets: delta, sieve, fastexp, dfs, bfs, dijkstra, floodfill

using namespace std;

ll n, k;

void Input() {
	cin >> n >> k;
}

void Solve() {
	vll a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	vll dp(k + 1, 0); //if the firsst player is winning with the kth value
	for (ll i = 0; i <= k; i++) {
		for (ll it : a) {
			if (i - it >= 0)dp[i] = max(dp[i], 1 - dp[i - it]);
		}
	}
	if (dp[k])cout << "First";
	else cout << "Second";
}

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

	ll T = 1;
	//cin >> T;
	//ll t = 1;
	while (T--) {
		Input();
		//cout << "Case " << t << ": ";
		Solve();
		//t++;
	}
	return 0;
}

Measured memory_bytes: 3992
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A;

  std::cin >> N;

  std::vector<std::pair<int, int>> pairs(N);

  for (int i = 0; i < N; i ++) {
    std::cin >> pairs[i].first;

    pairs[i].second = i + 1;
  }

  std::sort(ALL(pairs));

  for (int i = 0; i < N; i ++)
    std::cout << pairs[i].second << ' ';
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 1664
eval'N,A,B='+`dd`.split*?,
A*=t=(A+B).pow -2+M=10**9+7,M
B*=t
a=A.pow N,M
b=B.pow N,M
[g=1,*(1...N).map{g=g*_1%M}].map{$.=($.+(g*_1).pow(M-2,M)*(a+b)*100*g*t=t*N%M)%M
N+=1
a=a*B%M
b=b*A%M}
p$.

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

typedef long long LL;
typedef pair<int, int> pii;

#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int maxn = 90;
const int mod = 1e9 + 7;
const int oo = 0x3f3f3f3f;

template<typename T> T read() {
	T n(0), f(1);
	char ch = getchar();
	for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
	for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

LL fib[maxn], n, m;
vector<pair<LL, LL>> pool[maxn];

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    fib[0] = fib[1] = 1;
    for(int i = 2; i < maxn; i++) fib[i] = fib[i-1] + fib[i-2];

    pool[1].eb(1, 2);
    pool[1].eb(1, 3);
    for(int i = 2; i+2 < maxn; i++) 
        for(const auto& it : pool[i-1]) 
            for(LL y = it.fst + it.snd; y <= fib[i+2]; y += it.snd) 
                pool[i].eb(it.snd, y);

    for(int q = read<int>(); q; --q) {
        n = read<LL>();
        m = read<LL>();
        if(n > m) swap(n, m);

        if(n == 1) printf("1 %lld\n", m % mod); 
        else if(n == 2 && m == 2) printf("1 4\n");
        else {
            int k = 1, ans = 0;
            while(fib[k+1] <= n && fib[k+2] <= m) ++k;
            printf("%d ", k);
            for(const auto& it : pool[k-1]) {
                if(it.snd <= n) ans = (ans + (m - it.fst) / it.snd) % mod;
                if(it.snd <= m) ans = (ans + (n - it.fst) / it.snd) % mod;
            }
            printf("%d\n", ans);
        }
    }

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n, d, cnt = 0;
    cin >> n >> d;
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        if (x*x + y*y <= d*d) cnt++;
    }
    cout << cnt << endl;
}

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

int main(){
    int mun1,mun2;
    cin>> mun1 >> mun2;
    if (mun1 >= 10 or mun2 >= 10)
    {
        cout << -1 <<endl;
    }
    else{
        cout << mun1 * mun2 <<endl;
    }
}

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

void main() {
    int[] input = readln.split.to!(int[]);
    int W = input[0];
    int H = input[1];
    int N = input[2];
    int ans = 0;
    int[] point = readln.split.to!(int[]);
    foreach(int i; 1..N) {
        int[] _point = readln.split.to!(int[]);
        int dx = _point[0]-point[0];
        int dy = _point[1]-point[1];
        if (dx*dy > 0) {
            dx = abs(dx);
            dy = abs(dy);
            ans += min(dx, dy) + abs(dx-dy);
        } else {
            ans += abs(dx)+abs(dy);
        }
        point = _point;
    }
    ans.writeln;
}

Measured memory_bytes: 2504
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = [inp() for _ in range(n)]
now = a[0]
for i in range(1,n):
    now = a[i]*now//fractions.gcd(a[i],now) 
print(now)

Measured memory_bytes: 5068