akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

ll root(ll x,vector<ll>& par){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = root(par[x],par);
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N,M;
    cin >> N >> M;
    vector<ll> p(N);
    REP(i,N){
        ll tmp;
        cin >> tmp;
        tmp--;
        p[i] = tmp;
    }
    vector<ll> par(N);
    REP(i,N)par[i] = i;
    REP(i,M){
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        ll rx = root(x,par);
        ll ry = root(y,par);
        if(rx != ry)par[rx] = ry;
    }
    ll count = 0;
    REP(i,N){
        if(root(p[i],par) == root(i,par))count++;
    }
    cout << count << "\n";
}

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

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int a, b, c, d; cin >> a >> b >> c >> d;
    bool win = true;
    for (int i = 1;; ++i)
    {
        if (i % 2 == 1)
        {
            c -= b;
            if (c <= 0)
            {
                win = true;
                break;
            }
        }
        else
        {
            a -= d;
            if (a <= 0)
            {
                win = false;
                break;
            }
        }
    }
    cout << (win ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3636
N, X = map(int, input().split())
Y = N - X

ans = N

while True:
	if X == Y:
		ans += X
		break
	else:
		if X > Y:
			tmp = X
			X = Y
			Y = tmp
		a = Y % X
		b = Y // X
		if a == 0:
			ans += (b*2 - 1) * X
			break
		else:
			ans += b*2*X
		Y = X
		X = a
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>

using namespace std;

int w,h,v,t,x,y,p,q;

long long sqr(long long ll){
  return ll*ll;
}

bool hit(int by,int bx){
  return sqr(h*by+((by&1)?h-y:y)-q)+sqr(w*bx+((bx&1)?w-x:x)-p)<=sqr(v*t);
}

int main(){
  cin>>w>>h>>v>>t>>x>>y>>p>>q;
  int i;
  for(i=-v*t/h-10;;i++){
    if(hit(i,-1)||hit(i,0)||hit(i,1))break;
    if(i==10){
      cout<<0<<endl;
      return 0;
    }
  }
  int l=-2,r=2;
  long long ans=0;
  for(;;i++){
    while(hit(i,l)){
      l--;
    }
    while(!hit(i,l+1)){
      l++;
      if(r-l==1){
	cout<<ans<<endl;
	return 0;
      }
    }
    while(hit(i,r)){
      r++;
    }
    while(!hit(i,r-1)){
      r--;
    }
    ans+=r-l-1;
  }
}

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

ll gcd(ll p, ll q){
    if(q==0) return p;
    else return gcd(q, p%q);
}

ll lcm(ll p, ll q){
    ll g = gcd(p, q);
    return p/g*q;
}

int main() {
    ll a, b;
    while(cin >> a >> b){
        cout << gcd(a,b) << " " << lcm(a,b) << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
/*
 */
#include <iostream>
#include <algorithm>

using namespace std;

int sosu[9692];
int sosuN;

int iN; // 0 <= N <= 100,000
int iP; // 1 <= P <= 100

int iM[5050];

void init() {
  int i, j;
  bool b[101198];

  sosuN = 0;
  fill(b, b + 101198, true);
  b[0] = false;
  b[1] = false;

  for (i = 2; i < 101198; i++) {
    if (b[i]) {
      sosu[sosuN++] = i;
      for (j = 2; i * j < 101198; j++) {
        b[i * j] = false;
      }
    }
  }
}

bool input() {
  scanf("%d %d", &iN, &iP);
  if (iN == -1 && iP == -1) return false;
  return true;
}

void manage(){
  int i, j, k;
  int cnt = 0;
  int tmp;

  for (i = 0; i < sosuN; i++) {
    if (sosu[i] > iN) break;
  }

  for (j = 0; j < iP; j++) {
    for (k = j; k < iP; k++) {
      iM[cnt++] = sosu[i + j] + sosu[i + k];
    }
  }

  for (j = 0; j < iP; j++) {
    for (k = cnt - 1; k > j; k--) {
      if (iM[k - 1] > iM[k]) {
        tmp = iM[k];
        iM[k] = iM[k - 1];
        iM[k - 1] = tmp;
      }
    }
    //printf("%d\n", iM[j]);
  }
}

void output(){
  printf("%d\n", iM[iP - 1]);
}

int main() {
  init();
  while(1) {
    if (!input()) break;
    manage();
    output();
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define reg register
	#define Rint register int
	#define FOR(i,a,b) for(register int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
	#define FORit(templ,arr,i,a,b) for(register templ *i=(arr)+(a);i!=(arr)+(b)+1;++i)
	#define ROFit(templ,arr,i,a,b) for(register templ *i=(arr)+(a);i!=(arr)+(b)-1;--i)
	#define GO(x,p,e,i,v) for(register int i=p[x].head,v;i;i=e[i].link)
	#define MEM(x,v) memset(x,v,sizeof(x))
	#define fir first
	#define sec second
	#define pq priority_queue
	#define PII pair<int,int>
	#define MP make_pair
	typedef long long LL;
	typedef double DB;
	inline int read(){
		int ans=0,f=1;char c=getchar();
		while(!isdigit(c)){ f^=(c=='-'); c=getchar(); }
		for(;isdigit(c);c=getchar()) ans=(ans<<1)+(ans<<3)+(c^48); return f?ans:-ans;
	}
	const int mod = 998244353 , N = 100010;
	inline void inc(int &x,const int &y){ x+=y; if(x>=mod) x-=mod; }
	inline int ksm(int x,LL y){ int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res;}
	inline int gcd(int x,int y){ if(x<y) swap(x,y); return y?gcd(y,x%y):x; }
	#define FILE(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
}
using namespace my_std;

int n,m,x[N],pos[N],vis[N];
LL k , ans[N];
int stk[N] , top;

int main(){
	n = read();
	FOR(i,1,n) x[i] = read() , pos[i] = i;
	ROF(i,n,1) x[i] -= x[i - 1];
	m = read() , scanf("%lld",&k);
	Rint xx;
	FOR(i,1,m) xx = read() , swap(pos[xx] , pos[xx + 1]);
	FOR(i,1,n){
		if(!vis[i]){
			for(Rint j = i;!vis[j];j = pos[j]) vis[stk[top++] = j] = 1;
			FOR(j,0,top - 1) ans[stk[j]] = x[stk[(j + k) % top]];
			top = 0;
		}
	}
	FOR(i,1,n) ans[i] += ans[i - 1] , printf("%lld.0\n",ans[i]);
	return 0;
}//神luogu怎么知道我刚做了这个啊啊啊啊

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

int main()
{
  int a,b;
  cin>>a>>b;
  int cn=1;
  int ans=0;
  while(cn<b)
  {
  	cn-=1;
  	cn+=a;
  	ans++;
  }
 cout<<ans<<endl; 
}

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

using ll = long long;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	ll k;
	cin >> n >> k;
	vector<ll> a(n);
	for(ll i = 0; i < n; i++) cin >> a[i];
	vector<ll> b = a;
	b.insert(b.end(), a.begin(), a.end());
	vector<ll> jump(n);
	map<ll,ll> z;
	for(ll i = 2*n-1; i >= 0; i--){
		if(i < n) jump[i] = z[b[i]] - i + 1;
		z[b[i]] = i;
	}
	ll maxlen = n * k;

	const ll MAXJ = 64;
	vector<vector<ll> > jumplen(MAXJ, vector<ll>(n));
	for(ll i = 0; i < n; i++){
		jumplen[0][i] = jump[i];
	}
	for(ll j = 1; j < MAXJ; j++){
		for(ll i = 0; i < n; i++){
			jumplen[j][i] = jumplen[j-1][i] + jumplen[j-1][(i + jumplen[j-1][i]) % n];
			if(jumplen[j][i] > maxlen) jumplen[j][i] = maxlen + n + jumplen[j][i] % n;
		}
	}
	ll need = maxlen;
	ll cur = 0;
	for(ll j = MAXJ - 1; j >= 0; j--){
		while(need >= jumplen[j][cur]){
			need -= jumplen[j][cur];
			cur = (cur + jumplen[j][cur]) % n;
		}
	}
	cur = n - need;
	vector<ll> ans;
	map<ll,ll> freq;
	for(ll i = cur; i < n; i++){
		ll x = a[i];
		if(freq[x] > 0){
			while(freq[x] > 0){
				freq[ans.back()] -= 1;
				ans.pop_back();
			}
		} else {
			ans.push_back(x);
			freq[x] += 1;
		}
	}
	for(ll r : ans){
		cout << r << ' ';
	}
	cout << '\n';
}

Measured memory_bytes: 134372
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

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

    ll n;
    cin >> n;

    vector<ll> p(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> p[i];
    }


    ll ans = 1;
    ll min = p[0];
    for (ll i = 1; i < n; ++i)
    {
        if (min >= p[i]) {
            ans++;
        }
        if (min > p[i]) {
            min = p[i];
        }
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>

int arr1[100005];
int arr2[50005];

int main() {
  int n, i, q, cur, index, num, total = 0;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &arr1[i]);
  }

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    scanf("%d", &arr2[i]);
  }

  int left, right;
  int counter = 0;

  for (i = 0; i < q; i++) {
    cur = arr2[i];
    left = 0;
    right = n - 1;

    while (left <= right) {
      index = (left + right) / 2;
      num = arr1[index];

      //printf("S num: %d, T num: %d, index: %d\n", num, cur, index);

      if (num == cur) {
        total++;
        break;
      }
      if (cur > num)
        left = index + 1;
      else
        right = index - 1;

      if (index <= 0) {
        if (cur == arr1[0])
          total++;
        break;
      }

      if (index >= n - 1) {
        if (cur == arr1[n - 1])
          total++;
        break;
      }
    }
  }

  printf("%d\n", total);
}



Measured memory_bytes: 2372
mod=998244353
n,s=map(int,input().split())
a=list(map(int,input().split()))
dp=[[0]*(s+1) for _ in range(n+1)]
dp[0][0]=1
for i in range(n):
	for j in range(s+1):
		dp[i+1][j]+=2*dp[i][j]
		dp[i+1][j]%=mod
		if j+a[i]<=s:
			dp[i+1][j+a[i]]+=dp[i][j]
			dp[i+1][j+a[i]]%=mod
print(dp[n][s])

Measured memory_bytes: 139044
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#include <vector>
#include <cstring>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <map>
#include <stack>
#include <cmath>
#define LL long long 
using namespace std; 
 
int a[200005],f[200005]; 
int n;

bool cmp(int a,int b)
{
	return a>b;
} 

bool check(long long x,long long k)
{
	long long res=0;
	for(int i=1;i<=n;i++)
		res+=max(a[i]-x/f[i],(LL)0);
	return res<=k;
}
 
int main()
{
	long long k;
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&f[i]);
	sort(f+1,f+n+1,cmp);
	sort(a+1,a+n+1);
	long long l=0,r=(LL)1e12;
	while(l<r)
	{
//		cout<<l<<" "<<r<<endl;
		LL mid=(l+r)/2;
		if(check(mid,k))
			r=mid;
		else
			l=mid+1;
	}	
	cout<<r<<endl;
} 


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
dp = [0 for i in range(N)]
dp[0] = 0
dp[1] = abs(A[1]-A[0])
for i in range(2,N):
    dp[i] = min( abs(A[i]-A[i-2]) + dp[i-2] , abs(A[i]-A[i-1]) + dp[i-1])
