akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r,idx;
ll x[500005],y[500005],z[500005];
char s[500005];

ll norma = 0;
bool checked[500005][3];
bool flag,dame;

int main(){
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	sort(x,x+n);
	//first = cardの数字
	//second = cardの枚数
	P dp[200005];
	for(i=0;i<m;i++){
		cin >> a >> b;
		dp[i].first = b;
		dp[i].second = a;
	}
	sort(dp,dp+m);
	reverse(dp,dp+m);
	ll idx = 0;
	num = 0;
	while(1){
		for(i=num;i<num+dp[idx].second;i++){
			y[i] = dp[idx].first;
		}
		num += dp[idx].second;
		//p(num);
		idx++;
		if(num > n || idx >= m)break;
	}
	for(i=0;i<n;i++){
		ans += max(x[i],y[i]);
	}
	p(ans);

    
	return 0;
}

Measured memory_bytes: 24704
#include <iostream>
#include <algorithm>
#include <numeric>
int main(){
  int n,k,i,a,c[200001]={},d=0;
  std::cin>>n>>k;
  for(i=0;i<n;++i){std::cin>>a;++c[a-1];}
  for(int x:c)(x>0?++d:0);
  std::sort(c,c+n,std::greater<int>());
  std::cout<<std::accumulate(c+d-std::max(0,d-k),c+d,0)<<"\n";
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int i;
	for (i = 0; i < s.length(); i++)
	{
		int a;
		a = s.at(i) + n;
		//cout << a << endl;
		if (a > int('Z'))
		{
			a = 'A'-1 +a % int('Z');
		}
		s.at(i) = char(a);
	}
	cout << s<<endl;
}

Measured memory_bytes: 3576
N,M=map(int,input().split())

L = [[1,0] for i in range(N+1)]
L[1]=[1,1]

for i in range(M):
    X,Y=map(int,input().split())
    if(L[X][0]!=0):
        L[X][0]-=1
        L[Y][0]+=1
        if(L[X][1]!=0):
            L[Y][1]=1
            if(L[X][0]==0):
                 L[X][1]=0

t=0
for i in range(N+1):
    t+=L[i][1]
print(t)


