akhauriyash/Code-Regression huggingface dataset:
// SeptEtavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define re register
#define ll long long
#define il inline
#define rep(i,s,t) for(re int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(re int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define pt(ch) putchar(ch)
#define pti(x) printf("%d",x)
#define ptll(x) printf("%lld",x)
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
using namespace std;
// c_ints
il int ci(){
	re char ch;int f=1;
	while(!isdigit(ch=getchar()))f= ch=='-'?-1:1 ;
	re int x= ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}
enum{N=100024};
int fa[N],dis[N];
void fd(int x){
	if( fa[x]==x ) return ;
	fd(fa[x]);
	dis[x]+= dis[fa[x]];
	fa[x]= fa[fa[x]];
}
int main(){
	int n=ci(), m=ci();
	rep(i,1,n) fa[i]= i;
	while( m-- ){
		int l=ci(), r=ci(), d=ci();
		fd(l), fd(r);
		if( fa[l]==fa[r] ){
			if( dis[r]-dis[l]!=d ){
				puts("No");
				return 0;
			}
		}
		else{
			int fl=fa[l], fr=fa[r];
			int x= dis[l]+d-dis[r];
//			printf("%d %d\n",fl,fr);
//			if( x<0 ){
//				puts("No");
//				return 0;
//			}
			dis[fr]= x;
			fa[fr]= fl;
		}
//		printf("fa :");rep(i,1,n) printf("%d ",fa[i]); pt('\n');
//		printf("dis:");rep(i,1,n) printf("%d ",dis[i]); pt('\n');
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1024
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M 1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}
ll res[10005]={0};
int main()
{
    ll i,j,k;
    ll N;
    cin>>N;
    for(i=1;i*i<=N;i++)
    {
        for(j=1;j*j<=N;j++)
        {
            for(k=1;k*k<=N;k++)
            {
                ll p=i*i+j*j+k*k+i*j+j*k+k*i;
                if(p<=N)
                res[p]++;
            }
        }
    }
    for(i=1;i<=N;i++)
        cout<<res[i]<<"\n";
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define ll long long
#define MOD 1000000007

ll n, d, u[40][40],s[3][40],ans = INF;
int main() {
	cin >> n >> d;
	REPO(i, d) REPO(j, d)cin >> u[i][j];
	REPO(i, n) {
		REPO(j, n) {
			ll a; cin >> a;
			s[(i + j) % 3][a]++;
		}
	}
	REPO(i, d) {
		REPO(j, d) {
			REPO(k, d) {
				if (i != j and j != k and k != i) {
					ll sum = 0;
					REPO(l, d)sum += s[0][l] * u[l][i];
					REPO(l, d)sum += s[1][l] * u[l][j];
					REPO(l, d)sum += s[2][l] * u[l][k];
					ans = min(ans, sum);
				}
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
MAX_N = 10 ** 5 + 10
if __name__ == "__main__":
    N,M = map(int, input().split())
    deg = [0] * MAX_N
    for x in range(M):
        a,b = map(int, input().split())
        deg[a] += 1
        deg[b] += 1
    for x in range(MAX_N):
        if (deg[x] % 2 != 0):
            print ("NO")
            exit()
    print ("YES")


Measured memory_bytes: 3828
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;
const int maxn = 100100;
int key[maxn];
int main()
{
    int n,m;
    cin>>n>>m;
    //memset(key,0,sizeof(key))
    int l=0,r=maxn;
    int x,y;
    while(m--)
    {
        cin>>x>>y;
        if(x>l)l=x;
        if(y<r)r=y;
        if(l>r)
        {
            cout<<'0'<<endl;
            return 0;

        }

    }
    cout<<r-l+1<<endl;


	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int a; cin >> a;
  cout << a+a*a+a*a*a << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>

int main(void)
{
	int m, n, a, s, hs;
	int i, j;

	scanf("%d%d", &m, &n);
	hs = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
			if (a)
				hs++;
	}
	for (i = 1; i < m; i++) {
		s = 0;	
		for (j = 0; j < n; j++) {
			scanf("%d", &a);
			if (a)
				s++;
		}
		if (s > hs)
			hs = s;
	}
	printf("%d\n", hs);
	
	return 0;
}
			
		


	

Measured memory_bytes: 600
#ABC 045 C たくさんの数式
S = [int(i) for i in list(input())]

sum = 0
for i in range(2**(len(S)-1)):
  a = S[0]
  for j in range(len(S)-1):
    if (i >> j) & 1:
      sum += a
      a = 0
      
    a = a * 10 + S[j+1]
  sum += a
print(sum)

Measured memory_bytes: 3060
import math
a, b, C = map(int, input().split())
C = math.radians(C)
S = a * b * math.sin(C) * 0.5
c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(C))
L = a + b + c
h = 2 * S / a
print(S, L, h)


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

int main(){
  int n, l, r;
  cin >> n;
  int a[n], b[n];
  rep(i,n) cin >> a[i] >> b[i];
  sort(a,a+n); sort(b,b+n);
  if(n % 2 == 0) l = a[n/2-1] + a[n/2], r = b[n/2-1] + b[n/2];
  else l = a[n/2], r = b[n/2];
  cout << r- l + 1 << endl;
  return 0;
}


Measured memory_bytes: 5192
#include <bits/stdc++.h>
#define i64 long long
#define all(x) x.begin(), x.end()
#define LB(x,v) lower_bound(all(x),v) - x.begin()
using namespace std;

int main() {
	// your code goes here
	int n,val,maxVal = 0; cin>>n;
	vector<int>d(n);
	for(int i=0;i<n;i++) {
		cin>>d[i];
		//d.push_back(val);
		maxVal = max(maxVal,d[i]);
	}
	sort(all(d));
	//for(int i=0;i<n;i++) printf("%d ",d[i]);
	//printf("\n");
	
	int cnt = 0;
	for(val=2;val<=maxVal;val++){
		int idx = LB(d,val);
		if(d[idx] < val) idx++;
		idx = min(idx,n-1);
		if(idx > 0){
			if(d[idx-1] == val) idx--;
		}
		idx = max(0,idx);
		if(idx == n-idx) cnt++;
		//printf("val : %d , idx : %d,  n-idx : %d,  d[idx] : %d\n",val,  idx, n-idx, d[idx]);
	}
	printf("%d\n",cnt);
	return 0;
}

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

int main() {
	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;
	int num = 0;
	string value;
	cin >> num;
	for (int i = 0; i < num; i++) {
		cin >> value;
		if (value == "AC") {
			ac++;
		}
		else if (value == "TLE") {
			tle++;
		}
		else if (value == "WA") {
			wa++;
		}
		else if (value == "RE") {
			re++;
		}
	}
	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: 3636
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
int main(){
    int n,x[10000]={},y[10000]={};
    double D1=0.0,D2=0.0,D22=0.0,D3=0.0,D33=0.0,D=0.0,DD=0.0,max=-1000000000;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        cin>>y[i];
    }
    for(int i=0;i<n;i++){
        D1=D1+abs(x[i]-y[i]);
    }
    for(int i=0;i<n;i++){
        D22=D22+(x[i]-y[i])*(x[i]-y[i]);
    }
    D2=sqrt(D22);
    for(int i=0;i<n;i++){
        D33=D33+abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
    }
    D=1.0/3.0;
    D3=pow(D33,D);
    for(int i=0;i<n;i++){
        DD=abs(x[i]-y[i]);
        if(max<DD){
            max=DD;
        }
    }
    printf("%.8lf\n%.8lf\n%.8lf\n%.8lf\n",D1,D2,D3,max);
    return 0;
}


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

struct query{
	int ty, x, y, id;
};

const int N = 2e5 + 10;

query b[N];
int num[N], C[N];
long long C2[N];
int tot;

int lowbit(int x){
	return x & -x;
}

void add1(int x, int d){
	while (x <= tot){
		C[x] += d;
		x += lowbit(x);
	}
}

int sum1(int x){
	int ret = 0;
	while (x){
		ret += C[x];
		x -= lowbit(x);
	}
	return ret;
}

void add2(int x, int d){
	while (x <= tot){
		C2[x] += d;
		x += lowbit(x);
	}
}

long long sum2(int x){
	long long ret = 0;
	while (x){
		ret += C2[x];
		x -= lowbit(x);
	}
	return ret;
}

int main(){
	int q, cnt;
	long long ans, rec;
	scanf("%d",&q);
	for (int i = 1; i <= q; i++){
		scanf("%d",&b[i].ty);
		if (b[i].ty == 1){
			scanf("%d %d",&b[i].x,&b[i].y);
			b[i].x = b[i].x;
		}
		b[i].id = i;
	}
	sort(b + 1, b + q + 1, [&](query x, query y){return x.x < y.x;});
	for (int i = 1; i <= q; i++){
		if (b[i].ty == 1){
			tot++;
			num[tot] = b[i].x;
			b[i].x = tot;
		}
	}
	sort(b + 1, b + q + 1, [&](query x, query y){return x.id < y.id;});
	cnt = 0; ans = 0; rec = 0;
	for (int i = 1, l, r, mid; i <= q; i++){
		if (b[i].ty == 1){
			add1(b[i].x, 1);
			add2(b[i].x, num[b[i].x] * 2);
			ans += b[i].y;
			rec += num[b[i].x];
			cnt++;
		}
		else{
			l = 0; r = tot + 1;
			while (r - l > 1){
				mid = (l + r) >> 1;
				if (sum1(mid) < (cnt + 1) / 2) l = mid;
				else r = mid;
			}
			printf("%d %lld\n", num[r], ans + rec - sum2(r) + num[r] * (cnt % 2));
		}
	}
	return 0;
}

Measured memory_bytes: 8192
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<malloc.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, Q;
int s[100100];

signed main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }
    int ans = 0;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int a;
        cin >> a;
        bool flag = false;
        flag |= (a == *lower_bound(s, s + N, a));
        if(flag)ans++;
    }
    cout << ans << endl;

    return 0;
}

/*

*/


Measured memory_bytes: 3420
#include<iostream>
#include<string>
#include<cmath>

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

	int numA=0;
	int numB=0;

	for(int i=0; i<s.size(); i++){
		if(s[i]=='0')
			numA++;

		if(s[i]=='1')
			numB++;
	}

	std::cout<<2* std::min(numA, numB)<<std::endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,ans,mlby,f[1000010],a[500010],b[500010];
vector<int>zh[200010];
/*void build(int x,int l,int r){
	f[x]=-1e9;
	if(l==r)return;
	int mid=()
}*/
void ins(int x,int l,int r,int t,int w){
	if(l==r){
		f[x]=max(f[x],w);return;
	}
	int mid=(l+r)/2;
	if(mid>=t)ins(x*2,l,mid,t,w);
	 else ins(x*2+1,mid+1,r,t,w);
	f[x]=max(f[x*2],f[x*2+1]);
}
void xiu(int x,int l,int r,int t,int w){
	if(l==r){
		f[x]=w;return;
	}
	int mid=(l+r)/2;
	if(mid>=t)xiu(x*2,l,mid,t,w);
	 else xiu(x*2+1,mid+1,r,t,w);
	f[x]=max(f[x*2],f[x*2+1]);
}
int query(int x,int l,int r,int t,int k){
	if(t>k)return -1e9;
	if(l==t&&r==k)return f[x];
	int mid=(l+r)/2;
	if(mid>=k)return query(x*2,l,mid,t,k);
	 else if(t>mid)return query(x*2+1,mid+1,r,t,k);
	  else return max(query(x*2,l,mid,t,mid),query(x*2+1,mid+1,r,mid+1,k));
}
int main(){
	int i,j,x,y,xlh;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&b[i]);
	for(i=1;i<=n;i++){
		ans+=(b[i]==0);
		if(b[i]==1)a[i]=1;
		 else a[i]=-1;
	}
	for(i=1;i<=n;i++)a[i]+=a[i-1];
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		zh[x].push_back(y);
	}
	memset(f,172,sizeof(f));
	//build(1,1,n);
	for(i=1;i<=n;i++){
		for(j=0;j<zh[i].size();j++){
			x=zh[i][j];
			mlby=max(mlby,a[x]-a[i-1]);
			ins(1,1,n,x,a[x]-a[i-1]-a[x]);
			xlh=max(query(1,1,n,1,i-1)-a[i-1],query(1,1,n,i,x));
			mlby=max(mlby,xlh+a[x]);
			ins(1,1,n,x,xlh);
		}
		xlh=query(1,1,n,i,i);
		//printf("%d %d\n",i,xlh+a[i]);
		xiu(1,1,n,i,xlh+a[i]);
	}
	printf("%d",n-(mlby+ans));
}