print(dp[N-1])

Measured memory_bytes: 13928
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

void gcl(int& x,int& y){
    if(x<y) swap(x,y);
    while(y>0){
        int t=x%y;
        x=y;
        y=t;
    }
    return;
}

int main(){
    int n,k;cin>>n>>k;
    int ans=0;
    n=n-k;ans++;
    ans+=(n+k-2)/(k-1);
    cout<<ans<<endl;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	int n, out_count = 0;

	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i += 2)
	{
		out_count++;
		cout << a[n - 1 - i];
		if (out_count < n)
			cout << " ";
		else
			cout << endl;
	}
	for (int i = n % 2; i < n; i += 2)
	{
		out_count++;
		cout << a[i];
		if (out_count < n)
			cout << " ";
		else
			cout << endl;
	}
}


Measured memory_bytes: 4116
I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=(a,c),;Y+=c,;X+=a
for i in r(m):a,*b=I();H+=(a,b),;X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)
h,s,K=g(X);w,t,L=g(Y);j=lambda:[[0]*-~K for i in r(L+1)];V=j();U=j();v=j()
for(a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]-=1
for d,(e,f)in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]-=1
for i in r(L):
 for j in r(K):U[i][j+1]+=U[i][j];V[i+1][j]+=V[i][j]
q=[(h[0],w[0])];v[w[0]][h[0]]=1;a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in(-1,0),(1,0),(0,1),(0,-1),:
  c=x+e;d=y+f
  if 1-v[d][c]and(U[(f>0)+y][x]|e==0)|(V[y][(e>0)+x]|f==0):q+=[(c,d)];v[d][c]=1