Measured memory_bytes: 13172
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <unordered_set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 H, W;
  cin >> H >> W;
  vvi D(H, vi(W));
  i64 r, c;
  REP(0, H, r) {
    REP(0, W, c) {
      cin >> D[r][c];
    }
  }
  REP(0, H, r) {
    REP(0, W, c) {
      i64 b;
      cin >> b;
      D[r][c] -= b;
      if(D[r][c] < 0)
	D[r][c] *= -1;
    }
  }

  //  using us = unordered_set<i64>;
  //vector<vector<us>> S(H, vector<us>(W));
  vector<vector<vector<int>>> F(H, vector<vector<int>>(W));

  //i64 L = (H + W) / 2;

  i64 LIM = 161*81, d;
  F[0][0].resize(LIM, 0);
  F[0][0][D[0][0]] = 1;
  //cout << D[0][0] << endl;
  
  // S[0][0].insert(D[0][0]);
  REP(0, H, r) {
    REP(0, W, c) {
      /*
      if(r + c > L) {
	continue;
      }
      */

      if(r != 0 || c != 0) {
	F[r][c].resize(LIM, 0);
      }
      
      //i64 ct = 0;
      //cout << r << " " << c << endl;
      if(c > 0) {
	REP(0, LIM, d) {	  
	  if(F[r][c-1][d] == 1) {
	    i64 d0 = abs(d + D[r][c]), d1 = abs(d - D[r][c]);
	    F[r][c][d0] = 1;
	    F[r][c][d1] = 1;
	    //++ct;
	  }
	}
      }
      if(r > 0) {
	REP(0, LIM, d) {
	  if(F[r-1][c][d] == 1) {
	    i64 d0 = abs(d + D[r][c]), d1 = abs(d - D[r][c]);
	    F[r][c][d0] = 1;
	    F[r][c][d1] = 1;
	    //++ct;
	  }
	}
      }
      //cout << ct << endl;
      //cout << r << " " << c << " " << sz(S[r][c]) << endl;
    }
    //cout << "line " << r << endl;
  }

  REP(0, LIM, d) {
    if(F[H-1][W-1][d] != 0) {
      cout << d << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 326528
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>
#include <random>
#include <complex>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <cassert>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll gcd(ll a, ll b) {
    if (!a) return b;
    return gcd(b%a, a);
}

const int MN = 1010;
const ll MD = 1e9+7;

ll m;

ll inv[MN];
ll powt[MN][MN];
ll fact[MN];
ll comb[MN][MN];
ll gcdm[MN];
ll get2[MN];
void init() {
    inv[1] = 1;
    for (int i = 2; i < MN; i++) {
        inv[i] = inv[MD % i] * (MD - MD / i) % MD;
    }
    for (int i = 0; i < MN; i++) {
        powt[i][0] = 1;
        for (int j = 1; j < MN; j++) {
            powt[i][j] = powt[i][j-1]*i % MD;
        }
    }
    fact[0] = 1;
    for (int i = 1; i < MN; i++) {
        fact[i] = fact[i-1] * i % MD;
    }
    comb[0][0] = 1;
    for (int i = 1; i < MN; i++) {
        comb[i][0] = 1;
        for (int j = 1; j < MN; j++) {
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
            comb[i][j] %= MD;
        }
    }
    for (int i = 0; i < MN; i++) {
        gcdm[i] = gcd(m, i);
    }
    get2[0] = 1;
    get2[1] = 1;
    for (int i = 2; i < MN; i++) {
        get2[i] = get2[i-1] + (i-1) * get2[i-2];
        get2[i] %= MD;
    }
}


ll dp[3][MN][MN];
ll calc(int f, int n, int k) {
    if (k < 0) return 0;
    if (!k) return 1;
    if (dp[f][n][k] != -1) return dp[f][n][k];
    if (!f) {
        ll res = 0;
        for (int i = 1; i <= k; i++) {
            if (n*i / gcdm[n*i] != n) continue;
            ll r = calc(f, n, k-i);
            r *= comb[n*k-1][n*i-1]; r %= MD;
            r *= fact[n*i-1]; r %= MD;
            res += r; res %= MD;
        }
        return (dp[f][n][k] = res);
    } else {
        ll res = (n%2)*calc(f, n, k-1); res %= MD;
        ll r = (k-1)*n; r %= MD;
        r *= calc(f, n, k-2); r %= MD;
        res += r; res %= MD;
        return (dp[f][n][k] = res);
    }
}
ll solve(int n, int m) {
    assert(0 <= n);
    if (!n) return 1;
    if (n < m) return 0;
    if (dp[2][n][m] != -1) return dp[2][n][m];
    ll res = solve(n, m+1);
    for (int i = 1; i <= n/m; i++) {
        ll r = comb[n][i*m];
        r *= calc(0, m, i); r %= MD;
        r *= calc(1, m, i); r %= MD;
        r *= solve(n-i*m, m+1); r %= MD;
        res += r; res %= MD;
    }
    return (dp[2][n][m] = res);
}


int main() {
    memset(dp, -1, sizeof(dp));
    ll n, x, y, z;
    cin >> n >> x >> y >> z;
    x += z;
    m = abs(x-y);
    init();
    if (!x && !y) {
        cout << powt[n][n] * get2[n] % MD << endl;
        return 0;
    }
    if (x == y) {
        cout << fact[n] * get2[n] % MD << endl;
        return 0;
    }
    cout << solve(n, 1) << endl;
    return 0;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
typedef long long LL;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int a, b;
  cin >> a >> b;
  cout << (a + b - 1)/b << endl;
  return 0;
}



Measured memory_bytes: 256
from bisect import *
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):x=int(x);print(sum(1 for d in p[:bisect(p,x//2)]if a[x-d]))


Measured memory_bytes: 7800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

int a,b,h,m;
double solve(){
   double ans=0;
   double aH=h*M_PI/6+((double)M_PI/6)*((double)m/60);
   double angleM=m*M_PI/30;

   double diff=aH-angleM;

   if(diff<0)diff=-diff;
   if(diff>M_PI)diff=2*M_PI-diff;

   ans=a*a+b*b-2*a*b*cos(diff);
   ans=sqrt(ans);
   return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>a>>b>>h>>m;
    cout<<setprecision(15)<<solve()<<endl;
    return 0;
}

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

//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main(){
    int n;
    string s;
    cin >> n >> s;
    if(s.size()%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    string a = s.substr(0,n/2);
    string b = s.substr(n/2);
    if(a == b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
h, w, k = gets.split.map(&:to_i)
rows = Array.new(h){gets.chomp.bytes.map{|c| (c == '#'.ord) ? 1 : 0}}
cnt = 0
[0, 1].repeated_permutation(h) do |x|
  m = []
  x.each_with_index do |y, i|
    if y == 0
      m << rows[i].dup
    else
      m << [0] * w
    end
  end
  [0, 1].repeated_permutation(w) do |u|
    mc = []
    u.each_with_index do |v, l|
      if v == 0
        mc << m.transpose[l]        
      end
    end
    cnt += 1 if mc.flatten.sum == k
  end
end
puts cnt

Measured memory_bytes: 14488
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll p=1e5;

int main()
{
    /*#ifndef ONLINE_JUDGE
       freopen ("input.txt" , "r" , stdin);
		// freopen ("OUTPUT.txt" , "w" , stdout);
	#endif
    */
	fio;
    ll x,y;
    cin>>x>>y;
    ll sum=0;
    ll z=0;
    sum+=max(4-x,z);
    sum+=max(4-y,z);
    if(x==y && y==1)
    sum+=4;
    cout<<sum*p<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(ll i=a;i<=b;i++)
#define X first
#define Y second
#define maxn 100202
#define eps 0.0000001
#define inf 1e9
#define pb push_back
#define maxD 15
#define ll long long
using namespace std;
int h,w,n,a[maxn];
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
iii next(iii P){
	if(P.X.Y==1) {
		if(P.Y==-1) return {{P.X.X+1,P.X.Y},1};
		return {{P.X.X,P.X.Y+1},1};
	}	
	if(P.X.Y==w) {
		if(P.Y==1) return {{P.X.X+1,P.X.Y},-1};
		return {{P.X.X,P.X.Y-1},-1};
	}	
	return {{P.X.X,P.X.Y+P.Y},P.Y};
}
iii next2(iii P){
	return {{P.X.X+1,P.X.Y},P.Y};
}
int m[102][102];
main(){
	cin >> h >> w >> n;
	For(i,1,n)	{
		scanf("%d",a+i);
	}
	iii t = {{1,1},1};
//	For(i,1,n){
//		cout << t.X.X << " " << t.X.Y << " " << t.Y << "\n";
//		t = next(t);
//	}
	For(i,1,n){
		For(j,1,a[i]){
			m[t.X.X][t.X.Y] = i;
			t = next(t);
		}
	}
	if(w==1){
		t = {{1,1},1};
		For(i,1,n){
		For(j,1,a[i]){
			m[t.X.X][t.X.Y] = i;
			t = next2(t);
		}
	}
	}
	For(i,1,h){
		For(j,1,w){
			printf("%d ",m[i][j]);
		}
		printf("\n");
	}
}


Measured memory_bytes: 384
N,M=[int(i) for i in input().split()]
edge=[[] for i in range(N)]

for i in range(M):
	a,b=[int(i)-1 for i in input().split()]
	edge[a].append(b)
	edge[b].append(a)

went=[False for i in range(N)]

def dfs(now):
	if went.count(False)==0:
		return 1
	ans=0
	for _next in edge[now]:
		if not went[_next]:
			went[_next]=True
			ans+=dfs(_next)
			went[_next]=False
	return ans
went[0]=True

print(dfs(0))


Measured memory_bytes: 3064
import java.util.*;

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

		for (int i = 0;i < N;++i) {
			int A = sc.nextInt();
			count[A]++;
		}

		for (int a = 100;a >= 1;--a) {
			count[a - 1] += count[a];
		}

		int max = 0;
		for (int a = 0;a <= 100;++a) {
			if (count[a] >= a) {
				max = a;
			}
		}

		System.out.println(max);
	}
}



Measured memory_bytes: 26480
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int k; cin >> k;
    ll res = 0;
    rept(a, 1, k+1){
        rept(b, 1, k+1){
            rept(c, 1, k+1){
                res += __gcd(__gcd(a, b), c);
            }
        }
    }
    cout << res << ln;
}

Measured memory_bytes: 3600
import sys
sys.setrecursionlimit(10**9)
from collections import defaultdict

t = int(input())

for _ in range(t):
    n,a,b,c,d = map(int,input().split())
    dic = defaultdict(int)
    dic[0] = 0
    dic[1] = d

    def calc(x):
        if(x==0):
            return 0
        if(dic[x] != 0):
            return dic[x]

        tmp = x*d
        if(x%2==0):
            tmp = min(tmp, calc(x//2) + a)
        else:
            tmp = min(tmp, calc(x//2) + a + d, calc(x//2 + 1) + a + d)
        if(x%3==0):
            tmp = min(tmp, calc(x//3) + b)
        elif(x%3==1):
            tmp = min(tmp, calc(x//3) + b + d)
        else:
            tmp = min(tmp, calc(1 + x//3) + b + d)
        if(x%5==0):
            tmp = min(tmp, calc(x//5) + c)
        elif(x%5 < 3):
            tmp = min(tmp, calc(x//5) + c + d*(x%5))
        else:
            tmp = min(tmp, calc(1 + x//5) + c + d*(5 - x%5))

        dic[x] = tmp
        return tmp

    print(calc(n))

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

int c[22];

int main()
{
    int n,x;
    scanf("%d",&n);
    ++c[0];
    for (int i=1;i<=n;i++) {
        scanf("%d",&x);
        ++c[x];
    }
    if (*max_element(c,c+13)>2) {
        puts("0");
    } else if (c[0]>1) {
        puts("0");
    } else {
        vector<int> fix;
        vector<int> tmp;
        fix.push_back(0);
        for (int i=1;i<=12;i++) {
            if (c[i]==2) {
                fix.push_back(i);
                fix.push_back(24-i);
            } else if (c[i]==1) {
                tmp.push_back(i);
            }
        }
        int m=tmp.size();
        int lim=1<<m;
        int ans=0;
        for (int st=0;st<lim;st++) {
            vector<int> res(fix);
            for (int i=0;i<m;i++) {
                if (st>>i&1) {
                    res.push_back(24-tmp[i]);
                } else {
                    res.push_back(tmp[i]);
                }
            }
            sort(res.begin(),res.end());
            res.push_back(24);
            int now=1111;
            for (int i=1;i<(int)res.size();i++) {
                now=min(now,res[i]-res[i-1]);
            }
            ans=max(ans,now);
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
G = []
for i in range(N):
    x,y = map(int,input().split())
    G.append([x,y])

a = -10**10
b = 10**10
c = -10**10
d = 10**10

for i in range(N):
    x = G[i][0]
    y = G[i][1]
    t = x+y
    u = x-y
    a = max(a,t)
    b = min(b,t)
    c = max(c,u)
    d = min(d,u)

#print(a,b,c,d)
ans = max(a-b,c-d)
print(ans)


Measured memory_bytes: 102636
from collections import defaultdict, Counter
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    c = Counter([int(input()) for _ in range(N)])
    ans = 0
    for k, v in c.items():
        ans += v % 2 != 0
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16636
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

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

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

long long n;
string s;

signed main()
{
    srand(time(NULL));
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> s;
    if (n % 2 == 0)
    {
        int t = 1;
        for (int i = 0; i < n / 2; i++)
        {
            if (s[i] != s[i + n / 2])
            {
                cout << "No";
                return 0;
            }
        }
        cout << "Yes";
        return 0;
    }
    cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b==c+d)cout<<"Balanced";
  else if(a+b>c+d)cout<<"Left";
  else if(a+b<c+d)cout<<"Right";
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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; }

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

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000010

  int n;
  int M[100][100];
  int color[100];
  int d[100];
  int p[100];
  int mincost;

void prim(){
  rep(u,n) color[u]=WHITE;
  rep(u,n) d[u]=INF;
  d[0]=0;
  p[0]=-1;
  
  int u;
  while(1){
    mincost=INF; 
    rep(i,n){
      if(color[i] != BLACK && d[i]<mincost){
        mincost=d[i];
        u=i;
      }
    }
    
    if(mincost==INF) break;
    
    color[u]=BLACK;
    
    rep(v,n){
      if(color[v] != BLACK && M[u][v] != -1){
        if(M[u][v]<d[v]){
          d[v]=M[u][v];
          p[v]=u;
          color[v]=GRAY;
        }
      }
    }
  }
}

int main(){
  cin>>n;
  
  rep(i,n){
    rep(j,n) cin>>M[i][j];
  }
  
  prim();
  int sum=0;
  rep(i,n) sum+=d[i];
  
  cout<<sum<<endl;
  
  return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>

int main(void) {
	int n, m, i, sum=0, num;
	scanf("%d %d", &n, &m);
	for(i=0; i<m; i++){
		scanf("%d", &num);
		sum += num;
	}
	if(n-sum>=0)
		printf("%d", n-sum);
	else
		printf("-1");
	return 0;
}

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

using namespace std;

int main() {
   int a,b,c;
   cin >> a >> b >> c;  
   cout << (a==b ? c :b==c ? a : b) << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] h = new long[n];
		long total = 0;
		for(int i = 0;i < n;i++) {
			h[i] = sc.nextInt();
		}

		if(k >= n) {
			System.out.println(0);
			return;
		}
		Arrays.sort(h);
		for(int i = 0;i < n-k;i++) {
			total += h[i];
		}
		System.out.println(total);
	}

}

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

int main() {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;

  cout << ((v - w) * t >= abs(a-b) ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int N; cin >> N;
  vector<int64_t> a(3*N);
  rep(i,3*N) cin >> a.at(i);
  sort(all(a));
  int64_t ans=0;
  for(int i=3*N-1;i>N-1;i-=2){
    ans += a.at(i-1);
  }
  cout << ans << endl;
}

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

int main(){

 
  int N;
 
  cin>>N;
  int A[N];
  rep(i,N)cin>>A[i];
  int C[N];
  rep(i,N)C[A[i]-1]=i+1;

  rep(i,N)cout<<C[i]<<" ";
  cout<<endl;
}


Measured memory_bytes: 1536
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> sum(n + 1);
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + a[i];
  }
  long long ans = 1LL << 60;
  int j = 2, k = 4;
  for (int i = 3; i <= n - 1; i++) {
    long long x = abs(sum[j - 1] - (sum[i - 1] - sum[j - 1]));
    for (; j + 1 < i && x >= abs(sum[j] - (sum[i - 1] - sum[j])); j++) x = abs(sum[j] - (sum[i - 1] - sum[j]));
    long long y = abs(sum[k - 1] - sum[i - 1] - (sum[n] - sum[k - 1]));
    for (; k < n && y >= abs(sum[k] - sum[i - 1] - (sum[n] - sum[k])); k++) y = abs(sum[k] - sum[i - 1] - (sum[n] - sum[k]));
    long long mx = 0;
    long long mi = 1LL << 60;
    long long s1 = sum[j - 1];
    long long s2 = sum[i - 1] - sum[j - 1];
    long long s3 = sum[k - 1] - sum[i - 1];
    long long s4 = sum[n] - sum[k - 1];
    mx = max({s1, s2, s3, s4});
    mi = min({s1, s2, s3, s4});
    ans = min(ans, abs(mx - mi));
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<LL> vl;
typedef vector<vector<LL>> vvl;
typedef vector<vector<vector<LL>>> vvvl;


const int inf = 1e9+7;
const LL INF = 1e18+5;
const int mod = 1e9+7;
const int mxN = 1e5+5;
const int mxM = 1e5+5;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("E:\\Coding\\Programming\\input.txt", "r", stdin);
    freopen("E:\\Coding\\Programming\\output.txt", "w", stdout);
    #endif
    string s;
    cin>>s;
    int c = 0;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') c = 3;
    else if(s[0]=='R'&&s[1]=='R' || s[1]=='R'&&s[2]=='R') c = 2;
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R') c = 1;
    else c = 0;
    cout<<c<<endl;
}

Measured memory_bytes: 3548
n = int( input() )
#print( n )

cnt = 0
ans = "No"
for i in range( n ):
    a, b = map( int, input().split() )
    if a == b:
        cnt = cnt + 1
    else:
        cnt = 0

    if cnt == 3:
        ans = "Yes"


print( ans )


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

int main() {
    int l, r, d;
    cin >> l >> r >> d;

    l--;
    cout << r / d - l / d << endl;

    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] longArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long N = longArray[0];
            long K = longArray[1];
            N %= K;
            if(Math.Abs(N -K) <= N)
            {
                N = Math.Abs(N - K);
            }
            Console.WriteLine(N);
        }
    }
}

//24579 =  hon
//0168 = pon
//3 = bon
//long n = long.Parse(Console.ReadLine());
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine(cnt);
//Console.ReadKey();


Measured memory_bytes: 28260
N, M, X, Y = map(int,input().split())
x = sorted(list(map(int,input().split())))
y = sorted(list(map(int,input().split())))
ans = "War"
for i in range(X+1,Y+1):
  if(x[-1] < i <= y[0]):
    ans = "No War"
print(ans)

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

int main(){
  string s,t;
  cin >> s >> t;
  int ans = 0;
  rep(i,int(s.size())){
    if(s[i]!=t[i])ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    
    /* Input */
    int N;
    cin >> N;

    int AC = 0, WA = 0, TLE = 0, RE = 0;
    rep (i, N) {
        string s;
        cin >> s;
        if (s == "AC") AC++;
        if (s == "WA") WA++;
        if (s == "TLE") TLE++;
        if (s == "RE") RE++;
    }

    /* Output */
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long giant;
inline int read() {
	int x=0,f=1;
	char c=getchar();
	for (;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
typedef pair<int,int> Pair;
const int maxl=205;
char s[maxl],t[maxl];
int K,n;
Pair get(char a[],int n) {
	static char b[maxl];
	int ret(0);
	b[1]=a[1];
	for (int i=2;i<=n;++i) if (a[i]==b[i-1]) b[i]=' '; else b[i]=a[i];
	for (int i=1;i<=n;++i) ret+=(b[i]==' ');
	return Pair(ret,b[n]==' ');
}
void print(giant x) {
	printf("%lld\n",x);
	exit(0);
}
int main() {
	scanf("%s",s+1),n=strlen(s+1);
	scanf("%d",&K);
	copy(s+1,s+n+1,t+1);
	Pair one(get(t,n));
	if (one.second==1 || s[1]!=s[n]) print((giant)one.first*K);
	t[1]=' ';
	Pair two(get(t,n));
	if (two.second) {
		giant ans=(giant)(one.first+two.first)*(K/2);
		if (K&1) ans+=one.first;
		print(ans);
	} else print((giant)two.first*(K-1)+one.first);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
 
#define rep(i,n) for(int i = 0; i < n; i++)
 
typedef long long ll;
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;
 
int main(){
  int n,m;
  cin >> n >> m;
  cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}


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

int main(void){
    int h, w, k;
    cin >> h >> w >> k;
    string c[h];
    rep(i, h) cin >> c[i];
    int ans = 0;
    rep(hmsk, 1 << h){
        rep(wmsk, 1 << w){
            int bk = 0;
            rep(i, h){
                rep(j, w){
                    int th = hmsk >> i, tw = wmsk >> j;
                    if(th & 1 && tw & 1 && c[i][j] == '#') ++bk;
                }
            }
            if(bk == k) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    while(cin>>a>>b)
    {
        ll gc=__gcd(a,b);
        ll ans=(a/gc)*b;
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<complex>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
typedef int kz;

kz gcd(kz a,kz b) { if(b==0) return a; else gcd(b,a%b); }

bool pr(int n) {
    int i=2;
    while (i*i<=n) {
        if (n%i==0) return false;
        i++;
    }
    return true;
}

int main(){
    int mod=1000000007;
    bool b[111111]={0};
    for (int i=2;i<111111;++i) {
        b[i]=pr(i);
    }
    int n;
    for (;;) {
        scanf("%d",&n);
        if (n==0) break;
        int ans=0,cnt=0;
        for (int i=2;cnt<n;++i) {
            if (b[i]) {
                ans+=i;
                cnt++;
            }
            if (i==111110){
                printf("Yo!\n");
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3200
N, M = gets.split.map(&:to_i)
p = []
y = []
# 県=>市の配列 のハッシュ
c = {}
# ソートしちゃうので何番目に入力された市か覚えておく必要がある
# yearはユニークなので，year=>入力順の辞書を作っておく
dict = {}

M.times do |i|
  p[i], y[i] = gets.split.map(&:to_i)
  if c[p[i]].nil?
    c[p[i]] = []
  end
  c[p[i]].push(y[i])
  dict[y[i]] = i
end

c.each do |a|
  # 各県の市を誕生順に昇順ソートする
  a[1].sort!
end

# puts "#{c}"

ans = {}
c.each do |key, val|
  i = 1
  val.each do |v|
    ans[dict[v]] = format('%06d', key) + format('%06d', i)
    i += 1
  end
end

ans = ans.sort

ans.each do |a|
  puts a[1]
end

Measured memory_bytes: 41900
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl '\n'

const int MAXN=10;
const int MOD=10000000;

int main(){
	ll n;
	cin>>n;
	ll a[n+1];
	ll x[n+1],y[n+1]; 
	ll qq=0;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		x[i]=i + a[i];
		y[i]=i - a[i];
		if(a[i]==0)qq++;
	}
	ll ans =0 ;	
	sort(x+1,x+n+1);
	sort(y+1,y+n+1);
	for(ll i=1,j=1;i<=n && j<=n;){
		if(x[i] < y[j] )i++;
		else if(x[i] > y[j])j++;
		else {
			ll aa=1,bb=1;
			while(x[i+1]==y[j]){
				aa++;i++;
			}
			while(y[j+1]==x[i]){
				bb++;j++;
			}
			ans+=aa*bb;
			i++;j++;
		}
	} 
	cout<<ans - qq<<endl;
	
	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,31)-1;


int main() {
  int N; cin >> N;
  ll a[N]; rep(i,N) cin >> a[i];
  ll result = 0;
  int pos = 0;
  while (true) {
    pos=(pos+1)%N;
    ll tmp = a[pos]/N;
    rep(j,N) { if (j!=pos) a[j]+=tmp; else a[pos]%=N; }
    result += tmp;
    bool ok = true; rep(j,N) if (a[j]>=N) ok = false;
    if (ok) break;
  }
  cout << result << endl;
}

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

int main(void)
{
	stack<int> s;
	int zug;

	while (cin >> zug) {
		if (zug > 0) s.push(zug);
		else {
			cout << s.top() << endl;
			s.pop();
		}
	}
	
	return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    string s,t;
    cin >> s >> t;
    t += s;

    cout << t << endl;

    return 0;
}



Measured memory_bytes: 256
n = int(input())
t = [int(input()) for i in range(n)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)
    
l = 1
for i in t:
    l = lcm(l,i)

print(l)

Measured memory_bytes: 3316
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val seqP = in.readLine.split(" ").map(_.toInt-1)
  val uft = new UnionFindTree(n)
  Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt - 1))
    .foreach { e =>
      uft.unite(e(0), e(1))
    }
    
    val ans = (0 until n)./:(0)((acc,i) => {
      if(uft.same(i, seqP(i))) acc+1 else acc
    })

  println(ans)

  class UnionFindTree(n:Int) {
    private val par  = Array.range(0, n)
    private val rank = Array.fill(n)(1)

    def root(x:Int):Int = {
      if(par(x) == x) x
      else { par(x) = root(par(x)); par(x) }
    }

    def same(x:Int, y:Int):Boolean = root(x) == root(y)

    def unite(x:Int, y:Int):Unit = {
      val rx = root(x)
      val ry = root(y)
      if(rx == ry) return

      if(rank(rx) < rank(ry)) par(rx) = ry
      else {
        par(ry) = rx
        if(rank(rx) == rank(ry)) rank(rx) += 1
      }
    }
  }
}

Measured memory_bytes: 54344
#!/usr/bin/env python3
import sys

A, B, C = map(int, input().split())

count = 0
while True:
    if (A%2 == 1) or (B%2 == 1) or (C%2 == 1):
        print(count)
        sys.exit(0)
    if A == B and B == C:
        print(-1)
        sys.exit(0)
    A, B, C = (B+C)//2, (A+C)//2, (A+B)//2
    count += 1
print(count)


Measured memory_bytes: 38384
N, M = map(int,input().split())


like_count = [0 for _ in range(M+1)]

for _ in range(N):
    tmp = list(map(int,input().split()))
    like_list = tmp[1:]
    for like in like_list:
        like_count[like] += 1

count = 0
for value in like_count:
    if value == N:
        count += 1

print(count)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using std::max;

#define MAXN 100003
int d[MAXN][3],a[MAXN][3];
int main(void)
{
    int i,N;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
    }
    d[0][0]=a[0][0];
    d[0][1]=a[0][1];
    d[0][2]=a[0][2];
    for(i=1;i<N;i++)
    {
        d[i][0]=a[i][0]+max(d[i-1][1],d[i-1][2]);
        d[i][1]=a[i][1]+max(d[i-1][0],d[i-1][2]);
        d[i][2]=a[i][2]+max(d[i-1][1],d[i-1][0]);
    }
    printf("%d\n",max(d[N-1][0],max(d[N-1][1],d[N-1][2])));

    return 0;
}

Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>
#include <atcoder/all>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using namespace atcoder;


int op(int a, int b) { return max(a, b); }

int e() { return -1; }

int target;

bool f(int v) { return v < target; }

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &(a[i]));
    }

    segtree<int, op, e> seg(a);

    for (int i = 0; i < q; i++) {
        int t;
        scanf("%d", &t);
        if (t == 1) {
            int x, v;
            scanf("%d %d", &x, &v);
            x--;
            seg.set(x, v);
        }
        else if (t == 2) {
            int l, r;
            scanf("%d %d", &l, &r);
            l--;
            printf("%d\n", seg.prod(l, r));
        }
        else if (t == 3) {
            int p;
            scanf("%d %d", &p, &target);
            p--;
            printf("%d\n", seg.max_right<f>(p) + 1);
        }
    }
}

Measured memory_bytes: 6220
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;
using P = pair<LL, LL>;

struct Comp
{
	bool operator()(const P& p1, const P& p2)const
	{
		if (p1.second == p2.second)return p1.first < p2.first;
		return p1.second < p2.second;
	}
};

vector<P>vec, pv, qv;//PQ平面
map<P, int>rev;
set<P>ps;
set<P, Comp>qs;

LL dist;

int deg[114514] = {};

bool flag[114514] = {};
void dfs(int x)
{
	flag[x] = true;
	ps.erase(vec[x]);
	qs.erase(vec[x]);
	LL p = vec[x].first;
	LL q = vec[x].second;
	//lef
	for (;;)
	{
		auto itr = ps.lower_bound(P(p - dist, q - dist));
		if (itr != ps.end() && itr->first == p - dist && itr->second <= q + dist)
		{
			int nxt = rev[*itr];
			dfs(nxt);
		}
		else
		{
			break;
		}
	}
	//rht
	for (;;)
	{
		auto itr = ps.lower_bound(P(p + dist, q - dist));
		if (itr != ps.end() && itr->first == p + dist && itr->second <= q + dist)
		{
			int nxt = rev[*itr];
			dfs(nxt);
		}
		else
		{
			break;
		}
	}
	//dwn
	for (;;)
	{
		auto itr = qs.lower_bound(P(p - dist, q - dist));
		if (itr != qs.end() && itr->second == q - dist && itr->first <= p + dist)
		{
			int nxt = rev[*itr];
			dfs(nxt);
		}
		else
		{
			break;
		}
	}
	//upp
	for (;;)
	{
		auto itr = qs.lower_bound(P(p - dist, q + dist));
		if (itr != qs.end() && itr->second == q + dist && itr->first <= p + dist)
		{
			int nxt = rev[*itr];
			dfs(nxt);
		}
		else
		{
			break;
		}
	}
}

int N, a, b;

int main(void)
{
	//入力
	cin >> N >> a >> b;
	--a; --b;
	for (int i = 0; i < N; ++i)
	{
		LL xx, yy;
		cin >> xx >> yy;
		LL pp = xx + yy;
		LL qq = xx - yy;
		vec.push_back({ pp,qq });
		ps.insert({ pp,qq });
		qs.insert({ pp,qq });
		rev[vec.back()] = i;
	}
	dist = max(abs(vec[a].first - vec[b].first), abs(vec[a].second - vec[b].second));
	//適宜ソートをする
	pv = qv = vec;
	sort(pv.begin(), pv.end());
	sort(qv.begin(), qv.end(), Comp());
	//degを求める
	for (int i = 0; i < N; ++i)
	{
		LL p = vec[i].first;
		LL q = vec[i].second;
		int lef = upper_bound(pv.begin(), pv.end(), P(p - dist, q + dist))
			- lower_bound(pv.begin(), pv.end(), P(p - dist, q - dist));
		int rht = upper_bound(pv.begin(), pv.end(), P(p + dist, q + dist))
			- lower_bound(pv.begin(), pv.end(), P(p + dist, q - dist));
		int dwn = lower_bound(qv.begin(), qv.end(), P(p + dist, q - dist), Comp())
			- upper_bound(qv.begin(), qv.end(), P(p - dist, q - dist), Comp());
		int upp = lower_bound(qv.begin(), qv.end(), P(p + dist, q + dist), Comp())
			- upper_bound(qv.begin(), qv.end(), P(p - dist, q + dist), Comp());
		deg[i] = lef + rht + dwn + upp;
	}
	//DFSをする
	dfs(a);
	//答えはflagが立っている点の集合のdegの和
	LL ans = 0;
	for (int i = 0; i < N; ++i)
	{
		if (flag[i])
			ans += deg[i];
	}
	cout << ans / 2 << endl;
	return 0;
}


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

int main(int argc, char const *argv[])
{
	int n,m;
	int sum;
	cin >> n;
	vector<int> T(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> T.at(i);
		sum += T.at(i);
	}
	cin >> m;
	vector<int> P(m),X(m);
	for (int i = 0; i < m; ++i)
	{
		cin >> P.at(i) >> X.at(i);
		cout << sum - (T.at(P.at(i) - 1) - X.at(i)) << endl;
	}
	return 0;
}


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

using namespace std;

int main(){

int flg;
long i,j,n,ans=0,len;
string s[100000];
vector<string> lst;
vector<int> count;
unordered_map<string,int> mp;


cin >> n;

for(i=0;i<n;i++){
  cin >> s[i];
  sort(s[i].begin(),s[i].end());
  ans += mp[s[i]];
  mp[s[i]]++;
}

cout << ans << endl;

return 0;

}

Measured memory_bytes: 17572
while 1:
    a, op, b = input().split()
    if op == '?':
        exit()
    if op == '+':
        print(int(a)+int(b))
    if op == '-':
        print(int(a)-int(b))
    if op == '*':
        print(int(a)*int(b))
    if op == '/':
        print(int(a)//int(b))



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

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

  int answer;
  answer=0;
  
  
  for (int i=0;i<n-1;i++){
    int count=0;
    
    for (int j=0;j<26;j++){
      int flagf=0;
      int flagl=0;
      
      for (int k=0;k<=i;k++){
        if (s.at(k)==(char)('a'+j)){
          flagf=1;
          break;
        }
      }
      
        for (int k=i+1;k<n;k++){
        if (s.at(k)==(char)('a'+j)){
          flagl=1;
          break;
        }
      }
      
      count+=flagf*flagl;
    }
    
    answer=max(answer,count);
  }
  
    
    cout<<answer<<endl;
       
  
}

  













Measured memory_bytes: 256
import numpy as np
m = []
h, w = map(int, input().split())
for i in range(h):
    arr = list(input())
    if '#' in arr:
        m.append(arr)
    else:
        pass
m = np.array(m).T.tolist()
output = []
for i in range(w):
    if '#' in m[i]:
        output.append(m[i])
    else:
        pass
output = np.array(output).T.tolist()
for i in range(len(output)):
    print(''.join(output[i]))
    

Measured memory_bytes: 12628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

P parent(vi &vec, int v, int depth = 0) {
  if (vec[v] == v) return P(v, depth);
  return parent(vec, vec[v], depth + 1);
}

int main() {
  int N; cin >> N;
  Graph town_x(N, vi(2)), town_y(N, vi(2));
  rep(i,N) {
    cin >> town_x[i][0] >> town_y[i][0];
    town_x[i][1] = town_y[i][1] = i;
  }

  sort(all(town_x));
  sort(all(town_y));

  priority_queue<vi, vector<vi>, greater<vi>> pq;
  rep(i,N-1) {
    vi tmp(3);
    tmp[0] = town_x[i+1][0] - town_x[i][0];
    tmp[1] = town_x[i][1];
    tmp[2] = town_x[i+1][1];
    pq.push(tmp);
  }
  rep(i,N-1) {
    vi tmp(3);
    tmp[0] = town_y[i+1][0] - town_y[i][0];
    tmp[1] = town_y[i][1];
    tmp[2] = town_y[i+1][1];
    pq.push(tmp);
  }

  vi connect(N);
  rep(i,N) connect[i] = i;
  ll ans = 0;

  while (!pq.empty()) {
    auto dist = pq.top(); pq.pop();
    auto a = parent(connect, dist[1]);
    auto b = parent(connect, dist[2]);
    if (a.first == b.first) continue;
    ans += dist[0];
    if (a.second < b.second) connect[a.first] = b.first;
    else connect[b.first] = a.first;
  }

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


Measured memory_bytes: 23980
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cnt[26];
signed main(){
    string A;
    cin >> A;
    int N = A.size();
    int ans = (N*(N-1))/2;
    for(int i = 0; i < N; i++) {
        cnt[A[i]-'a']++;
    }
    for(int a:cnt) {
        ans -= (a*(a-1))/2;
    }
    cout << ans+1 << endl;
}

Measured memory_bytes: 3704