Measured memory_bytes: 16768
H, W, K = map(int, input().split())
MOD = 10 ** 9 + 7

factorial = [1, 1]
inverse = [1, 1]
invere_base = [0, 1]
for i in range(2, H * W + 2):
    factorial.append((factorial[-1] * i) % MOD)
    invere_base.append((-invere_base[MOD % i] * (MOD // i)) % MOD)
    inverse.append((inverse[-1] * invere_base[-1]) % MOD)


def nCr(n, r):
    if not 0 <= r <= n:
        return 0
    return factorial[n] * inverse[r] * inverse[n - r] % MOD


ans = 0
for dh in range(1, H):
    ans += dh * (H - dh) * pow(W, 2, MOD) * nCr(H * W - 2, K - 2) % MOD
    ans %= MOD
for dw in range(1, W):
    ans += dw * (W - dw) * pow(H, 2, MOD) * nCr(H * W - 2, K - 2) % MOD
    ans %= MOD

print(ans)


Measured memory_bytes: 32836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

vector< vector<int> > Graph;
vector< int > value;





bool ProductDay(int month,int day10,int day1) {
    if(day10*day1 == month) return true;
    else return false;
}



int main(int argc, const char * argv[]) {
    
   
    
    
    int m,d; cin >> m >> d;
    int ans = 0;
    for (int month = 1; month <= m; month++) {
        for (int day = 1; day <= d; day++) {
            if(ProductDay(month, day/10, day%10) && day/10 > 1 && day%10 > 1) {
                ans++;
                
            }
        }
    }
    
    cout << ans << endl;
    
    
    
    


    
    

    
}


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

int main(){
    int N, a, i;
    cin >> N;
    int count = 0;
    for (i=1; i<=N; ++i){
        cin >> a;
        if (a%2==1 && i%2==1){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3576
//compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
int gcd(int a, int b){
	int r;
	if(!(a > b))swap(a, b);
	r = a%b;
	if(r != 0){
		return gcd(b, r);
	}else if(r == 0){
		return b;
	}
}

int main(){
	int x, y;
	cin >> x >> y;
	cout <<gcd(x, y) <<endl;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

ll n, m;
vvl to;

void dfs(ll v, vector<bool>& visited) {
    if (visited[v]) return;

    visited[v] = true;
    for (auto nv : to[v]) {
        dfs(nv, visited);
    }
}

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

    cin>>n>>m;
    to = vvl(n + m);
    rep(i, n) {
        ll k;
        cin>>k;
        rep(j, k) {
            ll v;
            cin>>v; v--;
            to[i].push_back(n + v);
            to[n + v].push_back(i);
        }
    }

    vector<bool> visited(n + m);
    dfs(0, visited);
    bool ans = true;
    rep(i, n) ans &= visited[i];
    if (ans) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

int main() {
    int N;
    long K;
    cin >> N >> K;
    vector<int> A(N);
    long ans = 0;
    int mod = pow(10, 9) + 7;
    long k_ = K * (K - 1) / 2 % mod;
    for (int i = 0; i < N; i++) cin >> A.at(i);
    for (int i = 0; i < N; i++) {
        int a = A[i];
        int x = 0;
        int y = 0;
        for (int j = 0; j < i; j++) {
            if (a > A[j]) x++;
        }
        for (int j = i + 1; j < N; j++) {
            if (a > A[j]) y++;
        }
        ans += K * y;
        ans += (x + y) * k_;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> a;
    rep(i, n)
    {
        vector<int> hoge(n, 0);
        a.push_back(hoge);
    }
    rep(i, m)
    {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        for (int j = r; j < n; j++)
        {
            a[l][j]++;
        }
    }

    // cout<<endl;
    //     rep(i,n){
    //         rep(j,n){
    //             cout<<a[i][j]<<" ";
    //         }
    //         cout<<endl;
    //     }
    rep(i, q)
    {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        int ans = 0;
        for (int j = p; j <= q; j++)
        {
            ans += a[j][q];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
  public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    int input = Integer.parseInt(reader.readLine());

    int cases = 1;

    while(input>0) {
      int[][] arr = new int[input][input];
      int x=0,y=0;
      int count = 1;
      boolean mode = false;
      while(x<input&&y<input) {
        arr[x][y] = count;

        if(mode) {
          x--;  y++;
        }else {
          y--;  x++;
        }

        if(x>=input) {
          x--;  y++;  y++;
          mode = !mode;
        }else if(y>=input) {
          y--;  x++;  x++;
          mode = !mode;
        }

        if(x<0) {
          x++;
          mode = !mode;
        }else if(y<0) {
          y++;
          mode = !mode;
        }

        count++;
      }

      sb.append("Case "+cases+":\n");

      for(int i = 0; i < input; i++) {
        for(int j = 0; j < input; j++) {
          sb.append(String.format("%3d",arr[j][i]));
        }
        sb.append("\n");
      }

      input = Integer.parseInt(reader.readLine());
      cases++;
    }

    System.out.print(sb.toString());
  }
}

Measured memory_bytes: 24872
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
ll MAX = 1000000000l;
void solver(ll s, ll *x, ll *y)
{

    x[0] = 0, y[0] = 0;
    if (s <= MAX)
    {
        x[1] = 1, y[2] = s;
        x[2] = 0, y[1] = 0;
    }
    else if ((ll)(sqrt(s)) * (ll)(sqrt(s)) != s)
    {
        ll t = (ll)(sqrt(s));
        ll r = (ll)(sqrt(s));
        while (t * r >= s)
        {
            --t, --r;
        }
        rep(p, t, MAX + 1)
        {
            rep(q, r, MAX + 1)
            {
                if (p * q < s)
                    continue;
                ll a = p * q - s;
                x[1] = p, y[2] = q;

                rep(i, 1, (ll)(sqrt(a)) + 1)
                {
                    if (a % i == 0 && a / i <= MAX && i <= MAX)
                    {
                        x[2] = i, y[1] = a / i;
                        return;
                    }
                }
            }
        }
    }
    else
    {
        x[1] = sqrt(s), y[2] = sqrt(s);
        x[2] = 0, y[1] = 0;
    }
}
int main()
{
    ll s;
    cin >> s;
    ll x[3], y[3];
    solver(s, x, y);
    printf("%lld %lld %lld %lld %lld %lld\n", x[0], y[0], x[1], y[1], x[2], y[2]);
}

Measured memory_bytes: 3764
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type Abbreviation ---------- */
using ll = long long;

/* ---------- Constants ---------- */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */
template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    if (S[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }

    int cnt = 0;
    for (int i = 2; i < S.size() - 1; i++) {
        if (S[i] == 'C') cnt++;
    }

    if (cnt != 1) {
        cout << "WA" << endl;
        return 0;
    }

    int global_cnt = 0;
    for (int i = 0; i < S.size(); i++) {
        if (isupper(S[i])) global_cnt++;
    }

    if (global_cnt != 2) {
        cout << "WA" << endl;
        return 0;
    }

    cout << "AC" << endl;

    return 0;
}

Measured memory_bytes: 256
import math
from itertools import permutations
n = int(input())
x = []
for _ in range(n):
    x.append(list(map(int , input().split())))
p = permutations(x)
ans = 0
for i in p:
    dist = 0
    for k in range(1 , n):
        dist += math.sqrt((i[k][0] - i[k-1][0]) ** 2 + (i[k][1] - i[k-1][1]) ** 2)

    ans += dist
print(ans / len(list(permutations(x))))

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

using namespace std;

int gcd(int x, int y)
{
  int r = 0;
  
  if(x < y){
    swap(x,y);
  }
  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}
int main(){
  int x,y;
  
  cin >> x >> y;

  cout << gcd(x,y) << endl;
  return 0;
}
  



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

using static Input;
using static Util;
class Program
{
    static int N;
    static int[] M;
    static void INPUT()
    {
        N = NextInt();
        M = LineInt();
    }
    static void OUT()
    {
        var a = new int[M.Length];
        for (int i = 0; i < M.Length; i++)
        {
            a[M[i]-1] = i+1;
        }

        Console.WriteLine(string.Join(" ", a));
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
        N = 3;
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 29660
#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() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int score = 0;
    rep(i,n-1) {
        if (s[i] == s[i+1]) score++;
    }
    int ans = min(score+2*k, n-1);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	ll s , c ;
	cin >> s >> c;
	
	ll ans = 0;
	if(c < s * 2){
		ans = c / 2;
	}else{
		//cをsにしたほうがいい。c4でsccを一つ作れる
		ans = s;
		c -= s * 2;
		ans += c / 4;
	}
	
	cout << ans << endl;

}


Measured memory_bytes: 256
def main():
    N = int(input())
    b = list(map(int, input().split()))

    ans = []
    while b:
        for i in range(len(b) - 1, -1, -1):
            if i + 1 == b[i]:
                b.pop(i)
                ans.append(i + 1)
                break
        else:
            print(-1)
            return

    ans.reverse()
    for a in ans:
        print(a)


main()


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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

const ll MOD = 998244353;

ll a, b, c, d, res;

vector<ll> fac;
//dp[i][j] = i rows added and j columns added
vector<vector<ll>> dp;

ll exp(ll a, ll n){
    if(n == 0) return 1;
    ll tmp = exp(a, n/2);
    tmp *= tmp;
    tmp %= MOD;
    if(n%2) tmp *= a;
    tmp %= MOD;
    return tmp;
}

ll inv(ll x){
    return exp(x, MOD - 2);
}

ll cmb(ll c, ll k){
    if(k > c) return 0;
    ll t = inv(fac[c - k]) * inv(fac[k]);
    t %= MOD;
    t *= fac[c];
    t %= MOD;
    return t;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b >> c >> d;
    dp.assign(c - a + 1, vector<ll>(d - b + 1, 0));
    dp[0][0] = 1;
    for(int i = 0; i <= c - a; ++i){
        for(int j = 0; j <= d - b; ++j){
            if(i && j){
                dp[i][j] -= (dp[i - 1][j - 1] * (i + a - 1) * (j + b - 1))%MOD;
                dp[i][j] = (dp[i][j] + MOD)%MOD;
            }
            // dp[i][j] %= MOD;
            if(i + 1 <= c - a){
                dp[i + 1][j] += dp[i][j] * (j + b);
                dp[i + 1][j] %= MOD;
            }
            if(j + 1 <= d - b){
                dp[i][j + 1] += dp[i][j] * (i + a);
                dp[i][j + 1] %= MOD;
            }
        }
    }
    // for(auto i : dp){
    //     for(auto j : i){
    //         cout << j << " ";
    //     }
    //     cout << "\n";
    // }
    cout << dp[c - a][d - b];
    return 0;
}

Measured memory_bytes: 73656
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n,W;

int main() {
    cin >> n >> W;
    vector<ll> w(n);
    vector<ll> v(n);
    ll V = 0;
    REP(i, n){
        cin >> w[i] >> v[i];
        V += v[i];
    }
    vector<vector<ll>>  dp(V+1,vector<ll>(n+1,LLONG_MAX));
    dp[0][0]=0;
    REP(i,n){
        REP(j,V){
            if(dp[j][i]!=LLONG_MAX){
                dp[j][i+1]=min(dp[j][i+1],dp[j][i]);
                if(j+v[i]<=V){
                    dp[j+v[i]][i+1]=min(dp[j+v[i]][i+1],dp[j][i]+w[i]);
                }
            }
        }
    }
    ll res = 0;
    REP(j,V+1){
        if(0<dp[j][n]&&dp[j][n]<=W){
            res = max(res,j);
        }
    }
    put(res);
    return 0;
}




Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    int cnt = 1;
    for(int i = 1; i < n; i++){
        if(a[i] <= a[i - 1]) cnt++;
    }
    cout << cnt << endl;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    Graph G(n);
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }

    vector<int> dist(n, -1);
    vector<int> store(n, -1);
    queue<int> que;

    dist[0] = 0;
    store[0] = 0;
    que.push(0);

    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (int nv : G[v])
        {
            if (dist[nv] != -1)
                continue;
            dist[nv] = dist[v] + 1;
            store[nv] = v+1;
            que.push(nv);
        }
    }

    for (int v = 1; v < n; ++v)
    {
        if (dist[v] == -1)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int v = 1; v < n; ++v)
        cout << store[v] << endl;
}

Measured memory_bytes: 10684
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int[][] a = new int[3][3];
    for (int i = 0; i < 3; i++) {
      a[i] = sc.nextIntArray(3);
    }
    int n = sc.nextInt();
    int[] b = sc.nextIntArray(n);
    for (int val : b) {
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
          if (a[i][j] == val) {
            a[i][j] = -1;
          }
        }
      }
    }
    boolean isBingo = false;
    for (int i = 0; i < 3; i++) {
      int sum = 0;
      for (int j = 0; j < 3; j++) {
        sum += a[i][j];
      }
      isBingo |= sum == -3;
    }
    for (int j = 0; j < 3; j++) {
      int sum = 0;
      for (int i = 0; i < 3; i++) {
        sum += a[i][j];
      }
      isBingo |= sum == -3;
    }
    isBingo |= a[0][0] + a[1][1] + a[2][2] == -3;
    isBingo |= a[0][2] + a[1][1] + a[2][0] == -3;
    System.out.println(isBingo ? "Yes" : "No");
  }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, t[100], i, ans=0, f=0;
    string s[100], x;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> s[i] >> t[i];
    }
    cin >> x;
    for(i=0;i<n;i++){
        if(f==1) ans+=t[i];
        if(s[i]==x) f=1;
    }
    cout << ans <<endl;
    

    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i,n) {
    cin >> a[i];
  }

  sort(a.begin(), a.end());

  long sum = a[n-1];
  int count = 1;

  for (int i = n-2; i > n/2-1; i--) {
    count += 2;
    if (count <= n-1) {
      sum += 2*a[i];
    } else {
      sum += a[i];
    }
  }

  cout << sum << endl;


}


Measured memory_bytes: 4040
package main

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

func main() {
	io, flush := NewIO()
	defer flush()

	n, k := io.ScanInt2()
	heights := io.ScanInts(n)
	
	var count int
	for _, h := range heights {
		if h >= k {
			count++
		}
	}
	fmt.Println(count)
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 3604
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix


def solv(K, N, A):
    max_d = 0
    for i in range(N - 1):
        d = A[i + 1] - A[i]
        if d > max_d:
            max_d = d
    d = K + A[0] - A[-1]
    if d > max_d:
        max_d = d
    return K - max_d


if __name__ == "__main__":

    # K N
    # A_1 A_2 ... A_N
    #
    # 99
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    ans = solv(K, N, A)

    print(ans)


Measured memory_bytes: 26444
#include<stdio.h>

int main(){
 long long int n,k;
 long long int n1,n2,a;
  scanf("%lld %lld",&n,&k);
  a=n/k;
  n=n-k*a;
  n1=n;
  n=n-k;
  n2=n;
  if(n1<=(n2-(2*n2))){
    printf("%lld",n1);
  }else{
    printf("%lld",(n2-(2*n2)));
  }
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int X; cin >> X;
  if (X >= 30) Yes();
  else No();

  return 0;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct data{
    int h,w;
    data(int a,int b):h(a),w(b){}
    data(){}
    bool operator<(const data &d)const{
        int v=h*h+w*w;
        int dv=d.h*d.h+d.w*d.w;
        return v<dv||(v==dv&&h<d.h);
    }
};
int main(){
    vector<data>V;
    for(int i=1;i<150;i++){
        for(int j=i+1;j<=150;j++){
            V.push_back(data(i,j));
        }
    }
    sort(V.begin(),V.end());
    int h,w;
    while(scanf("%d%d",&h,&w),h||w){
        data d=*upper_bound(V.begin(),V.end(),data(h,w));
        printf("%d %d\n",d.h,d.w);
    }
    return 0;
}

Measured memory_bytes: 1164
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

x,k,d = inintm()
x = abs(x)

if x > k*d:
    print(x-k*d)
else:
    if (k - x//d) % 2 == 0:
        print(x-(x//d)*d)
    else:
        print(abs(min(x-(x//d)*d + d, x-(x//d)*d - d)))

Measured memory_bytes: 62088
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main()
{
    string S;
    string O = "CODEFESTIVAL2016";
    cin >> S;
    int cnt = 0;
    
    for (int i=0; i<16; i++) {
        if (S[i] != O[i]) {
            cnt++;
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
int cnt(0);
int N;

int main(){
  int N,K,h[100000];
  cin>>N>>K;
  for (int i(0);i<N;i++) cin>>h[i];
  sort(h,h+N);
  int mini(1e9);
  for (int i(0);i<N;i++){
    if (i+K-1>=N) break;
    mini = min(h[i+K-1]-h[i],mini);
  }
  cout << mini<< endl;
}


Measured memory_bytes: 768
def fun(n, k):
    A = [int(input()) for _ in range(n)]
    k_sum = 0
    maximam = 0
    for num, a in enumerate(A):
        if 0 <= num <= k-1:
            k_sum += a
        else:
            maximam = max(maximam, k_sum + a - A[num-k])
            k_sum = k_sum + a - A[num-k]
    print(maximam)

for _ in range(5):
    n, k = map(int, input().split())
    if n == 0 and k == 0:
        break
    else:
        fun(n, k)


Measured memory_bytes: 9616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    ll x, y;
    cin >> x >> y;
    int cnt =0 ;
    while(x <= y){
        x *= 2;
        cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	ll n,k;
	cin>>n>>k;
	ll ch[200010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	for(ll i=k;i<n;i++){
		if(ch[i-k]<ch[i]){
			cout << "Yes";
		}
		else{
			cout << "No";
		}
		cout <<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 5048
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

struct Node {
    int parent;
    vector<int> children;
};

int main()
{
    scanInt(N);
    vector<unordered_set<int>> edges(N);
    loop(i, N - 1){
        scanInt(ai); --ai;
        scanInt(bi); --bi;
        edges[ai].emplace(bi);
        edges[bi].emplace(ai);
    }
    vector<Node> nodes(N);
    nodes[0].parent = INT_MIN;
    function<void(int)> makeTree = [&](int n){
        for (auto& next : edges[n]){
            if (next == nodes[n].parent) continue;
            nodes[n].children.emplace_back(next);
            nodes[next].parent = n;
            makeTree(next);
        }
    };
    makeTree(0); // 0 is root
    auto countDepth = [&](int n){
        int count = 0;
        while (n != 0){
            n = nodes[n].parent;
            ++count;
        }
        return count;
    };
    const int w_depth = countDepth(N - 1);
    auto forwardToParent = [&](int n, int times){
        for (; 0 < times; --times){
            n = nodes[n].parent;
        }
        return n;
    };
    const int w_limit = forwardToParent(N - 1, (w_depth - 1) / 2);
    function <int(int)> countBlack = [&](int n){
        if (n == w_limit) return 0;
        int count = 1;
        for (auto& next : nodes[n].children){
            count += countBlack(next);
        }
        return count;
    };
    const int b_num = countBlack(0);
    if (b_num <= N - b_num){
        puts("Snuke");
    }else{
        puts("Fennec");
    }
}


Measured memory_bytes: 29184
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
map<string,priority_queue<int> >q;
map<string,int>st;
 
void END(){
  cout<<"No"<<endl;
  exit(0);
}
 
int main(){
  int n,m;
  cin>>n;
  string s[n];
  int D[n];
  r(i,n)cin>>s[i]>>D[i],st[s[i]]++;
  r(i,n){
    q[s[i]].push(D[i]);
  }
  cin>>m;
  string t[m];
  int ans[m];
  r(i,m)cin>>t[m-i-1];
  r(i,m){
    if(q[t[i]].empty())END();
    while(i){
      if(q[t[i]].empty())END();
      if(q[t[i]].top()<ans[i-1])break;
      else q[t[i]].pop();
    }
    int x=q[t[i]].top();
    ans[i]=x;
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 38384
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;
set<int> s;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n, ans = 0;
	string a, b, c;
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		s.clear();
		s.insert(a[i]);
		s.insert(b[i]);
		s.insert(c[i]);
		ans += (s.size() - 1);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  auto n=readln.chomp.to!(char[]);
  int sum1=0;
  foreach(c; n) sum1+=(c-'0');
  if(n.length>1){
    int tmp=(n[0]-'0')-1;
    tmp+=(n.length.to!(int)-1)*9;
    sum1=max(sum1, tmp);
  }

  writeln(sum1);  
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 256
# N人住んでいる
N = int(input())

# Xiが住んでいる場所
X = list(map(int, input().split()))

ans = 10**9
# 開催場所は0~一番遠い人のところまで
for p in range(max(X)+1):
    tmp = 0
    for x in X:
        #print(x,p,(x-p)**2)
        tmp += (x-p)**2
    # 最小値を更新する
    ans = min(ans, tmp)
    
print(ans)

Measured memory_bytes: 3060
(function(){
	'use strict';
	(function() {
		this.output = function() {
			console.log.apply( console, arguments );
		};
		this.stdin = process.openStdin();
		stdin.setEncoding('utf8');
		stdin.on('end', function(){
			process.exit();
		});
		this.fs = require('fs');
	}).call( this );
	(function(){
		(function input(next_func) {
			var list = [];
			stdin.on('data', function(chunk){
				var input_data = (function(){
					chunk.replace(/\\r/, '');
					return chunk.trim().split('\n');
				})(chunk);
				input_data.forEach(function(line){		
					list.push( parseInt(line.trim()) );			
				});
				if ( list.length >= 10 )
					return next_func(list);
			});
		}).call(this, function solve(list) {
			list.sort(function(a,b){
				return a < b;
			});
			var result = list.slice( 0, 3 );
			result.forEach(function(height){
				output(height);
			});
			process.exit();
		});
	}).call( this );
}).call(global);

Measured memory_bytes: 7784