print([a,'INF'][a>F])

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

int main() {
	int N;
	cin >> N;
	vector<int> X(N);
	int mid = 0;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		mid += tmp;
		X.at(i) = tmp;
	}
	mid /= N;
	int dist1 = 0, dist2 = 0;
	for (int i = 0; i < N; i++) {
		dist1 += (X.at(i) - mid) * (X.at(i) - mid);
		dist2 += (X.at(i) - (mid + 1)) * (X.at(i) - (mid + 1));
	}
	if (dist1 < dist2) {
		cout << dist1 << endl;
	} else {
		cout << dist2 << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if((a+b)%2==0){
		printf("%d\n",(a+b)/2);
	}
	else{
		printf("%d\n",((a+b)/2)+1);
	}
	return 0;
}


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

using namespace std;

int main(void)
{
    int N;
    long long int A[100000];

    cin >> N;
    bool flag = false;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] == 0)   flag = true;
    }
    if(flag == true){
        cout << 0 << endl;
        return 0;
    }

    long long int mult = 1;
    for(int i = 0; i < N; i++){
        if(A[i] <= 1000000000000000000 / mult){
            mult *= A[i];
        }
        else{
            cout << "-1" << endl;
            return 0;
        }
    }

    cout << mult << endl;

    return 0;
}

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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    bool flag=true;
    if(n%2>0)flag=false;
    else{
        for(int i=0;2*i<s.size();i++){
            if(s[i]!=s[s.size()/2+i])flag=false;
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

namespace ARC084
{
    class C
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] A = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            long[] B = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            long[] C = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();

            long res = 0;
            for (int i = 0; i < N; i++)
            {
                long indexA = Array.BinarySearch(A, B[i]);
                indexA = LowerBound(A, B[i]);

                long indexC = Array.BinarySearch(C, B[i]);
                indexC = N - UpperBound(C, B[i]);
                res += indexA * indexC;
            }
            Console.WriteLine(res);
        }

        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }

        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }

    }
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli n;
	lli a,b;
	cin>>n>>a>>b;

	lli aCnt=0;
	lli bCnt=0;

	string s;
	cin>>s;

	for(lli i=0;i<n;i++){
		if(s.at(i)=='a'){
			if(aCnt+bCnt<a+b){
				aCnt++;
				cout<<"Yes"<<endl;
			}
			else{
				cout<<"No"<<endl;
			}
		}
		else if(s.at(i)=='b'){
			if(aCnt+bCnt<a+b && bCnt<b){
				bCnt++;
				cout<<"Yes"<<endl;
			}
			else{
				cout<<"No"<<endl;
			}
		}
		else{
			cout<<"No"<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>pos[21];
ll inp[100];
map<ll,ll>mp;
vector<ll>points;
vector<ll>::iterator upper1, upper2;
int main()
{
  ll i,j,k,l,t,n,x=0,y=0,p,q,z=0;
  cin>>n;
  for(i=0;i<n;i++)
    {
      cin>>p;
      points.push_back(p);	
    }
    for(i=0;i<n;i++)
    {
       for(j=i+1;j<n;j++)
       {
        x=x+points[i]*points[j];	
       }	
    }
    cout<<x;
  
  
     
     
     	
  	
}

Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
const int N=200000+10;
int n,dp[N][3],a[N],b[N],c[N];
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
    dp[1][0]=a[1];
	dp[1][1]=b[1];
	dp[1][2]=c[1];
	for(int i=2;i<=n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<"\n";
    return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = Integer.parseInt(scanner.nextLine());
		
		for(int i = 0; i < n; i++) {
			String time = scanner.nextLine();
			int hour = Integer.parseInt(time.substring(0, 2));
			int min = Integer.parseInt(time.substring(3, 5));
			double rad_min = 6.0 * min;
			double rad_hour = 30.0 * hour + 30.0 * min / 60.0;
			
			double rad = Math.abs(rad_min - rad_hour);
			if (rad > 180) {rad = 360 - rad;}
			
			if (rad < 30.0) {
				System.out.println("alert");
			} else if (rad >= 90.0) {
				System.out.println("safe");
			} else {
				System.out.println("warning");
			}
		}
	}
}

Measured memory_bytes: 23336
import math

n, k = input().split()

n = int(n)
k = int(k)

total_p = 0

for i in range(n):
    i = i + 1  # i = 1 ~ n
    if k <= i:
        total_p += 1
    else:
        ntimes = math.ceil(math.log2(k / i))
        total_p += 1 / (2**ntimes)

p = total_p / n

print('{:.12f}'.format(p))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  string s,s1="",s2="";
  int q;
  cin >> s >> q;
  bool flag = true;
  rep(i,q){
    int t;
    cin >> t;
    if(t == 1){
      if(flag){
        flag = false;
      }else{
        flag = true;
      }
    }else{
      int f;
      string c;
      cin >> f >> c;
      if(f == 1 && flag || f == 2 && !(flag)){
        s1 += c;
      }else{
        s2 += c;
      }
    }
  }
  if(flag){
    reverse(s1);
    cout << s1 + s + s2 << endl;
    return 0;
  }else{
    reverse(s);
    reverse(s2);
    cout << s2 + s + s1 << endl;
    return 0;
  }
}

