akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

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

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll

const int N = 2005;
const int INF = 1e9 + 5;

int n, m, q, up[N][N], lf[N][N], cnt[N][N];
char a[N][N];

int SumCnt(int x1, int y1, int x2, int y2) {
	return cnt[x2][y2] - cnt[x2][y1 - 1] - cnt[x1 - 1][y2] + cnt[x1 - 1][y1 - 1];
}

int SumUp(int x1, int y1, int x2, int y2) {
	++x1;
	if(x1 > x2) return 0;
	return up[x2][y2] - up[x2][y1 - 1] - up[x1 - 1][y2] + up[x1 - 1][y1 - 1];
}

int SumLeft(int x1, int y1, int x2, int y2) {
	++y1;
	if(y1 > y2) return 0;
	return lf[x2][y2] - lf[x2][y1 - 1] - lf[x1 - 1][y2] + lf[x1 - 1][y1 - 1];
}

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m >> q;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> a[i][j];
		}
	}
	for(int i = 2; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			up[i][j] = up[i][j - 1] + up[i - 1][j] - up[i - 1][j - 1];
			if(a[i][j] == '1' && a[i - 1][j] == a[i][j]) {
				++up[i][j];
			}
		}
	}
	for(int i = 1; i <= n; ++i) {
		for(int j = 2; j <= m; ++j) {
			lf[i][j] = lf[i][j - 1] + lf[i - 1][j] - lf[i - 1][j - 1];
			if(a[i][j] == '1' && a[i][j - 1] == a[i][j]) {
				++lf[i][j];
			}
		}
	}
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cnt[i][j] = cnt[i][j - 1] + cnt[i - 1][j] - cnt[i - 1][j - 1];
			if(a[i][j] == '1') {
				++cnt[i][j];
			}
		}
	}
	for(int i = 1; i <= q; ++i) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		cout << SumCnt(x1, y1, x2, y2) - SumLeft(x1, y1, x2, y2) - SumUp(x1, y1, x2, y2) <<'\n'; 
	}
	return 0;
}
/*
	If you only do what you can do, 
	You will never be more than you are now!
*/

Measured memory_bytes: 52864
#include <stdio.h>

int main(void){
  long long N, A, B;
  scanf("%lld%lld%lld", &N, &A, &B);

  if(A > B || (N == 1 && A != B)) printf("0\n");
  else if(N == 1 && A == B) printf("1\n");
  else printf("%lld\n", (B*(N-1)+A+1)-(A*(N-1)+B));

  return 0;
}

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

int main(){
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> l(Q), r(Q);
  for(int i = 0; i < Q; i++){
    cin >> l[i] >> r[i];
  }
  
  vector<int> v(N);
  int now = 0;
  for(int i = 1; i < N; i++){
    if(S[i-1] == 'A' && S[i] == 'C'){
      now++;
      v[i] = now;
    }else{
      v[i] = v[i - 1];
    }
  }
  
  for(int i = 0; i < Q; i++){
    cout << v[r[i] - 1] - v[l[i] - 1] << endl;
  }
  
  
  
  return 0;
}

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


int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] * a[1] / 2<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    //%d 整数　%f 浮動小数　s% 文字列 %c もじ
    // atoi(): s->i 
    // atof(): i->s include <stdlib>
    // scanf():入力
    //strlen():文字列の長さを返す include <string.h>
    int a, b;
    scanf("%d",&a);
    scanf("%d",&b);
    printf("%d\n", b%a==0 ? a+b:b-a );

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if (a <= b && a <= c){
        cout << a << " ";
        if (c <= b)
            cout << c << " " << b << "\n";
        else cout << b << " " << c << "\n";
    } else if (b <= a && b <= c){
        cout << b << " ";
        if (a >= c)
            cout << c << " " << a << "\n";
        else cout << a << " " << c << "\n";
    } else if (c <= b && c <= a){
        cout << c << " ";
        if (a >= b)
            cout << b << " " << a << "\n";
        else cout << a << " " << b << "\n";
    }
    return 0;
}


Measured memory_bytes: 3100
rate = int(input())

if rate < 600:
    print(8)
elif rate < 800:
    print(7)
elif rate < 1000:
    print(6)
elif rate < 1200:
    print(5)
elif rate < 1400:
    print(4)
elif rate < 1600:
    print(3)
elif rate < 1800:
    print(2)
else:
    print(1)


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

int N, A, B, used[100], rings[100], G[100][199];
 
int rec(int pos)
{
    used[pos] = 1; int ret = 1;
     
    for(int i = 0; i < rings[pos]; i++)
    {
        if(!used[G[pos][i]])
        {
            ret = max(ret, rec(G[pos][i]) + 1);
        }
    }
     
    used[pos] = 0;
     
    return ret;
}
 
