akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
#define NIL -1
//#define INFTY 1000000000000000000

LL lpow(LL x, LL n){
    LL ans = 1;
    while(n>0){
        if((n&1)==1){
            ans = (ans * x);
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}
int main(){
    LL n;
    LL m;
    cin >> n >> m;
    LL num=lpow(2,n);
    vector<LL> a(m);
    LL b;
    vector<LL> c(m);
    LL tmp_c;
    for(LL i=0; i<m; i++){
        cin >> a[i] >> b;
        LL tmp=0;
        for(LL j=0; j<b; j++){
            cin >> tmp_c;
            tmp_c--;
            tmp+=lpow(2, tmp_c);
        }
        c[i]=tmp;
    }

    vector<vector<LL>> dp(m+1, vector<LL>(num, NIL));
    for(LL i=0; i<=m; i++){
        dp[i][0]=0;
    }
    for(LL i=1; i<=m; i++){
        for(LL j=0; j<num; j++){
            if(dp[i-1][j]==NIL){
                continue;
            }
            if(dp[i][j]==NIL){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=min(dp[i][j], dp[i-1][j]);
            }
            LL tmp=c[i-1];
            LL tmp_j=j;
            LL tmp_dist=0;
            for(LL k=0; k<n; k++){
                if(tmp%2==1 || tmp_j%2==1){
                    tmp_dist=tmp_dist+lpow(2,k);
                }
                tmp/=2;
                tmp_j/=2;
            }
            if(dp[i][tmp_dist]==NIL){
                dp[i][tmp_dist]=dp[i-1][j]+a[i-1];
            }else{
                dp[i][tmp_dist]=min(dp[i][tmp_dist], dp[i-1][j]+a[i-1]);
            }
            //cout << i << " " << j << " " << tmp_dist << " " << dp[i][tmp_dist] << endl;
        }
    }

    cout << dp[m][num-1] << endl;

    return 0;
}


Measured memory_bytes: 35376
#include <iostream>
#include <string.h>

using namespace std;
bool isPrime[10005];

void PrimeCalc()
{
	memset(isPrime, 1, sizeof(isPrime));
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i < 10005; ++i)
	{
		if(isPrime[i])
		{
			for(int j = 2 * i; j < 10005; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	PrimeCalc();
	int n;
	while(cin >> n, n)
	{
		for(int i = n; i >= 5; --i)
		{
			if(isPrime[i] && isPrime[i - 2])
			{
				cout << i - 2 << " " << i << endl;
				break;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <functional>

using namespace std;

using lint = long long;
using ldouble = long double;

const vector<int> dx({-1, -1, -1, 0, 0, 1, 1, 1});
const vector<int> dy({-1, 0, 1, -1, 1, -1, 0, 1});

bool solve() {
    int h, w;
    cin >> h >> w;
    if (h == 0) return false;

    vector<string> torus(h);
    for (auto& s : torus) cin >> s;

    string ans = "0";
    set<string> app;

    function<void(int, int, int, vector<vector<bool>>&, string)> dfs =
        [&](int x, int y, int d, vector<vector<bool>>& used, string s) {
            if (used[x][y]) return;
            used[x][y] = true;

            s.push_back(torus[x][y]);
            if (s.length() > 1 && app.count(s) &&
                ((ans.length() < s.length()) ||
                 (ans.length() == s.length() && s < ans))) {
                ans = s;
            }
            app.insert(s);

            x = (x + dx[d] + h) % h;
            y = (y + dy[d] + w) % w;
            dfs(x, y, d, used, s);
        };

    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            for (int d = 0; d < 8; ++d) {
                vector<vector<bool>> used(h, vector<bool>(w, false));
                dfs(x, y, d, used, "");
            }
        }
    }

    cout << ans << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 35612
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
double dis[1007][1007];
double r[1007],x[1007],y[1007];
double ds[1007];
bool vis[1007];
int n;
queue<int > q;
void dijkstra()
{
  for(int i=1;i<=n;i++)
  ds[i]=1e10;
  ds[1]=0;
  q.push(1);
  while(q.size())
  {
   int u=q.front();
   q.pop();
   vis[u]=0;
   for(int i=1;i<=n;i++)
   {
   	 if(i==u) continue;
   	 if(ds[u]+dis[u][i]<ds[i])
   	 {
   	    ds[i]=ds[u]+dis[u][i];
   	    if(!vis[i])
   	    {
   	     q.push(i);
			vis[i]=1;	
   	    }
   	 }
   }
  }
}
int main()
{
 while(scanf("%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2])!=EOF)
 {
   memset(vis,0,sizeof(vis));
   scanf("%d",&n);
   n+=2;
   for(int i=3;i<=n;i++)
   scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
   r[1]=r[2]=0;
   for(int i=1;i<=n;i++)
   {
    for(int j=1;j<=n;j++)
    {
      	double tmp=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
      	tmp-=(r[i]+r[j]);
      	if(tmp<0)
      	dis[i][j]=0;
      	else dis[i][j]=tmp;
    }
   }
   dijkstra();
   printf("%.10lf\n",ds[2]);
 }
 return 0;	
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	int n, k;
	cin >> n >> k;
	vector <int> a(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = k + 1; i <= n; i++) {
		if (a[i] > a[i - k]) {
			cout << "Yes\n";
		}	else cout << "No\n";
	}
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

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

    if(S == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }

    ll n = S.size();
    map<char, bool> r;
    for(auto s : S){
        r[s] = true;
    }

    if(n < 26){
       for(char c = 'a'; c <= 'z'; c++){
           if(r.count(c) == 0){
               S.push_back(c);
               cout << S << endl;
               return 0;
           }
       } 
    }else{
        for(ll k = n-2; k >= 0; k--){
            char c = S[k];
            char mn = 'z' + 1;
            for(ll i = k+1; i < n; i++){
                if(S[i] > c) mn = min(S[i], mn);
            }
            if(mn < 'z' + 1){
                rep(j, 0, k) cout << S[j];
                cout << mn << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

using namespace std;
typedef long long int LL;
typedef long long int LLint;

//Faster Coding
#define ED return 0
#define GET(a) int a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << endl
#define ANS(a,b) int a;cin >> a;cout << b << endl
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())

//Difficult Syntax
#define DOUBLECHANGE(count) cout << setprecision(count)

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define ipow(x,y) LL(pow(x,y))

//Debug
#define TEST cout << "OK" << endl

const long long INF = 999999999;
const long long mod = 1000000007;

int main(){
      cin.tie(0);
      ios::sync_with_stdio(false);
      ANS(a,pow(a,3));
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <queue>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define pb push_back
#define rng(x) x.begin(),x.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;

const int INF = 1001001001;

struct Mincost {
  struct Edge{
    int to, co, lim, nxt;
    Edge(){}
    Edge(int to, int co, int lim, int nxt):to(to),co(co),lim(lim),nxt(nxt){}
  };
  int n;
  vi head, dist, pre;
  vector<Edge> e;
  Mincost(int n):n(n),head(n,-1),dist(n),pre(n){}
  void add(int f, int t, int c=0, int l=1) {
    e.pb(Edge(t,c,l,head[f])); head[f] = sz(e)-1;
    e.pb(Edge(f,-c,0,head[t])); head[t] = sz(e)-1;
  }
  void dijk(int sv) {
    fill(rng(dist),INF);
    fill(rng(pre),-1);
    priority_queue<P,vp,greater<P>> q;
    int v, d;
    q.push(P(0,sv));
    dist[sv] = 0;
    while (sz(q)) {
      d = q.top().fi; v = q.top().se; q.pop();
      if (dist[v] != d) continue;
      for (int i = head[v]; i != -1; i = e[i].nxt) {
        int u = e[i].to;
        if (e[i].lim && d+e[i].co < dist[u]) {
          dist[u] = d+e[i].co;
          pre[u] = i^1;
          q.push(P(dist[u],u));
        }
      }
    }
  }
  int solve(int sv, int tv, int flow) {
    int res = 0, f;
    while (flow>0) {
      dijk(sv);
      if (dist[tv] == INF) return -1;
      rep(i,n) for (int j = head[i]; j != -1; j = e[j].nxt) {
        e[j].co += dist[i] - dist[e[j].to];
      }
      f = flow;
      for (int i = tv; i != sv; i = e[pre[i]].to) f = min(f,e[pre[i]^1].lim);
      for (int i = tv; i != sv; i = e[pre[i]].to) {
        e[pre[i]^1].lim -= f, e[pre[i]].lim += f;
      }
      res += dist[tv]*flow;
      flow -= f;
    }
    return res;
  }
};

vvi a;

int main() {
  int n, m, k;
  scanf("%d",&n);
  scanf("%d%d",&m,&k);
  a = vvi(n,vi(m));
  string s;
  rep(i,n) {
    cin >> s;
    rep(j,m) {
      a[i][j] += s[j]-'0';
    }
  }
  rep(i,m) {
    cin >> s;
    rep(j,n) {
      a[j][i] += s[j]-'0';
    }
  }
  Mincost mc(n+m+2);
  int sv = n+m, tv = sv+1;
  rep(i,n) mc.add(sv,i);
  rep(i,m) mc.add(n+i,tv);
  rep(i,n)rep(j,m) mc.add(i,n+j,a[i][j]);
  int l = 0, r = min(n,m)+1, c;
  // rep(i,n)rep(j,m) cout<<i<<" "<<j<<" "<<a[i][j]<<endl;
  // cout<<mc.solve(sv,tv,5)<<endl;
  while (l+1<r) {
    c = (l+r)>>1;
    auto nc = mc;
    int x = nc.solve(sv,tv,c);
    if (x == -1 || x > k) r = c; else l = c;
  }
  cout<<l<<endl;
  return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, i;
	cin >> n;
	long long a[n];
	for(i = 0 ; i < n ; ++i)
		cin >> a[i];
	long long maxm = *max_element(a, a + n);
	bool flag = false;
	long long tot = 0;
	for(i = 0; i < n; ++i) {

		if(maxm == a[i] && !flag){
			flag = true;
			tot += a[i]/2;
		}
		else
			tot += a[i];
	}
	cout << tot;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  long long int N, K;
  cin >> N >> K;
  vector<long long int> w(N), d(N);
  for(int i = 0; i < N; ++i){
    cin >> w[i] >> d[i];
  }
  unsigned long long int ng = 0LL, ok = 8E18+1LL;
  while(ok-ng > 1){
    unsigned long long int m = (ok+ng)/2LL, t = 0LL;
    for(int i = 0; i < N; ++i){
      if(m >= w[i]){
        t += (m - w[i])/d[i] + 1LL;
        if(t >= K) break;
      }
    }
    if(t >= K) ok = m;
    else ng = m;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1e9 + 7

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

    int n;
    long long s = 0;

    cin >> n;

    vector<int> a(n);

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

    long long x = 0,mn = LLONG_MAX;

    for(int i = 0;i < n-1;i++)
    {
        x+=a[i];
        mn = min(mn,abs(x-(s-x)));
    }

    cout << mn;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main(){
    int n;
    string s;
    cin >> s;
    cout << (s[0] == '9' || s[1] == '9'  ? "Yes" : "No") << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
//ll dp[int(1e9)][int(1e9)];
ll temp[100][100];
int h = 0;


int main()
{
	int n;
	cin >> n;
	vector<ll> f(n);
	for (int i = 0; i < n; i++) {
		cin >> f[i];
	}
    ll temp = 0;
	ll answer = 0;
	sort(f.begin(), f.end());
	if (n % 2 == 0) {
		for (int i = 0; i < n; i++) {
			if (n / 2 > i) {
				answer -= f[i] * 2;
				//cout << f[i] << endl;
			}
			else {
				answer += f[i] * 2;
				//cout << f[i] << "!" << endl;
			}
		}
		answer = answer - f[n / 2] + f[n / 2 - 1];
	}
	else {
		for (int i = 0; i < n; i++) {
			if ((n+1) / 2 > i) {
				answer -= f[i] * 2;
				//cout << f[i] <<"a"<< endl;
			}
			else {
				answer += f[i] * 2;
				//cout << f[i] << "!" << endl;
			}

			if (n / 2 > i) {
				temp -= f[i] * 2;
				//cout << f[i] << "a" << endl;
			}
			else {
				temp += f[i] * 2;
				//cout << f[i] << "!" << endl;
			}

		}
		//cout << f[(n - 1) / 2 + 1] << " " << f[(n - 1) / 2 + 2] << endl;
		answer = answer + f[(n+1) / 2-1] + f[(n+1) / 2-2];
		temp = temp - f[(n - 1) / 2 + 1] - f[(n - 1) / 2 ];

	}

	
		cout << max(answer,temp) << endl;
}

Measured memory_bytes: 1024
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,K = map(int,input().split())

ans = 0
for b in range(K+1,N+1):
    ans += (N//b)*max(0,b-K) + max(0,N%b-K+1)
    if K==0:
        ans -= 1

print(ans)

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

int main() {
    int64_t n, ans = 0;
    cin >> n;
    for (auto a = 1; a < n; a++) {
        ans += n / a;
        if(n % a == 0) ans--;
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
#define Puts(b) cout<<(b? "Yes":"No")<<endl
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

struct SCC {
  int n;
  vector<vector<int>> Edge;
  vector<vector<int>> rEdge;
  vector<int> order;
  vector<int> group;
  vector<bool> used;

  SCC(int node) : n(node), Edge(node), rEdge(node), group(node), used(node) {}

  void add(int from, int to) {
    Edge[from].push_back(to);
    rEdge[to].push_back(from);
  }

  void dfs(int v) {
    used[v] = true;
    for(auto next : Edge[v]) {
      if(!used[next]) dfs(next);
    }
    order.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    group[v] = k;
    for(auto next : rEdge[v]) {
      if(!used[next]) rdfs(next, k);
    }
    order.push_back(v);
  }

  void scc() {
    for(int v = 0; v < n; ++v) {
      if(!used[v]) dfs(v);
    }
    used.assign(n, false);
    int k = 0;
    for(int i = order.size() - 1; i >= 0; --i) {
      int v = order[i];
      if(!used[v]) rdfs(v, k++);
    }
  }

  bool same(int a, int b) {
    return group[a] == group[b];
  }
};

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

  SCC scc(13);
  scc.add(1, 3);
  scc.add(3, 5);
  scc.add(5, 7);
  scc.add(7, 8);
  scc.add(8, 10);
  scc.add(10, 12);
  scc.add(12, 1);
  scc.add(4, 6);
  scc.add(6, 9);
  scc.add(9, 11);
  scc.add(11, 4);
  scc.add(12, 4);
  scc.add(4, 2);
  scc.scc();

  int x, y;
  cin >> x >> y;
  if(scc.same(x, y)) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll d, g; cin >> d >> g;
    vi p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];

    // ボーナス取得の組み合わせは最大2^10なので全て試す。
    // 不足分は完答していない問題の中で基本スコアが最大の問題を解いて補完する。
    ll ans = INFLL;
    for(ll bit = 0; bit<(1LL<<d); bit++){
        ll sumScore = 0;
        ll sumCnt = 0;
        vi chk(d, 0);
        for(ll m = 0; m<10; m++){
            if(bit&(1LL<<m)){
                chk[m]++;
                sumScore += (m+1)*100*p[m]+c[m];
                sumCnt += p[m];
            }
        }
        if(sumScore < g){
            for(ll m = d-1; m>=0; m--){
                if(chk[m] == 0){
                    ll addCnt = min((ll)(ceil(1.0*(g - sumScore)/((m+1)*100))), p[m]);
                    sumScore += addCnt*(m+1)*100;
                    sumCnt += addCnt;
                    break;
                }
            }
        }
        if(sumScore < g) continue;
        chmin(ans, sumCnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
 
int N,M,K;
 
#include <vector>
using namespace std;
 
struct UnionFind {
  vector<int> par_;
  vector<int> rank_;
 
  void init(int size) {
    par_.resize(size, 0);
    rank_.resize(size, 0);
    for (int i = 0; i < size; i++) {
      par_[i] = i;
      rank_[i] = 0;
    }
  }
  int root(int x) { return par_[x] == x ? x : par_[x] = root(par_[x]); }
 
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return true;
 
    if (rank_[x] < rank_[y]) {
      par_[x] = y;
    } else {
      par_[y] = x;
      if (rank_[x] == rank_[y]) rank_[x]++;
    }
    return false;
  }
  bool same(int x, int y) { return root(x) == root(y); }
};
 
vector<int> bu(101010,-1);
 
int main(){
  cin >> N >> M >> K;
  UnionFind uf;
  uf.init(N);
  rep(i,0,K - 1){
    int c,a,b;
    cin >> c >> a >> b;
    a--;
    b--;
    if(c == 1){
      int ra = uf.root(a);
      int rb = uf.root(b);
      if(ra == rb) continue;
      if((bu[ra] == -1 || bu[rb] == -1) || bu[ra] == bu[rb]){
        uf.unite(ra,rb);
        int r = uf.root(ra);
        if(bu[ra] == -1){
          bu[r] = bu[rb];
        }
        if(bu[rb] == -1){
          bu[r] = bu[ra];
        }
      }
      else{
        cout << i + 1 << endl;
        return 0;
      }
    }
    else{
      int r = uf.root(a);
      if(bu[r] == -1 || bu[r] == b){
        bu[r] = b;
      }
      else{
        cout << i + 1 << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
  return 0;
}


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

using namespace std;
using LLONG = long long;

int main()
{
    string S;
    cin >> S;
    int count = 0;
    for (const char ch : S)
    {
        if (ch == 'x') ++count;
    }
    if (count <= 7)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


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

using namespace std;

int main(){
    int N;
    vector<int> V, C;
    int sub;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> sub;
        V.push_back(sub);
    }
    for(int i = 0; i < N; i++){
        cin >> sub;
        C.push_back(sub);
    }
    
    int ans = 0;
    
    int limit = 1;
    for(int i = 0; i < N; i++){
        limit *= 2;
    }
    
    for(int i = 1; i < limit; i++){
        int X = 0, Y = 0;
        
        int x = i, index = 0;
        while(x > 0){
            if(x & 1){
                X += V[index];
                Y += C[index];
            }
            x = x >> 1;
            index++;
        }
        
        ans = max(ans, X - Y);
        // cout << i << " " << X << " " << Y << " " << endl;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N, M := uint(sc.NextInt()), sc.NextInt()
	s := make([][]int, M)
	for i := 0; i < M; i++ {
		s[i] = make([]int, N+1)
		A := sc.NextIntArray()
		for j, c := range A {
			if j == 0 {
				continue
			}
			s[i][c-1] = 1
		}
	}
	ans := 0
	p := sc.NextIntArray()
	for i := uint(0); i < 1<<N; i++ {
		q := 0
		for k := 0; k < M; k++ {
			sm := 0
			for j := uint(0); j < N; j++ {
				if (i & (1 << j)) > 0 {
					sm += s[k][j]
				}
			}
			if sm%2 == p[k] {
				q++
			}
		}
		if q == M {
			ans++
		}
	}
	fmt.Println(ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <iomanip>
#include <queue>
#include <cmath>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin>>N;
    vl A(N);
    rep(i,N)cin>>A[i];
    vl acc(N+1,0);
    rep(i,N)acc[i+1]=acc[i]+A[i];
    sort(all(acc));
    ll t=acc[0],ans=0;
    ll cnt=1;
    repe(i,1,N+1){
    	if(t==acc[i])cnt++;
    	else{
    		ans+=cnt*(cnt-1)/2;
    		cnt=1;
    		t=acc[i];
    	}
    }
    ans+=cnt*(cnt-1)/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3456
# -*- coding:utf-8 -*-
n,m = map(int,input().split())
aa = [list(map(int,input().split())) for i in range(n)]
cc = [list(map(int,input().split())) for i in range(m)]

checkpoints = []
for a in aa:
    d = float("inf")
    checkpoint = -1
    for i,c in enumerate(cc):
        tmpd = min(abs(a[0]-c[0])+abs(a[1]-c[1]),d)
        if not tmpd == d:
            checkpoint = i+1
        d = tmpd
    print(checkpoint)


Measured memory_bytes: 3316
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=998244353;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){

    int n,k;
    cin>>n>>k;
    vector<pair<int,int>> rl;
    rep(i,k){
        int l,r;
        cin>>l>>r;
        rl.push_back({l,r});
    }

    sort(rl.begin(),rl.end());
    vector<ll> dp(n+1,0);
    vector<ll> dps(n+1,0);

    dp[0]=1;
    dps[1]=1;
    for(int i=1;i<n;i++){
        for(int j=0;j<k;j++){
         int l,r;
         l=rl[j].first;
         r=rl[j].second;

         dp[i]+=dps[max(0,i-l+1)];
         dp[i]%=MOD;
         dp[i]-=dps[max(0,i-r)];
         if(dp[i]<0)dp[i]+=MOD;
         dp[i]%=MOD;

        }

        dps[i+1]+=dp[i];
        dps[i+1]%=MOD;
        dps[i+1]+=dps[i];
        dps[i+1]%=MOD;
    }


    cout<<dp[n-1]<<endl;





    
return 0;
}


Measured memory_bytes: 6372
// コメント修正して, 再提出.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL MOD = 998244353;
// Fermat's little theorem を 適用し, 大きな冪乗の計算を行う.
// a の p乗 を 計算.
// @param a: べき乗したい正整数.
// @param b: 指数.
// @return:  べき乗した計算結果(mod版).
LL mPow(LL a, LL p){
    LL res = 1;
    while(p){
        if(p & 1) res = res * a % MOD;
        a = a * a % MOD;
        p >>= 1;
    }
    return res;
}
int X[111111];

int main(){
    
    // 1. 入力情報.
    int N, d0, d;
    scanf("%d %d", &N, &d0);
    X[d0]++;
    for(int i = 1; i < N; i++){
        scanf("%d", &d);
        X[d]++;
    }
    
    // 2. 条件を満たさない場合は終了.
    if(d0 != 0){
        printf("%d\n", 0);
        return 0;
    }
    
    // 3. 条件を満たす木を数える.
    // 連続する距離(1以上)で, 小さい順に, d1, d2, d3, ... 個あったとして,
    // (d1 の d2乗) × (d2 の d3乗) × (d3 の d4乗) × ... を 計算してみる.
    // 途中, 距離が歯抜けになったら, 
    // 条件を満たしていない(確認した辺の数 e が 0 にならず, 余る)と見て終了.
    LL ans = 1, bef = 1;
    int e = N - 1;
    for(int i = 1; i < 111111; i++){
        if(X[i - 1] > 0 && X[i] > 0){
            ans *= mPow(bef, (LL)X[i]);
            ans %= MOD;
            bef = (LL)X[i];
            e -= X[i];
        }else{
            break;
        }
    }
    
    // 4. 出力.
    if(e == 0) printf("%lld\n", ans);
    else       printf("%d\n", 0);
    return 0;
    
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n, ma, mb, i, j, k;
	cin >> n >> ma >> mb;
	vi a(n), b(n), c(n);
	for (i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vii dp(401,vi(401, inf));
	dp[0][0] = 0;
	for (i = 0; i < n; i++) {
		for (j = 400-a[i]; j >= 0; j--) {
			for (k = 400-b[i]; k >= 0; k--) {
				if (dp[j][k] != inf) {
					dp[j + a[i]][k + b[i]] = min(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
				}
			}
		}
	}
	int ans = inf;
	for (i = 1; i <= 400; i++) {
		if ((i*mb) % ma != 0) {
			continue;
		}
		else if (i*mb / ma > 400) {
			break;
		}
		else {
			ans = min(ans, dp[i][i*mb / ma]);
		}
	}
	if (ans == inf) {
		cout << -1 << endl;
		return 0;
	}
	else {
		cout << ans << endl;
		return 0;
	}
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Around Square
            int N = int.Parse(Console.ReadLine());
            long pow = 0;
            
            for(int i = 0; i < N; i++)
            {
                pow = (long)Math.Pow(i + 1, 2);

                if (pow > N)
                {
                    pow = (long)Math.Pow(i, 2);
                    break;
                }
            }

            Console.WriteLine(pow);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
using namespace std;
int a,b;
int main(){
cin>>a>>b;
int x=0;
for(int i=a;i<b+1;i++)
{
if(i<0)x++;
if(i==0)
{
cout << "Zero";
return 0;
}}
if(x%2==0)
cout << "Positive";
else
cout << "Negative";
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-8;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
	ll K;
	cin >> K;
	vector<vector<ll>> ans;
	ll N;
	if (K <= 500) {
		N = K;
		ans = vector<vector<ll>>(N, vector<ll>(N));
		for (int y = 0;y < N;y++) {
			for (int x = 0;x < N;x++) {
				ans[y][x] = y;
			}
		}
	}
	else {
		N = (K + 1) / 2;
		if (N % 2)
			N++;
		ans = vector<vector<ll>>(N, vector<ll>(N));
		for (int y = 0;y < N;y++) {
			for (int x = 0;x < N;x++) {
				if (y % 2)
					ans[y][x] = N + (x + y) % N;
				else
					ans[y][x] = (x + y) % N;
			}
		}
		for (int y = 0;y < N;y++) {
			for (int x = 0;x < N;x++) {
				if (ans[y][x] >= K) {
					ans[y][x] -= N;
				}
			}
		}
	}
	cout << N << endl;
	for (int y = 0;y < N;y++) {
		for (int x = 0;x < N;x++) {
			cout << ans[y][x] + 1;
			if (x == N - 1)
				cout << endl;
			else
				cout << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 3200
def add(n):
    return n + 1

if __name__ == "__main__":
    n = int(input())
    buf = input().split()
    a = [int(s) for s in buf]
    
    boxes = [0] * n

    for i in reversed(range(n)):
        pick_boxes = boxes[i::i+1]
        pick_boxes.pop(0)
        if pick_boxes:
            if (sum(pick_boxes) % 2) == a[i]:
                boxes[i] = 0
            else:
                boxes[i] = 1
        else:
            boxes[i] = a[i]

    box_name = [i for i, x in enumerate(boxes) if x == 1]
    box_name = list(map(add, box_name))
    print(len(box_name))
    if len(box_name) != 0:
        box_name = ' '.join(map(str,box_name))
        print(box_name)


Measured memory_bytes: 23332
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007;

void solve()
{
  int n; cin >> n;
  string s;
  cin >> s;
  int bra = 0;
  int ket = 0;
  int cnt_bra;
  int cnt_ket;
  for(int i = 0; i < n; ++i){
    if(s[i] == ')'){
      cnt_bra = 0;
      cnt_ket = 1;
      int flag = 0;
      for(int j = i-1;j >= 0; j--){
        if(s[j] == '(')cnt_bra++;
        else cnt_ket++;
        if(cnt_bra == cnt_ket){
          flag = 1;
          break;
        }
      }
      if(!flag) bra++;
    } else {
      cnt_bra= 1;
      cnt_ket = 0;
      int flag2 = 0;
      for(int j = i+1;j < n; ++j){
        if(s[j] == ')')cnt_ket++;
        else cnt_bra++;
        if(cnt_bra == cnt_ket){
          flag2 = 1;
          break;
        }
      }
      if(!flag2) ket++;
    }
  }
  string ans;
  for(int i = 0; i < bra; i ++) {
    char b = '(';
    ans += b;
  }
  ans += s;
  for(int i = 0; i < ket; i ++) {
    char k = ')';
    ans += k;
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;

namespace ABC061B
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int N = int.Parse(target[0]);
            int M = int.Parse(target[1]);
            int[,] r = new int[N,N];
            for(int i=0;i<N;i++)
                for(int j=0;j<N;j++)
                    r[i,j] = 0;
            for(int i=0;i<M;i++){
                target = Console.ReadLine().Split(' ');
                int a = int.Parse(target[0])-1;
                int b = int.Parse(target[1])-1;
                r[a,b]++;
                r[b,a]++;
            }
            for(int i=0;i<N;i++){
                int count = 0;
                for(int j=0;j<N;j++){
                    if(r[i,j] > 0) count+=r[i,j];
                }
                Console.WriteLine(count);
            }
        }
    }
}


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

int main() {
  int h,w,hi,wi; cin>>h>>w>>hi>>wi;
  cout<<(h-hi)*(w-wi)<<endl;

}


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

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

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

signed main(void)
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);

    while(true){
        int N;
        cin>>N;
        if(N==0) return 0;
        vector<int> V(N);
        for(int i=0;i<N;i++) cin>>V[i];
        sort(V.begin(),V.end());
        int sum=0;
        for(int i=1;i<N-1;i++) sum+=V[i];
        cout<<sum/(N-2)<<endl;
    }
}



Measured memory_bytes: 3048
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 1e5+5;
const dd eps = 1e-8;
const int mod = 1e9+7;

ll a,b,n;

ll cal(ll x){
  return ((a*x)/b) - a*(x/b);
}

int main(){
  ios::sync_with_stdio(false);
  // freopen("input.txt","r",stdin);
  cin>>a>>b>>n;
  if(b > n){
    cout<<cal(n)<<endl;
  }
  else cout<<cal(b-1)<<endl;
  return 0;
}


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

int main(){
    stack<char> st;
    char c;
    while(cin >> c){
        if(st.empty()){
            st.push(c);
        }else if( c == 'T' && st.top() == 'S' ){
            st.pop();
        }else{
            st.push(c);
        }
    }
    
    cout << st.size() << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++){ ;
int main() {
    string A,B,C;
    cin>>A>>B>>C;
    char p=A.at(0);
    char r=B.at(0);
    char q=C.at(0);
   p=toupper(p);
    q=toupper(q);
    r=toupper(r);
    cout<<p<<r<<q<<endl;
}

Measured memory_bytes: 3600
n = int(input())

evi_all = []
for _ in range(n):
    evi = []
    for _ in range(int(input())):
        x, y = map(int, input().split())
        evi.append((x - 1, y))
    evi_all.append(evi)

ans = 0
for mask in range(2 ** n):
    flg = True
    for bit in range(n):
        if (mask >> bit) & 1:
            for x, y in evi_all[bit]:
                if (y == 1 and (mask >> x & 1) == 0) or (y == 0 and (mask >> x & 1) == 1):
                    flg = False

    if flg:
        cnt = 0
        for bit_2 in range(n):
            if (mask >> bit_2) & 1:
                cnt += 1
        ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cstring> 
using namespace std;
int main()
{
	char s[4];
	int i;
	cin>>s;
	int a=0,b=0;
	for(i=0;i<3;i++)
	{
		if(s[i]=='A')
		a=1;
		if(s[i]=='B')
		b=1;
	}
	if(a==1&&b==1)
	cout<<"Yes";
	else
	cout<<"No";
	
}

Measured memory_bytes: 256
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())


using namespace std;


int h,w,d,n;
char t[50][50];
int r[10+1];
int x[50],y[50],s[50];


int c[50][50];

bool in(int y,int x){return 0<=x&&x<w&&0<=y&&y<h;}
bool in(int cy,int cx,int r,int y,int x){return abs(cy-y)<=r&&abs(cx-x)<=r;}



bool v[50][50];
void bfs(){
	int dy[]={0,1,0,-1};
	int dx[]={1,0,-1,0};
	pair<int,int> p;
	rep(i,h)rep(j,w)if(t[i][j]=='D'){
		p=make_pair(i,j);
	}
	v[p.first][p.second]=true;
	queue<pair<int,int> > q;
	q.push(p);
	while(!q.empty()){
		p=q.front();
		q.pop();
		rep(i,4){
			int ny=p.first+dy[i],nx=p.second+dx[i];
			if(in(ny,nx)&&t[ny][nx]!='#'&&!v[ny][nx]){
				q.push(make_pair(ny,nx));
				v[ny][nx]=true;
			}
		}
	}
}

string solve(){
	r[d]=50;
	rep(i,n){
		rep(j,h)rep(k,w){
			if(t[j][k]!='#' && in(y[i],x[i],r[s[i]],j,k) && !in(y[i],x[i],s[i]==0?-1:r[s[i]-1],j,k)){
				c[j][k]++;
			}
		}
	}
	bool f=false;
	rep(i,h)rep(j,w)if(c[i][j]==n)f=true;
	if(!f)return "Broken";
	bfs();
	bool a=false,b=false;
	rep(i,h){
		rep(j,w){
			if(c[i][j]<n)continue;
			if(v[i][j])a=true;
			else b=true;
		}
	}
	if(a&&b)return "Unknown";
	if(a)return "Yes";
	return "No";
}

int main(){
	cin>>h>>w>>d>>n;
	rep(i,h)rep(j,w)cin>>t[i][j];
	rep(i,d)cin>>r[i];
	rep(i,n)cin>>x[i]>>y[i]>>s[i];
	cout<<solve()<<endl;

	return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>
long long N[400010],L[400010],T;
long long  hyouka(long long a,long long b){return a+b;}
void lsset(int n,int *d){
  int i;
  for(T=1;T<n;T*=2);
  for(i=0;i<T;i++)N[T+i]=i<n?d[i]:0;
  for(i=T-1;i;i--)N[i]=hyouka(N[i*2],N[i*2+1]);
}
void lasy(int i,int l,int r){
  if(L[i]==0)return;
  N[i]+=L[i]*(r-l);
  if(r-l>1){
    L[i*2  ]+=L[i];
    L[i*2+1]+=L[i];
  }
  L[i]=0;
}
void lsadd(int a,int b,int c,int i,int l,int r){//printf("%d %d %d\n",i,l,r);
  lasy(i,l,r);
  if(r<=a||b<=l)return;
  if(a<=l&&r<=b){
    L[i]+=c;
    lasy(i,l,r);
  }
  else{
    lsadd(a,b,c,i*2  ,l,(l+r)/2);
    lsadd(a,b,c,i*2+1,(l+r)/2,r);
    N[i]=hyouka(N[i*2],N[i*2+1]);
  }
}
long long lsget(int a,int b,int i,int l,int r){
  lasy(i,l,r);
  if(b<=l||r<=a)return 0;
  if(a<=l&&r<=b)return N[i];
  return hyouka(lsget(a,b,i*2,l,(l+r)/2),lsget(a,b,i*2+1,(l+r)/2,r));
}
int main(){
  int n,m,i,a,b,c,q,d[100010]={};
  scanf("%d %d",&n,&m);
  lsset(n,d);
  for(i=0;i<m;i++){
    scanf("%d %d %d",&q,&a,&b);
    if(q)printf("%lld\n",lsget(a-1,b,1,0,T));
    else{
      scanf("%d",&c);
      lsadd(a-1,b,c,1,0,T);
    }
  }
  return 0;
}

Measured memory_bytes: 7136
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp11
{
    class MainClass
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(x=>int.Parse(x)-1).ToArray();
            Console.WriteLine(A.Sum());

        }
    }
}


Measured memory_bytes: 13424
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

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

int main() {
    int N;
    cin >> N;
    vector<P> data;
    for (int i=0;i<N;i++){
        int A;
        cin >> A;
        data.push_back(P(A,i+1));
    }
    sort(data.begin(),data.end());
    for (int i=0;i<N;i++){
        if (i < N - 1) cout << data[i].second << " ";
        else cout << data[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 1780
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        sc.close();

        int wa = 0;
        int work = n;

        while (work != 0) {
            wa += work % 10;
            work /= 10;
        }

        if (n % wa == 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

bool can(int N, const vector<long long> &A, const vector<long long> &F, long long K, long long m)
{
	for (int i = 0; i < N; ++i) {
		auto x = m / F[i];
		auto c = max(0LL, A[i] - x);
		if (K < c) {
			return false;
		}
		K -= c;
	}
	return true;
}

int main()
{
	int N;
	long long K;
	cin >> N >> K;
	vector<long long> A(N), F(N);

	for (auto &x : A) {
		cin >> x;
	}
	for (auto &x : F) {
		cin >> x;
	}

	sort(A.begin(), A.end());
	sort(F.rbegin(), F.rend());

	auto T = accumulate(A.begin(), A.end(), 0LL);

	long long l = -1;
	long long u = 1LL << 60;

	while (l + 1 < u) {
		auto m = (l + u) / 2;
		if (can(N, A, F, K, m)) {
			//cout << "can " << m << endl;
			u = m;
		}
		else {
			//cout << "cannot " << m << endl;
			l = m;
		}
	}
	cout << u << endl;
}


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

# from numba import njit
import sys
sys.setrecursionlimit(10**9)
# input = stdin.readline

INF = 10**9

# @njit
def solve(n):
  s = 0
  l = []
  for i in range(n):
    s += i+1
    l += [i+1]
    if s > n:
      l.remove(s-n)
      return l
    elif s == n:
      return l

  return -1



def main():
  N = int(input())
  # N,M = map(int,input().split())
  # a = list(map(int,input().split()))
  print(*solve(N),sep="\n")
  return

if __name__ == '__main__':
  main()


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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007

void solve()
{	
	ll n,ans=0;
	cin>>n;
	map<ll,ll> mp1,mp2;
	for(ll i=1;i<=n;i++)
	{
		ll x;
		cin>>x;
		mp1[x+i]++;
		mp2[i-x]++;
	}
	for(auto it:mp1)
	{
		ll t1=it.second;
		ll t2=mp2[it.first];
		ans+=t1*t2;
	}
	cout<<ans;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}


Measured memory_bytes: 37756
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long gcd(long x, long y) => y == 0 ? x : gcd(y, x % y);

        static void Main(string[] args)
        {
            var ns = Sarray();
            WriteLine(gcd(ns[0], ns[1]));
        }
    }
}


Measured memory_bytes: 18464
a, b, x = gets.split(' ').map(&:to_f)

pi = Math::PI

#半分以上の場合
if (a*b)/2 < (x/a)
  y = 2.0 * (b - (x/(a**2)))
  ans = 90.to_f - Math.atan2(a, y) * 180.to_f / pi
  puts ans
else
  y = (2.0 * x/a) / b
  ans = 90.to_f - Math.atan2(y, b) * 180.to_f / pi
  puts ans
end

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
char* bus="0123456789543210123456789";
char s[25], t[25];
int main()
{
    int n; scanf("%d", &n);
    while (n--) {
        int a, b; scanf("%d%d", &a, &b);
        int k = 0;
        for (int i = 0; i < 15; ++i)
            if (bus[i] == a + '0') k = i;
        int j = 0;
        for (int i = k; i < strlen(bus); ++i) {
            s[j++] = bus[i];
            s[j++] = ' ';
            if (bus[i] == b + '0') break;
        }
        if (s[j-2] != b + '0') for (j = 0; j < 25; ++j) s[j] = 'x';
        s[j-1] = '\0';

        k = 0;
        for (int i = 0; i < 15; ++i)
            if (bus[i] == a + '0') { k = i; break; }
        j = 0;
        for (int i = k; i < strlen(bus); ++i) {
            t[j++] = bus[i];
            t[j++] = ' ';
            if (bus[i] == b + '0') break;
        }
        if (t[j-2] != b + '0') for (j = 0; j < 25; ++j) t[j] = 'x';
        t[j-1] = '\0';
        puts(strlen(s) < strlen(t) ? s : t);
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int n, m, i, a, ans = 0, b = 0;
	string s;
	cin >> n >> m;
	vector<int> ac(n + 1, 0), wa(n + 1, 0);
	rep(i, m) {
		cin >> a >> s;
		if (ac[a])
			continue;
		if (s == "AC")
			ac[a] = 1;
		else
			wa[a]++;
	}
	rep(i, n + 1) {
		if (ac[i]) {
			ans++;
			b += wa[i];
		}
	}
	cout << ans << " " << b << "\n";
	return 0;
}

Measured memory_bytes: 1024