Measured memory_bytes: 1348
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main() {
	int k;
	cin >> k;
	string ans;
	rep(i, k)
		ans += "ACL";
	cout << ans << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>

int main(void) {
	int h, w, n;

	std::cin >> n >> h >> w;

	std::cout << (n - h + 1) * (n - w + 1) << std::endl;

	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<int64_t> P(A), Q(B), R(C);
  for (int i = 0; i < A; i++) {
    cin >> P[i];
  }
  for (int i = 0; i < B; i++) {
    cin >> Q[i];
  }
  for (int i = 0; i < C; i++) {
    cin >> R[i];
  }
  sort(P.begin(), P.end(), greater<int>());
  sort(Q.begin(), Q.end(), greater<int>());
  sort(R.begin(), R.end(), greater<int>());
  priority_queue<int64_t, vector<int64_t>, greater<int64_t>> que;
  for (int i = 0; i < X; i++) {
    que.push(P[i]);
  }
  for (int i = 0; i < Y; i++) {
    que.push(Q[i]);
  }
  for (int i = 0; i < C; i++) {
    if (R[i] > que.top()) {
      que.pop();
      que.push(R[i]);
    }
  }
  int64_t res = 0;
  while (!que.empty()) {
    res += que.top();
    que.pop();
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 4852
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string W[100];
    int N;
    char end;
    bool flag = true;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> W[i];
    }

    end = W[0][W[0].size()-1];
    for (int i = 1; (i < N && flag == true); i++) {
        if (end != W[i][0]) {
            flag = false;
        }
        end = W[i][W[i].size()-1];
        for (int j = 0; (j < i && flag == true); j++) {
            if (W[i] == W[j]) {
                flag = false;
            }
        }
    }

    cout << (flag? "Yes":"No") << endl;
}

Measured memory_bytes: 256
#include <iostream>

char a[3];
int count = 0;
int main()
{
	for(int i = 0; i < 4; i++)
	{

		std::cin >> a[i];
		if(a[i] == '+')
		{
			count++;
		}else
		{
			count--;
		}
	}
	std::cout << count;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	int n, m;
	cin >> n>> m;
	if (n == m)
		printf("Yes");
	else
		printf("No");

	//printf("%d", r);
	return 0;
}


Measured memory_bytes: 888
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue> 
#define P pair<int ,int >
#define pb push_back
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
#define int LL
using namespace std;
const int N   = 5e5+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();

#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

char s[N];
int n,cnt,ans;
signed main()
{
	scanf( "%s",s+1);
	n=strlen(s+1);
	rep(i,1,n)
	{
		if (s[i]=='B') ++cnt;
		else ans+=cnt;
	}
	printf("%lld",ans);
	
	return 0;
}

    
    

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    ll N,K;string S;
    cin>>N>>K>>S;
    S.push_back('.');

    ll cnt = 0;
    rep(i,N){
        if(i == N-1)continue;
        if(S[i]!=S[i+1]){
            cnt++;
        }
    }
    cerr<<cnt<<endl;
    ll kyoukai = cnt - K*2;
    cerr<<kyoukai<<endl;
    if(kyoukai<0){
        cout<<N-1<<endl;
        return 0;
    }
    ll ans = N - kyoukai-1;
    cout<<ans<<endl;
}

