akhauriyash/Code-Regression huggingface dataset:
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define Mx 2000000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
int main(){
	string s,t,v;
	vector<int> number;
	int i,j,n;
	cin>>s;
	t=s;
	reverse(t.begin(),t.end());
	if(t==s){
		cout<<0<<endl;
		return 0;
	}
	t="";
	for(i=0;i<s.size();i++) if(s[i]!='x') t+=s[i],number.push_back(i);
	v=t;
	reverse(v.begin(),v.end());
	if(v!=t){
		cout<<-1<<endl;
		return 0;
	}
	n=t.size();
	if(n%2==1){
		long long tt=number[n/2],ans=0;
		string a,b;
		a=s.substr(0,tt);
		b=s.substr(tt+1);
		reverse(b.begin(),b.end());
		for(int i=0;;i++){
			if(i>=a.size()||i>=b.size()) break;
			if(a[i]!=b[i]){
				ans++;
				if(a[i]=='x'){
					b.insert(i,"x");
				}else{
					a.insert(i,"x");
				}
			}
		}
		if(a.size()!=b.size()) ans+=abs((int)(a.size())-(int)(b.size()));
		cout<<ans<<endl;
		return 0;
		return 0;
	}else{
		long long tt1=number[n/2],tt2=number[n/2-1],ans=0;
		string a,b;
		a=s.substr(0,tt2);
		b=s.substr(tt1+1);
		reverse(b.begin(),b.end());
		for(int i=0;;i++){
			if(i>=a.size()||i>=b.size()) break;
			if(a[i]!=b[i]){
				ans++;
				if(a[i]=='x'){
					b.insert(i,"x");
				}else{
					a.insert(i,"x");
				}
			}
		}
		if(a.size()!=b.size()) ans+=abs((int)(a.size())-(int)(b.size()));
		cout<<ans<<endl;
		return 0;
		return 0;
	}
}

Measured memory_bytes: 1148
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	std::vector<ll>  a(5);
	ll k;
	ll kmax = 0;
	ll kmin = 124;
	for (int i = 0; i < 5; i++) {
		ll tmpk;
		std::cin >> tmpk;
		if (tmpk > kmax) kmax = tmpk;
		if (tmpk < kmin) kmin = tmpk;
	}

	std::cin >> k;
	if (kmax - kmin > k) std::cout << ":(" << std::endl;
	else std::cout << "Yay!" << std::endl;



	return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
#print(gcd(a,b))

#最小公倍数
def lcm(a,b):
  return a*b//gcd(a,b)
#print(lcm(a,b)

a,b,c,d = list(map(int,input().split(" ")))
e = lcm(c,d)
p=(a-1)//c
o=b//c
i=(a-1)//d
u=b//d
y=(a-1)//e
t=b//e
C = max([0,o-p])
D = max([0,u-i])
E = max([0,t-y])
print( (b-a+1)-(C+D-E) )

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#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 IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
/*
int dfs(int foo, int timer)
{
    //foo is node number
    if (finds[foo].first != -1)
        return timer;
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i, data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second = ++result;
    return result;
}
*/
int main()
{
    int a,c;
    cin>>a>>c;
    cout<<2*c-a<<endl;
    return 0;
}


Measured memory_bytes: 256
n=7**6;P=[0,0]+[1]*n;S=[0]*n
for i in range(2,n):
  for j in range(2*i,n,i):P[j]=0