int main()
{
    int N, A, B;
     
    while(true)
    {
        scanf("%d", &N);
         
        if(N == 0) { break; }
 
        for(int i = 0; i < 100; i++)
        {
            used[i] = rings[i] = 0;
        }
     
        for(int i = 0; i < N; i++)
        {
            scanf("%d", &A); A--;
            scanf("%d", &B); B--;
         
            G[A][rings[A]] = B; rings[A]++;
            G[B][rings[B]] = A; rings[B]++;
        }

        int nodes = 0;
         
        for(int i = 0; i < 100; i++)
        {
            if(rings[i])
            {
                nodes++;
            }
        }
     
        int ret = 0;
     
        for(int i = 0; i < 100; i++)
        {
            ret = max(ret, rec(i));
                 
            if(ret == nodes) { break; }
        }
         
        printf("%d\n", ret);
    }
     
    return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n+2];
  for(int i=0;i<n-1;i++){
    cin>>a[i];
  }
  int sum=0;
  sum=sum+a[0];
  int last=a[0];
  for(int i=1;i<n-1;i++){
    if(last>a[i]){
      sum=sum+a[i];
    }
    if(last<=a[i]){
      sum=sum+last;
    }
    last=a[i];
  }
  cout<<sum+a[n-2]<<endl;
  return 0;
}
    


Measured memory_bytes: 256
H, W = map(int, input().split())
s = (H*W)/3
counth = 0
while counth<s:
  counth += W
if abs(counth-s) > abs(counth-s-W):
  counth -= W