Measured memory_bytes: 512
from collections import deque


def solve():
    players = [deque(input()), deque(input()), deque(input())]
    # print(players)

    dc = ord('a')
    i = 0
    while True:
        cards = players[i]

        if len(cards) == 0:
            return i

        card = cards.popleft()
        i = ord(card) - dc


if __name__ == '__main__':
    res = solve()
    print(chr(res + ord('A')))


Measured memory_bytes: 38256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  NK := NextIntVec()
  N := NK[0]
  A := NextIntVec()
  D := make([][]int, 200001)
  for i := range D {
    D[i] = make([]int, 0)
  }
  H := make([]int, N)
  for i, a := range A {
    D[a] = append(D[a], i)
  }
  for i, _ := range D {
    for j := 0; j < len(D[i]); j++ {
      next := (j + 1) % len(D[i])
      H[D[i][j]] = D[i][next]
    }
  }
  k := 1
  for v := 0 ; v < N; v++ {
    if H[v] <= v {
      k += 1
      if NK[1] < k { break }
    }
    v = H[v]
  }
  K := NK[1] % k
  v := 0
  for ; K > 0; v++ {
    if H[v] <= v {
      K -= 1
      if K == 0 { break }
    }
    v = H[v]
  }
  S := make([]string, 0)
  for ; v < N; v++ {
    if H[v] <= v {
      S = append(S, strconv.Itoa(A[v]))
    } else {
      v = H[v]
    }
  }
  Write(strings.Join(S, " "))
  Output()
}