for i in range(1,n):S[i]+=(P[i]==P[(i+1)//2]==1)+S[i-1]
for _ in "_"*int(input()):l,r=map(int,input().split());print(S[r]-S[l-1])

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    double ans = 0;

    if (d == 0) {
        rep(i, m - 1) {
            ans += (double)n / n / n;
        }
    } else {
        rep(i, m - 1) {
            ans += (double)2 * (n - d) / n / n;
        }
    }

    printf("%.10f\n", ans);
}

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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    int N;
    cin>>N;
    vector<double> x(N),y(N);
    rep(i,N){
        cin>>x[i]>>y[i];
    }
    double sum=0;
    rep(i,N-1){
        for(int j=i;j<N;j++){
            sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    double ans=sum*2/N;
    std::cout << std::fixed<<std::setprecision(9);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3812
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    string s;
    cin>>s;
    if(s.size()%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<s.size();i+=2){
        if(s[i]!='h'||s[i+1]!='i'){
            cout<<"No"<<endl;
        return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[101010];
int main()
{
	int n,mid;
	long long ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	mid=(n+1)/2;
	if(n&1)
	{
		for(int i=1;i<mid;i++)
			ans-=a[i]*2;
		for(int i=mid+1;i<=n;i++)
			ans+=a[i]*2;
		ans-=min(a[mid]-a[mid-1],a[mid+1]-a[mid]);
	}
	else
	{
		for(int i=1;i<=mid;i++)
			ans-=a[i]*2;
		for(int i=mid+1;i<=n;i++)
			ans+=a[i]*2;
		ans-=a[mid+1]-a[mid];
	}
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

long long f(long long b, long long n) {
    if (b <= 1) return -1;
    if (n < b) return n;
    else return f(b, n / b) + n % b;
}
int main() {
    long long n, s;

    scanf("%lld%lld", &n, &s);
    long long res = 1e13 + 1;

    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }

    if (s > n) {
        cout << -1 << endl;
        return 0;
    }


    for (long long b = 2; b * b < n; ++b) {
        if (f(b, n) == s) res = min(res, b);
    }

    for (long long p = 1; p * p <= n; ++p) {
        long long r = s - p;
        long long b = (n - r) / p;
        if (f(b, n) == s) res = min(res, b);
    }

    if (res == 1e13 + 1) cout << -1 << endl;
    else cout << res << endl;


    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	ansYes(a + b >= c);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
 
#include <fstream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(void)
{
 
    
    long double a, b;
    
    cin >> a >> b;
  
  b *= 10000;
  floor(b);
  b /= 10000;
    
    cout << fixed << setprecision(0) << floor(a*b) << endl;
    
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  cout << a / b << ' '
       << a % b << ' '
       << fixed << setprecision(5) << 1.0 * a / b << endl;
  return 0;
}



Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	// no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} 
using io :: gi;
using io :: putc;
using io :: print;
const int N=205,mod=1e9+7;
int k,ans,tot,head[N],nxt[N],adj[N],dfn[N],low[N],id,s[N],top,q[N],vis[N],fac[N],ifac[N],power[N];
inline void addedge(ri x,ri y){
	nxt[++tot]=head[x];
	adj[head[x]=tot]=y;
}
inline int C(ri n,ri m){
	return m<0||n<m?0:(ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
inline int gcd(ri x,ri y){
	return !y?x:gcd(y,x%y);
}
inline void tarjan(ri x,ri fa){
	dfn[x]=low[x]=++id;
	s[++top]=x;
	ri y,i,j,cnt,edge,o,res;
	for(i=head[x];i;i=nxt[i]){
		if((y=adj[i])==fa) continue;
		if(!dfn[y]){
			tarjan(y,x);
			low[x]=min(low[x],low[y]);
			if(low[y]>=dfn[x]){
				q[cnt=1]=x;vis[x]=1; 
				do{
					q[++cnt]=s[top];
					vis[s[top]]=1;
				}while(s[top--]!=y);
				edge=0;
				for(j=1;j<=cnt;++j)
					for(o=head[q[j]];o;o=nxt[o])
						edge+=vis[adj[o]];
				edge>>=1;
				if(edge<cnt)
					ans=(ll)ans*k%mod;
				else if(edge==cnt){
					res=0;
					for(j=0;j<edge;++j)
						res=(res+power[gcd(j,edge)])%mod;
					res=(ll)res*ifac[edge]%mod*fac[edge-1]%mod;
					ans=(ll)ans*res%mod;
				}
				else
					ans=(ll)ans*C(edge+k-1,k-1)%mod;
				while(cnt) vis[q[cnt--]]=0;
			}
		}
		else
			low[x]=min(low[x],dfn[y]);
	}
}
inline int fpow(ri a,ri b){
	ri ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1) ans=(ll)ans*a%mod;
	return ans;
}
int main(){
	ri n,m,i,x,y,s;
	gi(n);gi(m);gi(k);
	s=m+k;
	fac[0]=1;
	for(i=1;i<=s;++i) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[s]=fpow(fac[s],mod-2);
	for(i=s;i;--i) ifac[i-1]=(ll)ifac[i]*i%mod;
	power[0]=1;
	for(i=1;i<=n;++i) power[i]=(ll)power[i-1]*k%mod;
	while(m--) gi(x),gi(y),addedge(x,y),addedge(y,x);
	ans=1;
	for(i=1;i<=n;++i)
		if(!dfn[i])
			tarjan(i,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>
int main(void){
    long long int a;
	long long int x=100;  
    long long int b=0;
    scanf("%lld",&a);
    while(1){
      x*=1.01;
      b++;
      if(a==100){
        printf("0");
        break;
      }
      if(x>=a){
      printf("%lld",b);
        break;
      }
    }
    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long
#define pb push_back 
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<ll>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl;
#define cno cout << "No" << endl;
#define mod 1000000007
#define mod2 998244353
#define INT_MAX1 900000000
//////////////////////////////////////////////////////////////////////////////////////////////

vector<vi> q;
int n,m;
int dp[100001];
bool v[100001];

int s1(int i)
{
    if(v[i])
        return dp[i];
    v[i] = 1;
    dp[i] = 0;
    loop(q[i])
    {
        dp[i] = max(dp[i], s1(it));
    }
    dp[i]++;
    return dp[i];
}

void solve()
{
    cin >> n  >> m;
    q.rs(n+1);
    rep(i,0,m-1)
    {
        int l,r;
        cin >> l >> r;
        q[l].pb(r);
    }

    int ans = 0;
    rep(i,1,n)
    {
        ans = max(ans, s1(i));
    }
    cout << ans-1 << endl;
    
}
 
int32_t main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 7936
N,T=map(int,input().split())
lst=[0]*N
a=0
b=0
min_c=float("inf")
t=0
for i in range(N):
    a,b=map(int,input().split())
    if b<=T:
        min_c=min(min_c,a)
if min_c==float("inf"):
    min_c="TLE"
print(min_c)

Measured memory_bytes: 3064
use strict;

my @lines = <STDIN>;
my ($N, $M) = split(/ /, $lines[0]);
my @A = split(/ /, $lines[1]);
my %h = (0 => 1);
my $count = 0;
my $S = 0;

for (my $i = 0; $i < $N; $i++) {
    $S += $A[$i];
    if (defined($h{$S % $M})) {
        $count += $h{$S % $M};
        $h{$S % $M} ++;
    } else {
        $h{$S % $M} = 1;
    }
}

print $count, "\n";


Measured memory_bytes: 23276
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define MOD 1000000007

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


int main()
{
	int N; cin >> N;
	int N2 = N * 2;
	int N3 = N * 3;
	vector<int> A(N3);
	for (int i = 0; i < N3; ++i) cin >> A[i];

	priority_queue<int, vector<int>, greater<int>> q1;	//小さい順に取り出す
	priority_queue<int> q2;								//大きい順に取り出す
	vector<ll> v1(N + 1, 0), v2(N + 1, 0);	//0～N-1+iまでから選んだ際の最大の総和、N+i～N3-1までから選んだ際の最小の総和
	//queを埋める
	for (int i = 0; i < N; ++i) {
		q1.push(A[i]);
		v1[0] += A[i];
		q2.push(A[i + N2]);
		v2[N] += A[i + N2];
	}
	//0～N-1+iまでから選んだ際の最大の総和を求める
	for (int i = N; i < N2; ++i) {
		int t = q1.top();
		if (t < A[i]) {
			q1.push(A[i]);
			q1.pop();
			v1[i + 1 - N] = v1[i - N] - t + A[i];
		}
		else {
			v1[i + 1 - N] = v1[i - N];
		}
	}
	//N+i～N3-1までから選んだ際の最小の総和を求める
	for (int i = N2 - 1; i >= N; --i) {
		int t = q2.top();
		if (t > A[i]) {
			q2.push(A[i]);
			q2.pop();
			v2[i - N] = v2[i + 1 - N] - t + A[i];
		}
		else {
			v2[i - N] = v2[i + 1 - N];
		}
	}
	ll ans = 0 - LLINF;
	for (int i = 0; i <= N; ++i) {
		ans = max(ans, v1[i] - v2[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6732
import java.util.Scanner;

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

            int[] tower = new int[1000];
            for (int i = 1; i < tower.length; i++) {
                tower[i] = i + tower[i - 1];
            }

            for (int i = 1; i + 1 < tower.length; i++) {
                int x = tower[i] - a;
                if (x < 0) {
                    continue;
                }
                if (x + b == tower[i + 1]) {
                    System.out.println(x);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  int mod = 1000000007;
  cin>>n>>m;
  int a[m],i;
  vector<int> v(n+1,-1);
  v[0]=1;
  v[1]=1;
  for(i=0;i<m;i++)
  {
    cin>>a[i];
    v[a[i]]=0;
  }
  for(i=2;i<=n;i++)
  {
    if(v[i])
    {
      v[i]=(v[i-1]+v[i-2])%mod;
    }
  }
//   for(i=0;i<=n;i++) cout<<v[i]<<" ";
  
  cout<<v[n];
  return 0;
}

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

int main() {

  long long int t;
  cin >> t;

  for ( long long int tt = 0; tt < t; tt++ ) {

    long long int h, w;
    cin >> h >> w;

    vector< string > m;

    long long int min_x[26] = {};
    long long int max_x[26] = {};
    long long int min_y[26] = {};
    long long int max_y[26] = {};

    for ( long long int i = 0; i < 26; i++ ) {
      min_x[i] = w;
      max_x[i] = -1;
      min_y[i] = h;
      max_y[i] = -1;
    }

    for ( long long int i = 0; i < h; i++ ) {

      string in;
      cin >> in;
      m.push_back( in );

      for ( long long int j = 0; j < w; j++ ) {

	if ( in[j] == '.' ) continue;
	long long int k = in[j] - 'A';
	min_x[ k ] = min( min_x[k], j );
	max_x[ k ] = max( max_x[k], j );
	min_y[ k ] = min( min_y[k], i );
	max_y[ k ] = max( max_y[k], i );

      }

    }

    bool f = true;

    while( f ) {

      f = false;

      for ( long long int i = 0; i < 26; i++ ) {

	if ( max_x[i] < 0 ) continue;

	bool ff = true;

	for ( long long int x = min_x[i]; x <= max_x[i]; x++ ) {
	  for ( long long int y = min_y[i]; y <= max_y[i]; y++ ) {

	    if ( m[y][x] != '*' && m[y][x] != 'A' + i ) {
	      ff = false;
	      break;
	    }

	  }
	  if ( ff == false ) break;
	}

	if ( ff == true ) {
	  f = true;
	  for ( long long int x = min_x[i]; x <= max_x[i]; x++ ) {
	    for ( long long int y = min_y[i]; y <= max_y[i]; y++ ) {
	      m[y][x] = '*';
	    }
	  }
	  max_x[i] = -1;
	}

      }

    }

    string out = "SAFE";
    for ( long long int i = 0; i < 26; i++ ) {
      if ( max_x[i] >= 0 ) {
	out = "SUSPICIOUS";
	break;
      }
    }
    cout << out << endl;


  }

  return 0;

}

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

int main() {
  int A, B; cin >> A >> B;
  int res = 10000;
  for (int x = 2000; x >= 0; x--) {
    if (A <= x*0.08 && x*0.08 < A+1 && B <= x*0.1 && x*0.1 < B+1) {
      res = x;
    }
  }
  if (res == 10000) {cout << -1 << endl;}
  else {cout << res << endl;}
}

Measured memory_bytes: 256
ans_list = []

def main():
    while True:
        ans = solve()
        if ans == "end":
            break
        ans_list.append(ans)
    
    for ans in ans_list:
        print(ans)
    
def solve():
    W,H = map(int,input().split())
    if (H,W) == (0,0):
        return "end"
    grid = [list(map(int,input().split())) for _ in range(H)]
    for i,line in enumerate(grid):
        for j,p in enumerate(line):
            if p == 2:
                si,sj = i,j
    around = [(0,1),(1,0),(0,-1),(-1,0)]
    res = [11]
    def dfs(i=si,j=sj,d=0):
        if d == 10:
            return
        for di,dj in around:
            ni = i; nj = j; nd = d
            # すぐ次のマスに障害物がある場合は進めない
            if not(0 <= ni+di < H and 0 <= nj+dj < W):
                continue
            if grid[ni+di][nj+dj] == 1:
                continue
            ni += di; nj += dj; nd += 1

            while True:
                if grid[ni][nj] == 3:
                    res[0] = min(res[0],nd)
                    break
                # はみ出たら終わり
                if not(0 <= ni+di < H and 0 <= nj+dj < W):
                    break
                # 壁に当たったらそこを支点に探索する
                if grid[ni+di][nj+dj] == 1:
                    grid[ni+di][nj+dj] = 0
                    dfs(ni,nj,nd)
                    grid[ni+di][nj+dj] = 1
                    break
                ni += di; nj += dj
    
    dfs()
    if res[0] == 11:
        res[0] = -1
    return res[0]

main()


Measured memory_bytes: 5628
N = int(input())
k = [[0] * 10 for _ in range(10)]

for n in range(1, N+1):
  sn = str(n)
  k[int(sn[0])][int(sn[-1])] += 1

ans = 0
for i in range(1, 10):
  for j in range(1, 10):
    ans += (k[i][j] * k[j][i])
    
print(ans)


Measured memory_bytes: 40428
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;

const int maxn = 1e5 + 10;
pair<ll, ll> p[maxn];
ll par[maxn];
ll s[maxn];
ll sum;
ll ans[maxn]; // d[i] 表示 没了1~i-1还有多少对连通
ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

int main() {
    ll n, m;
    scanf("%lld%lld", &n, &m);
    for (int i = 1; i <= n; i++) {
        par[i] = i;
        s[i] = 1;
    }
    for (int i = 0; i < m; i++) {
        scanf("%lld%lld", &p[i].first, &p[i].second);
    }
    sum = 1LL * n * (n - 1) / 2;
    for (int i = m - 1; i >= 0; i--) {
        ans[i] = sum;
        int x = find(p[i].first), y = find(p[i].second);
        if (x != y) {
            par[y] = x;
            sum -= s[x] * s[y];
            s[x] += s[y];
        }
    }
    for (int i = 0; i < m; i++) printf("%lld\n", ans[i]); 
    return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	int a, b, c;
	cin>>a>>b>>c;
	if(a < b && b < c) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 3080
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    string s; cin >> s;
    sort(ALL_OF(s));
    cout << Yes(s[0] == s[1] && s[0] != s[2] && s[2] == s[3]) << endl;
    
}

Measured memory_bytes: 764
H, W = map(int, input().split())
ans = 10**9

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    for h in range(1,H):
        A = h * W
        B = (H - h) * -(-W // 2)
        C = (H - h) * (W // 2) 
        ans = min(ans, max(A,B,C)-min(A,B,C))

    for w in range(1,W):
        A = w * H
        B = (W - w) * -(-H // 2)
        C = (W - w) * (H // 2) 
        ans = min(ans, max(A,B,C)-min(A,B,C))
    print(min(ans, H, W))

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

int N;
string S[10101];

void solve() {
    cin >> N;
    REP(i, N) cin >> S[i];

    ll ans = 0;
    ll BA = 0, _A = 0, B_ = 0;

    REP(i, N) {
        REP(j, (int)S[i].size()-1) {
            if (S[i][j] == 'A' && S[i][j+1] == 'B') {
                ans += 1;
            }
        }
        if (S[i].size() >= 2 && S[i].front() == 'B' && S[i].back() == 'A') {
            BA += 1;
        } else if (S[i].front() == 'B') {
            B_ += 1;
        } else if (S[i].back() == 'A') {
            _A += 1;
        }
    }
    

    bool a = false;
    while (BA > 0 || B_ > 0 || _A > 0) {
        if (!a) {
            if (_A) {
                _A -= 1;
                a = true;
            } else if (BA) {
                BA -= 1;
                a = true;
            } else {
                B_ -= 1;
            }
        } else {
            if (BA) {
                BA -= 1;
                ans += 1;
            } else if (B_) {
                B_ -= 1;
                ans += 1;
                a = false;
            } else {
                _A -= 1;
            }
        }
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    ll d;cin>>d;
    if(d==25)cout<<"Christmas"<<endl;
    if(d==24)cout<<"Christmas Eve"<<endl;
    if(d==23)cout<<"Christmas Eve Eve"<<endl;
    if(d==22)cout<<"Christmas Eve Eve Eve"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
 
int main(){
    unsigned int a,b;
    while(~scanf("%u%u",&a,&b)){
        unsigned int c=a,d=b;
        while(a>0&&b>0){
            if(a>b)a=a%b;
            else b=b%a;
        }
        printf("%u %u\n",a+b,c/(a+b)*d);
    }
}

Measured memory_bytes: 1032
/**
* I'm sorry I was an Idiot
*/
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long

using namespace std;

bool com(const pair<ll,ll> a, const pair<ll,ll> b){
	if(a.second < b.second)
		return true;
	if(a.second > b.second)
		return false;
	return a.first > b.first;
}

int main(){
	int j;
	cin >> j;
	vector<pair<ll,ll>> jobs(j);
	for(int i = 0; i < j;++i){
		ll val1,val2;
		cin >> val1 >> val2;
		jobs[i] = make_pair(val1,val2);
	}
	sort(jobs.begin(),jobs.end(),com);
	ll current = 0;
	bool posi = true;
	for(int i = 0; i < j;++i){
		if(current + jobs[i].first > jobs[i].second){
			posi = false;
			break;
		}
		current += jobs[i].first;
	}
	if(posi)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bucnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	int n, m;	cin >> n >> m;
	vint a(n);
	rep(i, n) {
		cin >> a[i];	a[i]--;
	}
	//お気に入り無しと比較した差を記録。減る分は2回累積和を取ると作れるので最後にまとめて。
	vector<ll> dist(2*m, 0);//メインの累積部
	vector<ll> sub(2*m, 0);//1回imosしたら引いて階段をうまく作るためのもの
	srep(i, 1, n) {
		if (a[i - 1] < a[i]) {
			dist[a[i - 1] + 2]++;
			dist[a[i] + 1]--;
			sub[a[i] + 1] -= a[i] - a[i - 1] - 1;
		}
		else {
			dist[a[i - 1] + 2]++;
			dist[a[i] + 1 + m]--;
			sub[a[i] + 1 + m] -= a[i] + m - a[i - 1] - 1;
		}
	}
	srep(i, 1, 2 * m)	dist[i] += dist[i - 1];
	rep(i, 2 * m)	dist[i] += sub[i];
	srep(i, 1, 2 * m)	dist[i] += dist[i - 1];
	vector<ll> sum(m, 0);
	rep(i, m)	sum[i] = dist[i] + dist[m + i];
	int to = 0;
	rep(i, m) {
		if (sum[to] < sum[i])	to = i;
	}
	ll ret = -sum[to];
	srep(i, 1, n) {
		ret += (m + a[i] - a[i - 1]) % m;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4608
///In the name of Almighty Allah(swt).

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,i,a=0,w=0,t=0,r=0;
    cin>>n;
    string s[n];
    for(i=0; i<n; i++)
    {
        cin>>s[i];
    }
    for(i=0; i<n; i++)
    {
        if(s[i] == "AC")
            a++;
        else if(s[i] == "TLE")
            t++;
        else if(s[i] == "WA")
            w++;
        else if(s[i] == "RE")
            r++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;



    return 0;
}



Measured memory_bytes: 6712
//Author: AnandRaj anand873
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 2e9+7,MAX = 1e5+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
}
//////////////////Sieve////////////////////

const ll LIM = 1e18;

int main()
{
	int n;
	cin>>n;
	vl A(n);
	take(A,0,n);
	bool yes=true;
	ll prod=1;
	sort(all(A));
	for(int i=0;i<n;i++)
	{
		if(prod==0) break;
		if(A[i]>LIM/prod) {yes=false;break;}
		else prod*=A[i];
	}
	if(yes) cout<<prod<<endl;
	else cout<<-1<<endl;
}		

Measured memory_bytes: 4580
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

int mi;
int c[10];

map<int,int> memo;

int f(int n) {
  const int idx = n;
  if (n == 0) return n;
  if (memo.count(idx)) return memo[idx];
  int m = f(n / 10);
  if (m != n / 10) return memo[idx] = m * 10 + mi;
  while (c[n % 10]) ++n;
  if (n / 10 != m) return memo[idx] = f(n / 10) * 10 + mi;
  return memo[idx] = n;
}

void solve() {
  int N, K;
  cin >> N >> K;
  REP(i,K) {
    int x;
    cin >> x;
    c[x] = 1;
  }
  REP(i,10) {
    if (c[i] == 0) {
      mi = i;
      break;
    }
  }
  cout << f(N) << endl;
  return;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
	
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		System.out.printf("%d %d %f", a / b, a % b, (double) a / b);
	}
}

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

int main(){
    long a, b, n;
    cin >>n >> a >>b ;
    if((b-a)%2 == 0){
        cout << (b-a)/2;
    }
    else if(a-1 < n-b){
        cout << (a+b-1)/2;
    }
    else{
        cout << n-(a+b-1)/2;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int x,y,ans;
int main()
{
	scanf("%d%d",&x,&y);
	int x1=abs(x),y1=abs(y);
	if(x1>=y1)
	{
		if(x<0)
		{
			if(y>0)ans=x1-y1+1;
			else ans=x1-y1;
		}
		else if(y<=0)ans=x1-y1+1;
		else ans=x1-y1+2;
	}
	else
	{
		if(x<0)
		{
			if(y>=0)ans=y1-x1+1;
			else ans=y1-x1+2;
		}
		else if(y<0)ans=y1-x1+1;
		else ans=y1-x1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
h,w=gets.split.map(&:to_i)
a=$<.map{|x|x.split.map(&:to_i)}
res = [];
cnt = 0;
h.times{|y|
  (w-1).times{|x|
    if a[y][x]&1 == 1
      cnt += 1
      res << [y+1,x+1,y+1,x+2]
      a[y][x]^=1
      a[y][x+1]^=1;
    end
  }
}

(h-1).times{|y|
  if(a[y][-1]&1 == 1)
    cnt += 1
    res << [y+1,w,y+2,w]
    a[y][-1] ^=1
    a[y+1][-1] ^= 1
  end
}
p cnt
puts res.map{|x|x*" "}

Measured memory_bytes: 52988
#include <bits/stdc++.h>
#define x real()
#define y imag()
using namespace std;
typedef complex <double> point;
vector <point> po;
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}

double get_area(){
  double res=0;
  for(int i=0;i<po.size();i++)res+=cross(po[i],po[(i+1)%po.size()])/2;
  return abs(res);
}


int main(){
  int n;
  cin>>n;
  for(int i=0,a,b;i<n;i++)cin>>a>>b,po.push_back(point(a,b));
  printf("%.1f\n",get_area());
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ss substr
typedef long long ll ;
typedef long double ld ;
typedef pair<ll, ll> pairs ;
typedef map<ll,ll> mapi ;
typedef map<string,string> maps ;


int main()
{
  //freopen("lifeguards.out", "w", stdout) ;
  //freopen("lifeguards.in", "r", stdin) ;
  ios_base::sync_with_stdio(0) ;
  cin.tie(NULL) ;
  cout.tie(NULL) ;
 
 //int t ; cin >> t ; while(t--){} 
 
 int n ; cin >> n ;
 for ( int i = 1 ; i <= 9 ; i++ )
 {
   if ( n % i == 0 && n/i <= 9 )
   {
     cout << "Yes" ;
     return 0 ;
   }
 }
 cout << "No" ;

}
 
 



 


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  long N,n,a,b,s;
  double D,d;
  cin>>N>>D;
  n=0;
  int i;
  for (i=0;i<N;i++)
  {
    cin>>a>>b;
    a=a*a;
    b=b*b;
    s=a+b;
    d=sqrt(s);
    if (d>D)
    {
      continue;
    }
    else
    {
      n=n+1;
    }
  }
  cout<<n<<endl;
  return 0;
}

Measured memory_bytes: 3724
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
int main() {
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int d = min(x/500,a);
  int ans = 0;
  
  rep(i,d+1){
    int e = min((x-500*i)/100,b);
    rep(j,e+1){
      if((x-500*i-100*j)/50 <= c) ans++;
    }
  }
  dunk(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    ll N; cin >> N;
    cout << (N * (N - 1)) / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,n;
  cin >> n;
  ll a[n],ret=0ll;
  for(i=0;i<n;i++)cin >> a[i];
  ll l=0,r;
  while(l<n){
    if(a[l]==0){
      l++;
      continue;
    }
    r=l+1;
    ll mi=a[l];
    while(r<n&&a[r]!=0){
      mi=min(mi,a[r]);
      r++;
    }
    ret+=mi;
    for(i=l;i<r;i++)a[i]-=mi;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1e6+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

PLL d[100009];

int main(){
	DRI(n);
	REP(i,n){
		scanf("%lld%lld",&d[i].F,&d[i].S);
	}
	LL ans=0;
	for(int i=n-1;i>=0;i--){
		d[i].F+=ans;
		ans+=((d[i].F+d[i].S-1)/d[i].S)*d[i].S-d[i].F;
	}
	printf("%lld",ans);
}


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

template<class T>
T sqr(T obj) {return obj * obj;}

struct color {
	string name;
	int R, G, B;

	color(string n, int r, int g, int b) {
		name = n;
		R = r;
		G = g;
		B = b;
	}
};

color color_list[] = {
	color("black", 0x00, 0x00, 0x00),
	color("blue", 0x00, 0x00, 0xff),
	color("lime", 0x00, 0xff, 0x00),
	color("aqua", 0x00, 0xff, 0xff),
	color("red", 0xff, 0x00, 0x00),
	color("fuchsia", 0xff, 0x00, 0xff),
	color("yellow", 0xff, 0xff, 0x00),
	color("white", 0xff, 0xff, 0xff),
};

int main() {
	string s;
	while(cin >> s) {
		if(s[0] == '0')
			break;

		int mind, indx;
		indx = 0;
		mind = 1e8;

		int a[3];
		for(int j = 0; j < 3; j++) {
			int tmp = 0;
			if('0' <= s[1 + 2 * j] && s[1 + 2 * j] <= '9')
				tmp += (s[1 + 2 * j] - '0') * 16;
			else
				tmp += (s[1 + 2 * j] - 'a' + 10) * 16;

			if('0' <= s[2 + 2 * j] && s[2 + 2 * j] <= '9')
				tmp += (s[2 + 2 * j] - '0');
			else
				tmp += (s[2 + 2 * j] - 'a' + 10);
			a[j] = tmp;
		}

		for(int i = 0; i < 8; i++) {
			int d = 0;

			d += sqr(color_list[i].R - a[0]);
			d += sqr(color_list[i].G - a[1]);
			d += sqr(color_list[i].B - a[2]);
			if(d < mind) {
				indx = i;
				mind = d;
			}
		}
		cout << color_list[indx].name << endl;
	}
}

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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

const int MAXN = 2e5 + 5;
const int oo = 1e9 + 7;

int n, k, x[MAXN];

int main () {
    scanf("%d%d", &n, &k);
    fto(i, 1, n) scanf("%d", &x[i]);

    int ans = oo;
    fto(i, 1, n-k+1) {
        int t = x[i+k-1] - x[i] + min(abs(x[i+k-1]), abs(x[i]));
        ans = min(ans, t);
    }

    printf("%d\n", ans);

    return 0;
}


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

#define ll long long

int main()
{
    ll n, a[200000], mx = 0, ans = 0;
    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        ll amt = mx - a[i];
        if (amt > 0) ans += amt;
        mx = max(mx, a[i]);
    }

    cout << ans << "\n";
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL dp[3][100001];

void solve(long long N, long long K, long long R, long long S, long long P, std::string T){
    LL ans = 0;
    REP(i, K) {
        int lp = ((N-i) % K == 0 ? (N-i) / K : (N-i) / K + 1);
        REP(j, 3) REP(k, lp+1) dp[j][k] = 0;
        
        // 相手が 0 = グー, 1 = チョキ, 2 = パー
        // 自分が 0 = パー, 1 = グー, 2 = チョキ
        dp[0][0] = (T[i] == 'r' ? P : 0);
        dp[1][0] = (T[i] == 's' ? R : 0);
        dp[2][0] = (T[i] == 'p' ? S : 0); 
        REP1(j, lp) {
            dp[0][j] = max(dp[1][j-1], dp[2][j-1]) + (T[i+K*j] == 'r' ? P : 0);
            dp[1][j] = max(dp[0][j-1], dp[2][j-1]) + (T[i+K*j] == 's' ? R : 0);
            dp[2][j] = max(dp[1][j-1], dp[0][j-1]) + (T[i+K*j] == 'p' ? S : 0);
        }
        ans += max(dp[0][lp-1], max(dp[1][lp-1], dp[2][lp-1]));
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long R;
    scanf("%lld",&R);
    long long S;
    scanf("%lld",&S);
    long long P;
    scanf("%lld",&P);
    std::string T;
    std::cin >> T;
    solve(N, K, R, S, P, T);
    return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,b,p,t,max=0;
	scanf("%d",&x);
	if(x<4)
	{
		printf("1");
		return 0;
	}
	for(b=2;;b++)
	{
		t=pow(b,2);
		if(t>x)
		{
			break;
		}
		if(t>max)
		{
			max=t;
		}
		for(p=3;;p++)
		{
			t=pow(b,p);
			if(t>x)
			{
				break;
			}
			if(t>max)
			{
				max=t;
			}
		}
	}
	printf("%d",max);
	return 0;
}

Measured memory_bytes: 512