Mhs = counth
counth = counth//W
H1 = H-counth
ls = [Mhs, H1*(W//2), H*W-Mhs-H1*(W//2)]
#print(ls)
ansh = [max(ls)-min(ls)]
ls = [Mhs, W*(H1//2), H*W-Mhs-W*(H1//2)]
#print(ls)
ansh += [max(ls)-min(ls)]
ansh = min(ansh)
countw = 0
while countw<s:
  countw += H
if abs(countw-s) > abs(countw-s-H):
  countw -= H
Mws = countw
countw = countw//H
W1 = W-countw
ls = [Mws, W1*(H//2), H*W-Mws-W1*(H//2)]
#print(ls)
answ = [max(ls)-min(ls)]
ls = [Mws, H*(W1//2), H*W-H*(W1//2)-Mws]
answ += [max(ls)-min(ls)]
#print(ls)
answ = min(answ)
print(min(ansh, answ))


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

using namespace std;

bool isPrime(int n) {
  bool prime = 1;
  for(int d = 2; d * d <= n; ++d) {
    if(n % d == 0) {
      prime = 0;
      break;
    }
  }
  prime = n == 2 ? 1 : prime;
  return prime;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n; cin >> n;
  int ans;
  for(int i = 2; ; ++i) {
    if(i >= n and isPrime(i)) {
      ans = i;
      break;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int N,M;
	cin >> N >> M;
	set<int> atoc, ctob;
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		if (a == 1)atoc.insert(b);
		if (b == N)ctob.insert(a);
	}
	for (auto itr = atoc.begin(); itr != atoc.end(); itr++) {
		if (ctob.find(*itr) != ctob.end()) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 9600
//header files

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n,flag=0,d1,d2,i=0,count=0;
	cin>>n;
	while(i<n)
	{
		cin>>d1>>d2;
		if(d1==d2)
			count++;
		else 
			count = 0;
		if (count >= 3)
			flag = 1;

		i++;
	}
	if (flag == 1)
		cout<<"Yes";
	else
		cout<<"No";

	return 0;
}

Measured memory_bytes: 3628
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int
#define ld long double

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10
#define PI acos(-1LL)

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int n;
	cin>>n;

	vector<int>a(n);

	multiset<int>s;

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

	int cnt=0;

	for(i=0;i<n;i++)
	{
		auto it=s.lower_bound(a[i]);
		if(it==s.begin())
		{
			cnt++;
		}
		s.insert(a[i]);
	}
	cout<<cnt<<endl;



}

Measured memory_bytes: 14256
#include<cstdio>
typedef unsigned long long ull;
const int MaxN=405,MaxM=100005;
int N,M,x[MaxM],y[MaxM];
ull g[MaxN][MaxN/64+1],del[MaxN/64+1],v[MaxN][MaxN/64+1];
int main(){
	scanf("%d%d",&N,&M);
	for(int i=0;i<M;i++)scanf("%d%d",x+i,y+i),--x[i],--y[i];
	for(int i=0;i<N;i++)g[i][i>>6]|=1ull<<(i&63);
	for(int i=M;i--;){
		ull*gx=g[x[i]],*gy=g[y[i]];
		for(int j=0;j<<6<N;j++){
			del[j]|=gx[j]&gy[j];
			gx[j]=gy[j]=gx[j]|gy[j];
		}
	}
	int cnt=0,ans=0;
	for(int i=0;i<N;i++)if(!(del[i>>6]>>(i&63)&1)){
		for(int j=0;j<N;j++)if(g[j][i>>6]>>(i&63)&1)v[cnt][j>>6]|=1ull<<(j&63);
		for(int j=0;j<cnt;j++){
			bool fl=1;
			for(int k=0;k<<6<N&&fl;k++)if(v[j][k]&v[cnt][k])fl=0;
			if(fl)ans++;
		}
		cnt++;
	}
	printf("%d\n",ans);
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N; cin >> N;
    string s; cin >> s;

    int sheep[2] = {1, -1};
    REP(i, 2)
    {
        REP(j, 2)
        {
            vi v(N, 0);
            v[0] = sheep[i];
            v[N-1] = sheep[j];

            bool ok = true;

            REP(k, N)
            {
                int pre = (k-1+N) % N, suc = (k+1) % N;
                int next = v[pre];
                if((v[k] == 1 && s[k] == 'x') || (v[k] == -1 && s[k] == 'o')) next *= -1;
                if(v[suc] != 0 && v[suc] != next) ok = false;
                v[suc] = next;
            }

            if(ok)
            {
                REP(k, N)
                {
                    if(v[k] == 1) cout << 'S';
                    else cout << 'W';
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

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

typedef long long int llint;

int n, m;
int i, j;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<int> edge[51];
bool done[51];

int dfs(int now, int enode, int from);

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

  int a, b;
  
  for(i = 0; i < m; i++) {
    cin>> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  int cnt = 0;
  
  for(i = 1; i <= n; i++) {
    for(j = 0; j < edge[i].size(); j++) {
      
      fill(done, done + n + 1, false);
      int tmp = edge[i][j];
      edge[i][j] = 0;
      cnt += dfs(i, tmp, 0);
      edge[i][j] = tmp;
      
    }
  }

  cout<< m  - cnt / 2 <<endl;
  
  return 0;
}

int dfs(int now, int enode, int from)
{
  if(now == enode)      return 1;
  if(done[now] || !now) return 0;
  
  done[now] = true;
  int rec = 0;
  
  for(int i = 0; i < edge[now].size() && !rec; i++) {
    rec += dfs(edge[now][i], enode, now);
  }

  return rec;
}


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

int main()
{
  int n, m;
  cin >> n >> m;
  
  vector<int> div(0);
  for(int i = 1; i*i <= m; i++)
    if(m%i == 0)
      div.emplace_back(i), div.emplace_back(m/i);
  sort(div.begin(), div.end());
  
  int res = 0;
  for(auto x : div)
    if(m/x >= n) res = x;
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    S1 = S()
    T = S()

    ans = float("inf")

    for i in range(0, len(S1)):

        count = 0
        for j in range(len(T)):
            s = S1[i+j]
            t = T[j]
            if s != t:
                count += 1
        ans = min(ans, count)
        if i == len(S1)-len(T):
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9748
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef float fl;
typedef long long ll;
#define chmax(x,y) x = max(x,y)

typedef pair<int,int> P;
int dp[3005][3005];

// 食べ切れる条件を考える、最大の時間がかかるものを固定する
int main(){
    int n, t; cin >> n >> t;
    vector<P> p(n);
    rep(i,n) cin >> p[i].first >> p[i].second;
    sort(p.begin(),p.end());
    int ans = 0;
    rep(i,n) {
        rep(j,t) {
            chmax(dp[i+1][j], dp[i][j]);
            int nj = j + p[i].first;
            if (nj < t) chmax(dp[i+1][nj], dp[i][j]+p[i].second);
        }
        int now = dp[i][t - 1] + p[i].second;
        chmax(ans,now);
    }
    cout << ans << endl;
    return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int H[100010];

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

	int N, K;

	cin >> N >> K;
	K--;
	rep(i, 0, N)
	{
		cin >> H[i];
	}

	sort(H, H + N);

	int ans = INF;
	int t = 0;
	int l = 0;
	int r = 0;
	rep(r, 0, N)
	{
		while (r - l > K)
		{
			l++;
		}
		if (r - l == K)
		{
			chmin(ans, H[r] - H[l]);
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
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; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vector<vpll> path; vs S;

int main() {
	cin >> H >> W >> M;
	vl A(H),B(W);
	multiset<ll> S;
	vll C(H);
	for (i = 0; i < M; i++) {
		ll h, w;
		cin >> h >> w;
		h--; w--;
		A[h]++;
		B[w]++;
		C[h].push_back(w);
	}
	//debug(A, B);
	for (i = 0; i < W; i++) {
		S.insert(B[i]);
	}
	for (i = 0; i < H; i++) {
		vl P = C[i];
		for (j = 0; j < P.size(); j++) {
			S.erase(S.lower_bound(B[P[j]]));
			S.insert(B[P[j]]-1);
		}
		//debug(*S.rbegin());
		ans = max(ans, *S.rbegin() + A[i]);
		//元も戻す
		for (j = 0; j < P.size(); j++) {
			S.erase(S.lower_bound(B[P[j]]-1));
			S.insert(B[P[j]]);
		}
		
	}
	co(ans);
}







Measured memory_bytes: 38364
import java.util.Scanner;

class Main {

    static int gcd(int x, int y) {
        if (y == 0) {
            return x;
        } else {
            return gcd(y, x % y);
        }
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int C = sc.nextInt();
        int WH = gcd(W, H);
       
        
        int a = (W/WH)*(H/WH);
        
        System.out.println(a*C);
    }
}


Measured memory_bytes: 26320
def main():
    s = input()
    m = len(s)//2
    ans = 0
    if len(s)%2 == 0:
        a = s[:m]
        b = s[m:]
        for i in range(m):
            if b[i] != a[m-i-1]:
                ans += 1
        print(ans)
    else:
        a = s[:m]
        b = s[m+1:]
        for i in range(m):
            if b[i] != a[m-i-1]:
                ans += 1
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
s=input()
n=len(s)
mod=10**9+7
dp=[[0]*13 for i in range(n+1)] # dp[i][j]:i番目までで j mod 13.
dp[0][0]=1
for i in range(1,n+1):
  for j in range(13):
    if s[i-1]=='?':
      for k in range(10):
        dp[i][(j*10+k)%13]+=dp[i-1][j]
        dp[i][(j*10+k)%13]%=mod
    else:
      dp[i][(j*10+int(s[i-1]))%13]+=dp[i-1][j]
      dp[i][(j*10+int(s[i-1]))%13]%=mod
print(dp[n][5])

Measured memory_bytes: 61916
import Control.Monad
import Data.List
main = map read . words <$> getLine >>= \[n, k] -> replicateM n (map read . words <$> getLine) >>= print . fst . head . dropWhile ((<k) . snd) . scanl (\(_, x) (t, y) -> (t, x+y)) (0, 0) . sort . map (\[a, b] -> (a, b))

Measured memory_bytes: 96636
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

int main() {
	int a,b,c,d,e,f;
	int R;
	int T;
	string str;
	int M1,M2,M3,M4,M5,M6;
	cin>>a>>b>>c>>d>>e>>f;
	M1=a,M2=b,M3=c,M4=d,M5=e,M6=f;
	cin>>str;
	for (int j=0;j<str.size();j++){
		if(str[j]=='S')T=M6,M6=M2,M2=M1,M1=M5,M5=T;
		if(str[j]=='N')T=M1,M1=M2,M2=M6,M6=M5,M5=T;
		if(str[j]=='E')T=M3,M3=M1,M1=M4,M4=M6,M6=T;
		if(str[j]=='W')T=M1,M1=M3,M3=M6,M6=M4,M4=T;

	}
	R=M1;
	cout<<R<<endl;

	return 0;
}

Measured memory_bytes: 3188
n = int(input())
l = [input() for i in range(n)]
a = 0
b = 0
ba = 0
ab = 0
for i in range(n):
    if 'AB' in l[i]:
        for j in range(len(l[i])-1):
            if l[i][j] == 'A' and l[i][j+1] == 'B':
                ab += 1
    if l[i][0] =='B' and l[i][-1] == 'A':
        ba += 1
    elif l[i][-1] == 'A':
        a += 1
    elif l[i][0] == 'B':
        b += 1
if max(a,b) == 0 and ba <= 1:
    print(ab)
elif max(a,b) == 0:
    print(ab+ba-1)
else:
    print(min(a,b)+ab+ba)

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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; ++i) cin >> b[i];
  
  vector<vector<bool>> C(3, vector<bool>(3, false));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (A[j][k] == b[i]) C[j][k] = true;
      }
    }
  }
  
  bool ans = false;
  if (C[0][0] && C[0][1] && C[0][2]) ans = true;
  if (C[1][0] && C[1][1] && C[1][2]) ans = true;
  if (C[2][0] && C[2][1] && C[2][2]) ans = true;
  if (C[0][0] && C[1][0] && C[2][0]) ans = true;
  if (C[0][1] && C[1][1] && C[2][1]) ans = true;
  if (C[0][2] && C[1][2] && C[2][2]) ans = true;
  if (C[0][0] && C[1][1] && C[2][2]) ans = true;
  if (C[0][2] && C[1][1] && C[2][0]) ans = true;
  
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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


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

struct edge {int to; ll cost; };

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

ll GCD(ll a, ll b){
  if(b==0) return a;
  else return GCD(b, a%b);
}

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}

int main(){
  int h, w;
  cin >> h >> w;
  int sx, sy;
  cin >> sx >> sy;
  int gx, gy;
  cin >> gx >> gy;
  sx--; sy--; gx--; gy--;
  vector<vector<int>> m(h, vector<int>(w, -1));
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      char c;
      cin >> c;
      if(c == '#') m[i][j] = -2;
    }
  }
  m[sx][sy] = 0;
  queue<P> que, que2;
  que.push(make_pair(sx, sy));
  while(!que.empty()){
    P p = que.front();
    que.pop();
    int x = p.first;
    int y = p.second;
    bool isblock = false;
    for(int i=0; i<4; i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
      if(m[nx][ny]==-2){
        isblock = true;
        continue;
      }
      if(m[nx][ny]==-1){
        m[nx][ny] = m[x][y];
        que.push(make_pair(nx, ny));
      }
    }
    if(isblock) que2.push(make_pair(x, y));
    if(que.empty()){
      while(!que2.empty()){
        P p2 = que2.front();
        que2.pop();
        x = p2.first;
        y = p2.second;
        for(int i=-2; i<=2; i++){
          for(int j=-2; j<=2; j++){
            int nx = x + i;
            int ny = y + j;
            if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
            if(m[nx][ny]==-1){
              m[nx][ny] = m[x][y]+1;
              que.push(make_pair(nx, ny));
            }
          }
        }
      }
    }
  }
  cout << m[gx][gy] << endl;
  return 0;
}


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
    int x,i,n;
    cin>>n;
    for(i=0; i<n; i++)
    {
        x=n-4*i;
        if(x<0)
            break;
        if(x%7==0)
        {
            cout<<"Yes"<<endl;
            return 0;
        }


    }
    cout<<"No"<<endl;

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long 
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int dp[100010];
	dp[0] = 0;
	dp[1] = abs(vec.at(1) - vec.at(0));
	for(int i = 2;i < N;i++) {
		dp[i] = min(dp[i - 2] + abs(vec.at(i) - vec.at(i - 2)),dp[i - 1] + abs(vec.at(i) - vec.at(i - 1)));
	}
	cout << dp[N - 1] << endl; 
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct DisjointSet {
	vector<int>p, rank;
	DisjointSet(int n) {
		p.resize(n);
		rank.assign(n, 0);
		rep(i, 0, n)p[i] = i;
	}
	int root(int x) {
		if (x != p[x])p[x] = root(p[x]);
		return p[x];
	}
	int same(int x, int y) {
		return root(x) == root(y);
	}
	void unite(int x, int y) {
		if (same(x, y))return;
		
		x = root(x), y = root(y);

		if (rank[x] < rank[y])p[x] = y;
		else {
			p[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	DisjointSet uf(n);
	rep(i, 0, q) {
		int com, x, y; cin >> com >> x >> y;
		if (com)cout << uf.same(x, y) << endl;
		else uf.unite(x, y);
	}
	return 0;
}

Measured memory_bytes: 3260
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n=int(input())
w=list(intinput())
sums=[0]
for i in range(len(w)):
    sums.append(sums[i]+w[i])
x=10**100
for i in range(len(sums)-1):
    x=min(x,abs(sums[-1]-(2*sums[i])))
print(x)

Measured memory_bytes: 3064
N = input()

hon = ["2", "4", "5", "7", "9"]
pon = ["0", "1", '6', '8']
bon = ['3']

ans = ""
if N[-1] in hon:
    ans = "hon"
elif N[-1] in pon:
    ans = "pon"
else:
    ans = "bon"

print(ans)


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

//dp[i] i以上にするための最小のコスト
vector<int> dp;
signed main() {
  int H, N; cin >> H >> N;
  dp.assign(20000+1000,INF_LL);
  vector<P> power(N);
  rep(i, N) {
    cin >> power[i].first >> power[i].second;
  }
  dp[0] = 0;
  rep(i, 10000*2+100) {
    if(i == 0) continue;
    rep(j, N) {
      if(i - power[j].first < 0){
        chmin(dp[i], dp[0]+power[j].second);
      }
      else{
        chmin(dp[i], dp[i-power[j].first] + power[j].second);
      } 
    }
  }
  int ans = INF_LL;
  for(int i=H; i < 20000+100; i++){
    chmin(ans, dp[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout<<((a)?"Yes":"No")<<endl;
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    yn(abs(a-b)<=d&&abs(c-b)<=d||abs(a-c)<=d);

    return 0;
}


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

const int maxN=200005;
int N;
int A[maxN],B[maxN];int *d;
int idA[maxN],idB[maxN];
bool cmp(int u,int v){return d[u]<d[v];}
int mA[maxN],mB[maxN];
int fa[maxN],siz[maxN];int find(int x){return (fa[x]==x)?x:fa[x]=find(fa[x]);}
void merge(int x,int y){x=find(x),y=find(y);if(x==y) return;fa[x]=y,siz[y]+=siz[x];}

int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%d",&A[i]),A[0]^=A[i],idA[i]=i;
	for(int i=1;i<=N;i++) scanf("%d",&B[i]),B[0]^=B[i],idB[i]=i;
	d=A;sort(idA,idA+N+1,cmp);d=B;sort(idB,idB+N+1,cmp);
	for(int i=0;i<=N;i++){
		if(i==0) mA[idA[i]]=1; else mA[idA[i]]=mA[idA[i-1]]+1-(A[idA[i]]==A[idA[i-1]]);
		if(i==0) mB[idB[i]]=1; else mB[idB[i]]=mB[idB[i-1]]+1-(B[idB[i]]==B[idB[i-1]]);
		if(A[idA[i]]!=B[idB[i]]){printf("-1\n");return 0;}
	} 
	for(int i=1;i<=N+1;i++) fa[i]=i,siz[i]=1;
	int ans=0;
	for(int i=0;i<=N;i++) merge(mA[i],mB[i]),ans+=(mA[i]!=mB[i]);
	for(int i=1;i<=N+1;i++) if(fa[i]==i&&siz[i]>=2) ans+=1;
	if(siz[find(mA[0])]!=1){
		if(mA[0]==mB[0]) ans-=1;
		else ans-=2;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 10000
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	k := getNextInt(scanner)

	tree := make([][]int, n)
	color := make([]int, n)
	for i := 0; i < n; i++ {
		tree[i] = make([]int, 0)
	}
	for i := 0; i < n-1; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		tree[a] = append(tree[a], b)
		tree[b] = append(tree[b], a)
	}

	ans := int64(k) * dfs(tree, color, 0, 1, n, k)

	fmt.Fprintln(writer, ans%(10e8+7))

	writer.Flush()
}

func dfs(tree [][]int, color []int, r, depth, n, k int) int64 {
	var ans, mod int64
	ans = 1
	mod = 10e8 + 7
	color[r] = 2

	c := 0
	for i := 0; i < len(tree[r]); i++ {
		if color[tree[r][i]] != 0 {
			continue
		}
		color[tree[r][i]] = 1
		ans *= dfs(tree, color, tree[r][i], depth+1, n, k)
		ans %= mod
		c++
	}

	if c == 0 {
		return 1
	}

	if depth == 1 {
		ans *= calc(k-1, c)
	} else {
		ans *= calc(k-2, c)
	}
	ans %= mod

	return ans
}

func calc(n, c int) int64 {
	ans := 1
	for i := 0; i < c; i++ {
		ans *= n - i
		ans %= 10e8 + 7
	}

	return int64(ans)
}


Measured memory_bytes: 37376
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            Console.WriteLine((x*x*x).ToString());
        }
    }
}



Measured memory_bytes: 13884
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>

#define PI 3.14159265359

#define INF 1000000;

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

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/
string button[10] = {"12345678", ".,!? ", "abc", "def", "ghi", "jkl" , "mno", "pqrs", "tuv", "wxyz" };


int main()
{
	int n;
	string s;
	
	cin >> n;
	rep(j,n)
	{
		cin >> s;
		int bnum=0, pushnum=0;
		REP(s.size())
		{
			if (s[i] == '0' && pushnum > 0)
			{
				cout << button[bnum][(pushnum + button[bnum].size()-1) % button[bnum].size()];
				pushnum = 0;
				bnum = 0;
				continue;
			}
			if (s[i] != '0'){pushnum++; bnum = s[i]-'0';}
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//shuffle(permutation.begin(), permutation.end(), rng);
//uniform_int_distribution<int>(l, r)(rng);

int n;
vi prime;
bool iscomposite[100005];
ll s[100005];
map<ll, ll> mep;
map<ll, bool> sek;
ll catat[100005];
ll simp[100005];

void pre() {
	prime.pb(2);
	for(ll i = 3; i <= 100000; i += 2) {
		if (!iscomposite[i]) {
			prime.pb(i);
			for(ll j = i * i; j <= 100000; j += i) iscomposite[j] = 1;
		}
	}
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	pre();
	cin >> n;
	REP(i, n) {
		cin >> s[i];
		catat[i] = 1;
		simp[i] = 1;
	}
	REP(i, prime.size()) {
		ll tmp = prime[i];
		ll sat = prime[i];
		//cout << sat << "awea\n";
		if (sat >= 3000) break;
		tmp = tmp * tmp * tmp;
		REP(j, n) {
			if (s[j] % tmp == 0) {
				while (s[j] % tmp == 0) {
					s[j] /= tmp;
				}
			}
			if (s[j] % (sat * sat) == 0) {
				catat[j] *= sat; 
				simp[j] *= sat * sat;
			}
			else if (s[j] % sat == 0) {
				catat[j] *= (sat * sat);
				simp[j] *= sat;
			}
		}
	}
	ll res = 0;
	REP(i, n) {
		int j = i;
		mep[s[i]]++;
		if (s[i] != simp[i]) {
			ll tmp = s[i] / simp[i];
			ll akar = sqrt(tmp);
			if (akar * akar == tmp) {
				catat[i] *= akar;
			}
			else {
				if (s[j] > 1000000) {
					catat[j] = 100000000000000;
				}
				else {
					catat[j] *= tmp;
					if (catat[j] > 100000000000) catat[j] = 100000000000000;
					else catat[j] *= tmp;
				}
			}
		}
	}
	REP(j, n) {
		//cout << s[j] << ' ' << catat[j] << "hahahi\n";
		if (sek[s[j]] == 0) {
			if (s[j] == 1) {
				res += 1;
				sek[s[j]] = 1;
			}
			else {
				if (catat[j] > 10000000000) {
					res = res + mep[s[j]];
					sek[s[j]] = 1;
				}
				else {
					res = res + max(mep[s[j]], mep[catat[j]]);
					sek[s[j]] = 1, sek[catat[j]] = 1;
				}
			}
		}
	}
	cout << res << '\n';
}

Measured memory_bytes: 23296
hi, wi = map(int, input().split())
ho, wo = map(int, input().split())

if 1 <= hi <= 20 and 1 <= wi <= 20 and 1 <= ho <= hi and 1 <= wo <= wi:
    white = hi * wi
    black = hi * wo + ho * wi - ho * wo
    print(white - black)
else:
    print('hoge')

Measured memory_bytes: 3064
# B - 81
N = int(input())

hantei = [False]*82
for i in range(1, 10):
    for j in range(1, 10):
        hantei[i*j] = True

if N > 81:
    print('No')
else:
    if hantei[N]:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

        int cnt = 0;
        for(int i = 0; i < s.size() / 2; i++) {
                if(s[i] != s[s.size() - i - 1]) cnt++;
        }

        cout << cnt << endl;
        
        return 0;
}


Measured memory_bytes: 256
long mod=1e9+7,dp[1<<21];
n,a,I,x,y,i,j;
main()
{
	for(*dp=scanf("%d",&n);i++<n;)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a);
			for(I=(1<<i)-1;I<1<<n;)
			{
				if(a&&(I&1<<j))dp[I]=(dp[I]+dp[I&~(1<<j)])%mod;
				x=I&-I,y=I+x;
				I=(I&~y)/x>>1|y;
			}
		}
	}
	printf("%d",dp[I-y/2]);
}

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

#include <iostream>
#include <array>
// #include <map>
#include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

int w; // j
int h; // i
string max_s(70, ' ');
array<array<char, 70>, 70> field; // [i][j]
array<array<string, 70>, 70> memo; // [i][j]

inline string big(const string& a, const string& b) {
	if (a.size() == b.size()) {
		if (a > b) {
			return a;
		} else {
			return b;
		}
	}
	if (a.size() > b.size()) {
		return a;
	} else {
		return b;
	}
}

string _trace(int i, int j) {
	if (memo[i][j] != "") {
		return memo[i][j];
	}
	int new_i = i + 1;
	int new_j = j + 1;
	string res1 = "";
	string res2 = "";
	if (new_i < h and isdigit(field[new_i][j])) {
		res1 = _trace(new_i, j);
	}
	if (new_j < w and isdigit(field[i][new_j])) {
		res2 = _trace(i, new_j);
	}
	memo[i][j] = field[i][j] + big(res1, res2);
	return memo[i][j];
}

inline bool myIsdigit(char c) {
	return ('1' <= c and c <= '9');
}

string trace(int i, int j) {
	if (myIsdigit(field[i][j]) == false) {
		return "";
	}
	if (i > 0 and myIsdigit(field[i - 1][j])) {
		return "";
	}
	if (j > 0 and myIsdigit(field[i][j - 1])) {
		return "";
	}
	auto res = _trace(i, j);
	return res;
}

void solve() {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> field[i][j];
			memo[i][j] = "";
		}
	}
	max_s = "";
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			max_s = big(max_s, trace(i, j));
		}
	}
	cout << max_s << endl;
}

int main() {

	while (true) {
		cin >> w >> h;
		if (w == 0 and h == 0) {
			break;
		}
		solve();
	}

	//std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}

Measured memory_bytes: 3256
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N, Q = map(int, readline().split())

N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [INF]*(2*N0)
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2*k+1], data[2*k+2])
def query(l, r):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])

        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s


ans = []
for q in range(Q):
    t, x, y = map(int, readline().split())
    if t:
        ans.append(str(query(x, y+1)))
    else:
        update(x, y)
write("\n".join(ans))
write("\n")



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

using ll = long long;
static const ll MOD = 1e9 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string l;
  cin >> l;
  
  vector<vector<ll>> dp(l.size() + 1, vector<ll>(2));
  dp.at(0).at(0) = 1;
  for (int i = 0; i < l.size(); i++) {
    for (int j = 0; j < 2; j++) {
      for (int d = 0; d <= (j ? 1 : l.at(i) - '0'); d++) {
        if (d == 0) {
          dp.at(i + 1).at(j || (d < l.at(i) - '0')) += dp.at(i).at(j);
          dp.at(i + 1).at(j || (d < l.at(i) - '0')) %= MOD;
        }
        else {
          dp.at(i + 1).at(j || (d < l.at(i) - '0')) += 2 * dp.at(i).at(j);
          dp.at(i + 1).at(j || (d < l.at(i) - '0')) %= MOD;
        }
      }
    }
  }
  
  cout << (dp.at(l.size()).at(0) + dp.at(l.size()).at(1)) % MOD << '\n';
}

Measured memory_bytes: 5840
#include<stdio.h>
int main(){
  int n,s[30010],i,j,k,a[15],b[1010],sum,ans=0,d[110];
  char c;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%c",&c);
    s[i]=c-'0';
  }
  for(i=0;i<10;i++){
    a[i]=0;
  }
  for(i=0;i<1000;i++){
    b[i]=0;
  }
  for(i=0;i<100;i++){
    d[i]=0;
  }
  for(i=0;i<n;i++){
    if(ans==1000){
      break;
    }
    if(a[s[i]]!=1){
    for(j=i+1;j<n;j++){
      if(d[10*s[i]+s[j]]!=1){
      for(k=j+1;k<n;k++){
        sum=100*s[i]+10*s[j]+s[k];
        if(b[sum]==0){
          b[sum]=1;
          ans++;
        }
      }
        d[10*s[i]+s[j]]=1;
      }
    }
      a[s[i]]=1;
    }
  }
  printf("%d\n",ans);
  return 0;
}      

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))

genzaichi=1
rireki=set()
houmon=[0]*(N+1)
flag=0

for i in range(1,K+1):
    genzaichi=A[genzaichi-1]
    if genzaichi not in rireki:
        houmon[genzaichi]=i
        rireki.add(genzaichi)
    else:
        roop_from=genzaichi
        x=houmon[roop_from]
        roop=i-x
        flag=1
        break

if flag==0:
    print(genzaichi)
else:
    genzaichi=roop_from
    K=(K-x)-((K-x)//roop)*roop
    for i in range(K):
        genzaichi=A[genzaichi-1]
    print(genzaichi)

Measured memory_bytes: 36136
//
//  a.cpp
//  agc029
//
//  Created by reproy on 12/15/18.
//  Copyright © 2018 reproy. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define LL                      long long
#define Ulong                   unsigned long long
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-14
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl
#define nl                      cout<<endl
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("/home/matrixcode/Desktop/in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
    register char c = getchar();x = 0;
    int neg = 0;
    for(; ((c<48 || c>57) && c != '-'); c = getchar());
    if(c=='-'){neg = 1;c = getchar();}
    for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 2e5+5;
LL A[N];

int main()
{
    string S;
    cin >> S;
    LL ans = 0, cnt = 0;
    for(int i = S.size()-1; i >= 0; i --) {
        if(S[i] == 'B') ans += cnt;
        else cnt ++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

set<long long int> st;

void dfs(int n3, int n5, int n7, int dig, long long int cur) {
    if(dig>=10) {
        if(n3>=1 && n5>=1 && n7>=1) {
            st.insert(cur);
        }
        return;
    }
    
    dfs(n3, n5, n7, dig+1, cur);
    dfs(n3+1, n5, n7, dig+1, cur*10+3);
    dfs(n3, n5+1, n7, dig+1, cur*10+5);
    dfs(n3, n5, n7+1, dig+1, cur*10+7);
}

int main() {
    long long int N;
    cin >> N;
    
    dfs(0, 0, 0, 0, 0);
    long long int cnt=0;
    for(auto itr=st.begin(); itr!=st.end(); itr++) {
        if(*itr<=N) cnt++;
        else break;
    }
    cout << cnt << endl;


    return 0;
    
}

Measured memory_bytes: 4096