Measured memory_bytes: 24448
#include<bits/stdc++.h>
using namespace std;
template<typename T = int>T in() { T x; cin >> x; return x; }
#define REP(i,n) for(int i=0;i<(n);++i)
#define _REP(i,n)for(int i=1;i<=(n);++i)
int main()
{
	while (true)
	{
		char m[14][14];
		REP(i, 14)REP(j, 14)m[i][j] = '0';
		_REP(i, 12)_REP(j, 12)
		{
			m[i][j] = in<char>();
			if (cin.eof())
			{
				return 0;
			}
		}
		int count = 0;
		set<pair<int, int>>s;
		_REP(i, 12)
		{
			_REP(j, 12)
			{
				if (m[i][j] == '1')
				{
					s.insert(make_pair(i, j));
					while (s.size() != 0)
					{
						int y = s.begin()->first, x = s.begin()->second;
						s.erase(s.begin());
						m[y][x] = '0';
						if (m[y - 1][x] == '1')s.insert(make_pair(y - 1, x));
						if (m[y][x - 1] == '1')s.insert(make_pair(y, x - 1));
						if (m[y + 1][x] == '1')s.insert(make_pair(y + 1, x));
						if (m[y][x + 1] == '1')s.insert(make_pair(y, x + 1));
					}
					count++;
				}
			}
		}
		cout << count << endl;
	}
}


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n, k;
    cin >> n >> k;
    map<i64, i64> ab;
    for (i64 i = 0; i < n; i++) {
        i64 a, b;
        cin >> a >> b;
        ab[a] += b;
    }

    i64 ans = 0;
    for (auto& e : ab) {
        i64 a, b;
        tie(a, b) = e;
        if (!(a & ~k)) ans += b;
    }

    for (i64 i = 0; i < 30; i++) {
        if (!((k >> i) & 1)) continue;
        i64 can = 0;
        i64 l = (k & ~(1 << i)) | ((1 << i) - 1);
        for (auto& e : ab) {
            i64 a, b;
            tie(a, b) = e;
            if (!(a & ~l)) can += b;
        }
        ans = max(ans, can);
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 6528
def valid(i)
  T.size.times do |j|
    if S[i+j] == T[j] || S[i+j] == "?"
      next
    else
      return false
    end
  end
  return true
end
S = gets.chomp
T = gets.chomp
mem = []
0.upto(S.size-T.size) do |i|
  if valid(i)
    mem.push(i)
  end
end
if mem == []
  puts "UNRESTORABLE"
else
  i = mem.last
  S[i..(i+T.size-1)] = T
    0.upto(S.size-1) do |j|
      S[j] = "a" if S[j] == "?"
    end
  puts S
end

Measured memory_bytes: 1788
#include <stdio.h>
int main(void) {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF) {
    double st, tt, ut;
    int s, t, u;
    x1 -= xp, x2 -= xp, x3 -= xp;
    y1 -= yp, y2 -= yp, y3 -= yp;
    //printf("%f %f %f %f %f %f\n", x1, y1, x2, y2, x3, y3);
    st = x1 * y2 - x2 * y1;
    if(!st) {
      printf("NO\n");
      continue;
    }
    s = st < 0 ? 0 : 1;
    tt = x2 * y3 - x3 * y2;
    if(!tt) {
      printf("NO\n");
      continue;
    }
    t = tt < 0 ? 0 : 1;
    ut = x3 * y1 - x1 * y3;
    if(!ut) {
      printf("NO\n");
      continue;
    }
    u = ut < 0 ? 0 : 1;
    //printf("%d %d %d\n", s, t, u);
    if(s == t && t == u) printf("YES\n");
    else printf("NO\n");
  }
}


Measured memory_bytes: 2724
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    while 1:
        n=II()
        if n==0:break
        aa=[II() for _ in range(n)]
        aa.sort()
        print(sum(aa[1:n-1])//(n-2))

main()



Measured memory_bytes: 6032
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r))

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;
string s;
int a=0,b;
stack<char> st;

signed main(){
    io();
    in(n,s);
    
    for(auto e:s){
        if(e=='('){
            st.push(e);
        }else{
            if(!st.empty()){
                st.pop();
            }else{
                a++;
            }
        }
    }
    b=st.size();

    //show(a,b);
    rep(i,a) s.insert(s.begin(), '(');
    rep(i,b) s.insert(s.end(), ')');

    out(s);

    return 0;
}


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

int main(void){
  int x,n;
  cin>>x>>n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
  }
  
  int lans=-1000;
  int uans=1000;
  int l,u;
  l=x;
  u=x;
  int tmp;
  
  bool is_exist=false;
  //lower
  while(l>=0){
    is_exist=false;
    for(int k=0;k<n;k++){
      tmp=p.at(k);
      if(tmp==l){
        is_exist=true;
      }
    }
    if(!is_exist){
      lans=l;
      break;
    }
    l--;
  }
  
  //upper
  while(u<=101){
    is_exist=false;
    for(int k=0;k<n;k++){
      tmp=p.at(k);
      if(tmp==u){
        is_exist=true;
      }
    }
    if(!is_exist){
      uans=u;
      break;
    }
    u++;
  }
  
  
  auto diff1=x-lans;
  auto diff2=uans-x;
  
  if(diff1<=diff2) cout<<lans<<endl;
  else cout<<uans<<endl;
  
  return 0;
}

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


int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(d==1)cout<<1<<endl;
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<ll> v;
void dfs(int k, ll x){
	v.push_back(x);
	if(k>=9) return;
	int a=x%10;
	if(a){
		dfs(k+1, x*10+a-1);
	}
	dfs(k+1, x*10+a);
	if(a<9){
		dfs(k+1, x*10+a+1);
	}
}
int main()
{
	for(int i=1; i<=9; i++) dfs(0, i);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int k; cin>>k;
	cout<<v[k-1]<<endl;
	return 0;
}


Measured memory_bytes: 2420
from collections import defaultdict
d = defaultdict(list)

el = int(input())

for ei in range(1,el+1):
    s,p = input().split()
    p = int(p)
    d[s] = d[s] + [(p,ei)]

d = list(d.items())
d.sort(key=lambda spei: spei[0])
for spei in d:
    peis = spei[1]
    peis.sort(key=lambda pei: -pei[0])
    for pei in peis:
        print(pei[1])

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

int main()
{
    string S, T;
    cin >> S >> T;
    auto N = S.size();
    map<char, int> used_S, used_T;
    vector<int> S2(N, -1);
    vector<int> T2(N, -1);
    for(int i=0; i<N; i++){
        auto cS = S[i];
        if(!used_S.count(cS)){
            used_S[cS] = used_S.size();
        }
        S2[i] = used_S[cS];

        auto cT = T[i];
        if(!used_T.count(cT)){
            used_T[cT] = used_T.size();
        }
        T2[i] = used_T[cT];
    }
    if(equal(S2.begin(), S2.end(), T2.begin())){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 2312
<?php
$n = intval(fgets(STDIN));
$str = trim(fgets(STDIN));
$Q = intval(fgets(STDIN));

$seg = new SegTree($n);
function op($a, $b){return $a | $b;}

for($i = 0; $i < $n; $i++){
  $seg->set($i, 1<<(ord($str[$i])-97));
}
while($Q--){
  list($q, $a, $b) = explode(" ", trim(fgets(STDIN)));
  if($q == "1"){
    $seg->set($a-1, 1<<(ord($b)-97));
  }else{
    $ret[] = popcount($seg->get($a-1, $b));
  }
}
echo implode("\n", $ret);


class SegTree{
  public $tree;
  public $bits;
  function __construct($n){
    $this->bits = max(1, ceil(log($n)/log(2)));
    for($i = 0; $i < $this->bits; ++$i){
      $this->tree[$i] = array_fill(0, 2**($this->bits-$i), 0);
    }
  }
  function set($i, $amount){
    $this->tree[0][$i] = $amount;
    for($j = 1; $j < $this->bits; ++$j){
      $this->tree[$j][$i>>$j] = op($this->tree[$j-1][$i>>$j<<1], $this->tree[$j-1][($i>>$j<<1) + 1]);
    }
  }
  function get($f, $t){
    $sum = 0;
    $tree = $this->tree;
    for($i = 0; $i < $this->bits ; ++$i){
      $treei = $tree[$i];
      $ff = $f>>$i+1<<$i+1;
      if($f!=$ff){
        $sum = op($sum, $treei[$f>>$i]);
        $f+=1<<$i;
      }
      $tt = $t>>$i+1<<$i+1;
      if($t!=$tt){
        $sum = op($sum, $treei[($t>>$i)-1]);
        $t-=1<<$i;
      }
      if($f==$t)break;
    }
    return $sum;
  }
}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}


Measured memory_bytes: 39544
from bisect import bisect_left
n=int(input())
a=list(map(int,input().split()))
bl=[0]
for i in a:bl.append(bl[-1]+i)
br=[0]
for i in a[::-1]:br.append(br[-1]+i)
def fl(r):
  suma=bl[r+1]
  ir=bisect_left(bl,suma//2)
  ans11,ans12=bl[ir],suma-bl[ir]
  ans21,ans22=bl[ir-1],suma-bl[ir-1]
  if abs(ans11-ans12)<abs(ans21-ans22):return[ans11,ans12]
  else:return[ans21,ans22]
def fr(l):
  r=(n-1)-l
  suma=br[r+1]
  ir=bisect_left(br,suma//2)
  ans11,ans12=br[ir],suma-br[ir]
  ans21,ans22=br[ir-1],suma-br[ir-1]
  if abs(ans11-ans12)<abs(ans21-ans22):return[ans11,ans12]
  else:return[ans21,ans22]
ans=10**20
for i in range(1,n-1):
  l=i
  r=i+1
  ll,lr=fl(i)
  rl,rr=fr(i+1)
  ans=min(ans,max(ll,lr,rl,rr)-min(ll,lr,rl,rr))
print(ans)

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

int main(){
	int X, Y;
	cin >> X >> Y;

	string ans = "No";
	for(int i=0;i<=X;i++){
		if((4*X-2*i) == Y) ans = "Yes";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    int c = b - a;

    int d = (c * (c + 1)) / 2;

    System.out.println(d - b);

  }
}

Measured memory_bytes: 23892
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, k;
llint a[55][55];
llint b[55][55];

void id(llint dest[55][55])
{
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i == j) dest[i][j] = 1;
			else dest[i][j] = 0;
		}
	}
}

void mul(llint a[55][55], llint b[55][55], llint c[55][55])
{
	int tmp[55][55];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			tmp[i][j] = 0;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				tmp[i][j] += a[i][k]*b[k][j]%mod;
				tmp[i][j] %= mod;
			}
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			c[i][j] = tmp[i][j];
		}
	}
}

void matpow(llint a[55][55], llint n, llint dest[55][55])
{
	if(n == 0) id(dest);
	else{
		if(n % 2){
			llint tmp[55][55];
			matpow(a, n-1, tmp);
			mul(tmp, a, dest);
		}
		else{
			llint tmp[55][55];
			matpow(a, n/2, tmp);
			mul(tmp, tmp, dest);
		}
	}
}


int main(void)
{
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}
	
	matpow(a, k, b);
	
	llint ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			ans += b[i][j], ans %= mod;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3072
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/floor.hpp
#ifndef FLOOR_HPP
#define FLOOR_HPP


/*
usage:

tools::floor(5, 3) // => 1 (i.e., floor(5 / 3))
*/

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

int main() {
  i64 K;
  std::cin >> K;
  std::vector<i64> A;
  tools::read(A, K);

  std::reverse(A.begin(), A.end());
  std::pair<i64, i64> answer = std::make_pair(2, 2);
  for (const i64& A_i : A) {
    const i64 l = tools::ceil<i64>(answer.first, A_i);
    const i64 u = tools::floor<i64>(answer.second, A_i);
    if (l > u) {
      std::cout << -1 << std::endl;
      return 0;
    }
    answer = std::make_pair(l * A_i, (u + 1) * A_i - 1);
  }

  std::cout << answer.first << ' ' << answer.second << std::endl;
  return 0;
}

Measured memory_bytes: 1024
from collections import deque
s = input()
g = deque()
p = deque()
for i in range(len(s)):
    if s[i] == "\\":
        g.append(i)
    elif s[i] == "/":
        a = 0
        if len(g) > 0:
            while True:
                if len(p) > 0 and p[-1][0] > g[-1]:
                    a += p[-1][1]
                    p.pop()
                else:
                    break
            a += i - g[-1]
            p.append([g[-1], a])
            g.pop()
for i in range(len(p)):
    p[i] = p[i][1]
if len(p) > 0:
    print(sum(p))
    print(len(p), end = " ")
    print(" ".join(map(str, p)))
else:
    print(0)
    print(0)


Measured memory_bytes: 6564
def rec(i,j)
  @m[i][j]=0
  rec(i,j+1) if j<11 and @m[i][j+1]==1
  rec(i,j-1) if j>0 and @m[i][j-1]==1
  rec(i+1,j) if i<11 and @m[i+1][j]==1
  rec(i-1,j) if i>0 and @m[i-1][j]==1
end
loop do
  @m,c,t=[],0,12
  t.times{@m<<gets.split("").map(&:to_i)}
  t.times{|i|
    t.times{|j|
      if @m[i][j]==1
        rec(i,j);c+=1
      end
    }
  }
  p c
  break if !gets
end

Measured memory_bytes: 8792
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner input= new Scanner(System.in);
		String S=input.next();
		//System.out.println(S);
		//if(S=="AAA") ←　数値のみ有効 
		if("AAA".equals(S)||"BBB".equals(S)) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}
	}

}


Measured memory_bytes: 21840
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    for(int i = 1;i<=9;i++){
        if(n%i==0 && i<=n && n<=9*i){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256