akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
#define mp(a,b) std::make_pair(a,b)
#define ITR(a,b) for(auto a:b)
#define REP(a,b,c) for(register int a=(b),a##end=(c);a<=a##end;++a)
#define DEP(a,b,c) for(register int a=(b),a##end=(c);a>=a##end;--a)
const int MAXN=100000+10;
int n,m,A[MAXN],B[MAXN],fa[MAXN<<1],cnt,vA,vB;
std::vector<int> V;
std::map<int,int> M;
template<typename T> inline void read(T &x)
{
	T data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
	if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline void discretization()
{
	REP(i,1,n)V.push_back(A[i]),V.push_back(B[i]);
	std::sort(V.begin(),V.end());
	V.erase(std::unique(V.begin(),V.end()),V.end());
	REP(i,0,V.size()-1)M[V[i]]=i+1;m=V.size();
	REP(i,1,n)A[i]=M[A[i]],B[i]=M[B[i]];
}
inline int found(int x)
{
	if(fa[x]!=x)fa[x]=found(fa[x]);
	return fa[x];
}
inline bool same()
{
	REP(i,1,n)if(A[i]!=B[i])return false;
	return true;
}
int main()
{	read(n);
	REP(i,1,n)read(A[i]),vA^=A[i];
	REP(i,1,n)read(B[i]),vB^=B[i];
	if(same())
	{
		puts("0");
		return 0;
	}
	A[++n]=vA;B[n]=vB;
	discretization();
	REP(i,1,n)if(A[i]!=B[i]||i==n)
	{
		if(i!=n)cnt++;
		if(!fa[A[i]])fa[A[i]]=A[i];
		if(!fa[B[i]])fa[B[i]]=B[i];
		int u=found(A[i]),v=found(B[i]);
		if(u!=v)fa[u]=v;
	}
	std::sort(A+1,A+n+1);
	std::sort(B+1,B+n+1);
	REP(i,1,n)if(A[i]!=B[i])
	{
		puts("-1");
		return 0;
	}
	REP(i,1,n)if(found(i)==i)cnt++;
	printf("%d\n",cnt-1);
	return 0;
}


Measured memory_bytes: 7796
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;

signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  
  int ans = 200000000000;
  for (int bit = 0; bit < (1 << N); ++bit) {
    vector<int> b(N);
    for (int i = 0; i < N; ++i) b[i] = a[i];
    
    vector<int> S;
    for (int i = 0; i < N; ++i) {
      if (bit & (1 << i)) S.push_back(i);
    }
    
    int cost = 0;
    for (int i : S) {
      int MAX = 0;
      for (int j = 0; j < i; ++j) MAX = max(b[j], MAX);
      if (MAX >= b[i]) {
        cost += MAX - b[i] + 1;
        b[i] = MAX + 1;
      }
    }
    
    int cnt = 0;
    int MAX;
    for (int i = 0; i < N; ++i) {
      if (i == 0) {
        ++cnt;
        MAX = b[i];
      } else {
        if (MAX < b[i]) ++cnt;
        MAX = max(b[i], MAX);
      }
    }
    
    if (cnt >= K) ans = min(cost, ans);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
string str;
int sum,f;
int main()
{
    cin>>str;
    for(int i=1;i<str.length();i++) sum += 9;
    for(int i=1;i<str.length();i++) if(str[i]!='9') f=1;
    if(f) cout<<sum+str[0]-'1';
    else cout<<sum+str[0]-'0';
    cout<<endl;
    return 0;
}

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

vector<int> getDig (int x) {
  vector<int> ret;
  for (int it = 0; it < 3; it++) {
    ret.push_back(x % 10);
    x /= 10;
  }
  return ret;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<vector<int>> pos(10);
  for (int i = 0; i < n; i++) {
    pos[s[i] - '0'].push_back(i);
  }
  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    vector<int> now = getDig(i);
    int p = 0, f = 1;
    for (int v : now) {
      auto it = lower_bound(pos[v].begin(), pos[v].end(), p);
      if (it == pos[v].end()) {
        f = 0;
        break;
      }
      p = (*it) + 1;
    }
    ans += f;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int h,w; cin>>h>>w;
	vector<vector<string>> vv(h+2,vector<string>(w+2,"."));
	for(int i=1; i<=h; i++){
		string s; cin>>s;
		for(int j=1; j<=w; j++){
			vv[i][j]=s[j-1];
		}
	}
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			int cnt=0;
			if(vv[i][j]=="#"&&vv[i+1][j]=="#") cnt++;
			if(vv[i][j]=="#"&&vv[i-1][j]=="#") cnt++;
			if(vv[i][j]=="#"&&vv[i][j+1]=="#") cnt++;
			if(vv[i][j]=="#"&&vv[i][j-1]=="#") cnt++;
			if(vv[i][j]=="#"&&cnt==0){cout<<"No"<<endl; return 0;}
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3680
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	for (char i : n)
	{
		if (i == '1')
		{
			print("9");
		}
		else
		{
			print("1");
		}
	}

	println("");
}

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

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	auto p = minmax_element(a, a + n);
	cout << *p.second - *p.first << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

_LL getans()
{
    _LL x, k, d;
    cin >> x >> k >> d;
    _LL ax = abs(x);

    _LL k2 = k / 2;
    _LL d2 = d * 2;

    if( k % 2 == 1 ) ax = abs(ax - d);

    if( k2 < ax / d2 )
    {
        return ax - d2 * k2;
    }

    _LL ans1 = ax % d2;
    _LL ans2 = ans1 - d2;
    return min(abs(ans1), abs(ans2));
}

int main()
{
    cout << getans();
    return 0;    
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int h, w, k;

typedef vector<string> V;

int solve(V mas, int tb, int yb){
	for(int i = 0;i < h;i++){
		if(tb & (1 << i)){
			for(int j = 0;j < w;j++){
				mas[i][j] = '.';
			}
		}
	}

	for(int j = 0;j < w;j++){
		if(yb & (1 << j)){
			for(int i = 0;i < h;i++){
				mas[i][j] = '.';
			}
		}
	}

	int cnt = 0;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(mas[i][j] == '#') cnt++;
		}
	}

	return cnt == k ? 1 : 0;
}

signed main(){
	cin >> h >> w >> k;
	V mas(h);
	for(int i = 0;i < h;i++){
		cin >> mas[i]; 
	}

	int ans = 0;
	for(int i = 0;i < (1 << h);i++){
		for(int j = 0;j < (1 << w);j++){
			ans += solve(mas, i, j);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main(){
	long long int ans = 0;
	int n;
	map<string, int> table;

	cin >> n;

	for (int i = 0; i < n; i++){
		string s;
		cin >> s;

		//計算
		sort(s.begin(), s.end());

		if (table.count(s) == 0)
		{
			table[s] = 1;
		}
		else
		{
			ans += table[s];
			table[s]++;
		}
	}

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

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int D()
{
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
const int N=2e5+9;

int arr[N],in[N];
int main(){
    int a=D();
    int b=D();

    int c=D();
    int d=D();

    for(int i =a ;i <c;i++)
        cout<<"R";
        for(int j =b ;j <d;j++)
        cout<<"U";
        for(int i =a ;i <c;i++)
        cout<<"L";
        for(int j =b ;j <d;j++)
        cout<<"D";
        cout<<"D";
        for(int i =a ;i <c;i++)
        cout<<"R";
        cout<<"R";
        for(int j =b ;j <d;j++)
        cout<<"U";
        cout<<"U";
        cout<<"L";
        cout<<"U";
        for(int i =a ;i <c;i++)
        cout<<"L";
        cout<<"L";
        for(int j =b ;j <d;j++)
        cout<<"D";
         cout<<"D";

                cout<<"R";










      ///  cout<<a<<" "<<b<<endl;
     ///   cout<<i<<" "<<j<<" "<<cnt<<endl;
        }



/**
bool ok(int val){
  int cntm=0,cntp=0;
  for(int i=0;i<n-val;i++)
  {
      cntm=0;cntp=0;
      for(int j=i;j<val;j++)
      {
      (arr[j]==1)?cntp++:cntm++;
      }
      if(cntp==cntm)
        break;
  }
  return cntp==cntm;
}
int binarySearch(){
  int low = 0, med, hi =n;
  while(low<hi){
    med = (low+hi+1)>>1;
    cout<<med<<" "<<hi<<" "<<low<<endl;
    if(ok(med))  low = med;
    else  hi = med-1;
  }
  return low;
}*/



/**
  int power1(int b, int p){               //O(p)
    if(!p)  return 1;
    return b*power1(b, p-1);
  }
  int power2(int b, int p){               //O(Log(p))
    if(!p)  return 1;
    int ret = power2(b, p/2);
    return (p&1 ? ret*ret*b : ret*ret);
  }
   int mul(int a, int b, int m){
      return (a%m * b%m) % m;
  }

*/


/**
void seive()
{
    bitset<N>iscomp;
    iscomp[0]=iscomp[1]=1;
    for(long long i=2; i<=N; ++i)
    {
        if(!iscomp[i])
        {
            a.push_back(i);
            for(long long j=i*i; j<=N; j+=i)
                iscomp[j]=1;
        }
    }
}
3
abc
abc
*/

    /**


    */


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a >= 10){
    cout << b << endl;
  }
  else{
    cout << b + 100 * (10 - a) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
const int N=410;
int K;
ll a[N],C[N];
int A[N],B[N];
map <ll,int> w;
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline ll F(ll x) {return x/1000+x%1000*1000000000;}
inline ll get(ll x) {
    ll ret=x;K=1;
    for(int i=0;i<3;i++) {
	x=F(x);
	if(x<ret) ret=x,K=0;
	if(x==ret) ++K;
    }
    return ret;
}
int main() {
    int n;
    ll ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
	ll x=0;
	for(int j=0;j<4;j++) x=x*1000+gi();
	++w[a[i]=get(x)];
    }
    for(int i=1;i<=n;i++) {
	--w[a[i]];
	for(int j=i+1;j<=n;j++) {
	    --w[a[j]];
	    for(int k=0;k<4;k++) {
		ll x=a[i],y=a[j]=F(a[j]),res=1;
		for(int p=0;p<4;p++,x/=1000,y/=1000)
		    A[3-p]=x%1000,B[3-p]=y%1000;
		swap(B[1],B[3]);
		for(int p=0;p<4;p++) {
		    C[p]=get(A[p]*1000000000LL+B[p]*1000000+B[(p+1)%4]*1000+A[(p+1)%4]);
		    res*=K*w[C[p]]--;
		}
		ans+=res;
		for(int p=0;p<4;p++) ++w[C[p]];
	    }
	    ++w[a[j]];
	}
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 80128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i in range(N):
  if A[i] >= B[i]:
    ans += B[i]
  else:
    ans += A[i]
    tmp = B[i] - A[i]
    ans += min(A[i + 1], tmp)
    A[i + 1] = max(A[i + 1] - tmp, 0)

print(ans)

Measured memory_bytes: 19244
a, b = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(a)]
e = 0
for i in range(a):
    for j in range(i+1, a):
        d = 0
        for k in range(b):
            d += (c[i][k] - c[j][k]) ** 2
        d = d ** 0.5
        if d % 1 == 0:
            e += 1
print(e)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define D(a) (double)(a)
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI 2*acos(0.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define rt return true
#define rf return false
///................function.....................///
#define siz(s) (int)(s.size())
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define dbg(a) cout << #a << " = " << a << " ";
///...........knight moves.....................///
///int dx[] = {+1,+1,-1,-1,+2,+2,-2,-2};
///int dy[] = {+2,-2,+2,-2,+1,-1,+1,-1};

int main()
{
    FIO;
    int n,i,j;
    cin>>n;
    vll v(n);
    read(v,0,n);
    ll ans=0LL;
    for(i=1; i<n; i++)
    {
        if(v[i-1]>v[i])
        {
            ans+=v[i-1]-v[i];
            v[i]=v[i-1];
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 4780
n = int(input())
flag=0
lst = [int(i) for i in input().split()][:n]
for i in lst:
    if i%2==0 and i%3!=0 and i%5!=0:
        flag=1 
    else:
        continue
if (flag==1):
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string>
using namespace std;
int main(void){
   int K;
   int X;
   cin>>K;
   cin>>X;
   for(int i=X-K+1;i<=X+K-1;i++){
       cout<<i<<endl;
   }
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
signed main(){
  int a;
  cin>>a;
  rep(i,100){
    if((a*100+i)%108==0){
      cout<<(a*100+i)/108<<endl;
      return 0;
    }
      }
  cout<<":(";
}

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

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

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

constexpr int nax = 1000 * 1000 + 105;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  const int n = s.size();
  map<char, ll> licz;
  for (char c : s) licz[c]++;
  ll wynik = 0;
  for (char c : s) wynik += (n - licz[c]);
  wynik /= 2;
  cout << wynik + 1 << endl;
  return 0;
}


Measured memory_bytes: 720
from math import sin, cos, radians
a, b, c = map(int, input().split())
print(a * b * sin(radians(c)) / 2)
print(a + b + ((a ** 2 + b ** 2) - 2 * a * b * cos(radians(c))) ** 0.5)
print(b * sin(radians(c)))



Measured memory_bytes: 5716
#include <cstdio>
#include <iostream>
using namespace std;
int n,root=0;
struct ti
{
    int par,lef,rig;
}nodes[30];
void preorder(int node)
{
    if(node==-1)return;
    printf(" %d",node);
    preorder(nodes[node].lef);
    preorder(nodes[node].rig);
}
void inorder(int node)
{
    if(node==-1)return;
    inorder(nodes[node].lef);
    printf(" %d",node);
    inorder(nodes[node].rig);
}
void postorder(int node)
{
    if(node==-1)return;
    postorder(nodes[node].lef);
    postorder(nodes[node].rig);
    printf(" %d",node);
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)nodes[i].par=-1;
    for(int i=0;i<n;i++)
    {
        int iid,ilef,irig;
        scanf("%d%d%d",&iid,&ilef,&irig);
        nodes[iid].lef=ilef;
        nodes[iid].rig=irig;
        if(ilef!=-1)nodes[ilef].par=iid;
        if(irig!=-1)nodes[irig].par=iid;
    }
    for(int i=0;i<n;i++)if(nodes[i].par==-1)root=i;
    printf("Preorder\n");
    preorder(root);
    printf("\nInorder\n");
    inorder(root);
    printf("\nPostorder\n");
    postorder(root);
    cout<<endl;
	return 0;
}


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

ll gcd(ll x, ll y){
	while(1){
		if(x < y) swap(x, y);
		if(!y) break;
		x %= y;
	}
	return x;
}

int main(){
	int n; cin >> n;
	int A[n], ans[n+1];
	for(int i=0; i<n; i++){
		cin >> A[i];
		ans[A[i]] = i+1;
	}
	for(int i=1; i<=n; i++){
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1536
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N, M;
	cin >> N >> M;

	int L, R;
	if (N & 1) {
		L = 0;
		R = N - 2;
		for (int i = 0; i < M; ++i) {
			cout << L + 1 << " " << R + 1 << endl;
			L += 1;
			R -= 1;
		}
	}
	else {
		int A = (M + 1) / 2;
		int RR = A * 2;
		for (int i = 1; i <= A; ++i) {
			cout << i << " " << RR - i + 1 << endl;
		}
		int B = M / 2;
		int start = RR + 1;
		int end = RR + B * 2+1;
		for (int i = 0; i < B; ++i) {
			cout << start << " " << end << endl;
			++start;
			--end;
		}
	}
	
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}

Measured memory_bytes: 3656
function Main(input) {
    //var N = input;
    //入力はn進法で与えられてるので10進法にすること。
    var n = parseInt(input, 10);
    function hoge(n) {
        //var hogehoge = hoge.toString().split('').map(n => parseInt(n).reduce((a, b) => a + b);
        //上に同じく。reduceはつなげないとかそんな決まりはない。最初のコードでおｋ
        var n = n.toString().split('').map(n => parseInt(n, 10)).reduce((a, b) => a + b);
        return n;
    }
    if(n % hoge(n) === 0) {
        console.log('Yes');
    } else{
        console.log('No');
    }
    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vi a;
    rep(i, n) {
        int aa;
        cin >> aa;
        if(aa >= k) continue;
        a.emplace_back(aa);
    }
    n = a.size();
    if(!n) {
        cout << 0 << endl;
        return 0;
    }
    sort(all(a));
    int l = -1, r = n, mid;
    while(r-l != 1) {
        mid = (l+r)>>1;
        vi dp(k);
        dp[0] = 1;
        rep(i, n) if(i != mid) {
            for(int j = k-1; j >= a[i]; j--) {
                dp[j] += dp[j-a[i]];
            }
        }
        bool ok = false;
        for(int i = k-a[mid]; i < k; i++) {
            if(dp[i]) ok = true;
        }
        if(ok) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 3668
// AGC025
// B - RGB Coloring

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

const ll MOD = 998244353;

int N, A, B;
ll K;
vector<ll> fact, inv_fact;

ll extgcd(ll a, ll b, ll& x, ll& y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

ll mod_inv(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x) % m;
}

ll combi(ll a, ll b) {
    return (fact[a] * inv_fact[a - b] % MOD) * inv_fact[b] % MOD;
}

int main() {
    cin >> N >> A >> B >> K;

    fact.resize(N + 1);
    inv_fact.resize(N + 1);
    fact[0] = 1;
    inv_fact[0] = 1;
    for (int i = 1; i <= N; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv_fact[i] = mod_inv(fact[i], MOD);
    }

    ll ans = 0;
    for (ll x = 0; x <= N && x * A <= K; x++) {
        if ((K - x * A) % B != 0) {
            continue;
        }
        ll y = (K - x * A) / B;
        if (y > N) {
            continue;
        }
        ans += combi(N, x) * combi(N, y) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


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

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

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    int ans = a - 2 * b;
    if (ans < 0)
        ans = 0;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string tr, s[4][13];
int main() {
	while (cin >> tr, tr != "#") {
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) {
				cin >> s[i][j];
			}
		}
		int r = 0, ptr = 0;
		for (int i = 0; i < 13; i++) {
			vector<int> a(4);
			for (int j = 0; j < 4; j++) {
				int c = 0;
				if (s[j][i][1] != s[ptr][i][1] && s[j][i][1] != tr[0]) continue;
				if (s[j][i][0] == 'T') c = 10;
				else if (s[j][i][0] == 'J') c = 11;
				else if (s[j][i][0] == 'Q') c = 12;
				else if (s[j][i][0] == 'K') c = 13;
				else if (s[j][i][0] == 'A') c = 14;
				else c = s[j][i][0] - 48;
				if (s[j][i][1] == tr[0]) c += 13;
				a[j] = c;
			}
			ptr = max_element(a.begin(), a.end()) - a.begin();
			if (ptr & 1) r++;
		}
		if (r > 6) cout << "EW " << r - 6 << endl;
		else cout << "NS " << 7 - r << endl;
	}
	return 0;
}

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

int main() {

    int r,g,b;
    cin >> r >> g >> b;

    int num = r * 100 + g * 10 + b;

    string ans;
    if(num % 4 == 0){
        ans = "YES";
    }else{
        ans = "NO";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	S := map[string]bool{}
	for i := 0; i < n; i++ {
		sc.Scan()
		key := sc.Text()
		if _, ok := S[key]; !ok {
			S[key] = true
		}
	}

	sc.Scan()
	result := 0
	for sc.Scan() {
		key := sc.Text()
		if _, ok := S[key]; ok {
			result++
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 1252
package main

import (
	"fmt"
	"math"
	"reflect"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, n)
	q := make([]int, n)
	for i := range p {
		fmt.Scan(&p[i])
	}
	for i := range q {
		fmt.Scan(&q[i])
	}

	o := make([]int, n)
	for i := range o {
		o[i] = i + 1
	}

	var a, b int
	for i := 0; ; i++ {
		if reflect.DeepEqual(o, p) {
			a = i
		}
		if reflect.DeepEqual(o, q) {
			b = i
		}

		if !nextPermutation(sort.IntSlice(o)) {
			break
		}
	}

	fmt.Println(math.Abs(float64(a - b)))
}

func nextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

// 
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N, K; cin >> N >> K;
  ll x, y; cin >> x >> y;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  // ll ans = 0;
  bool ok = false;
  rep(t, 100) {
    rep(k, 100) {
      if(t * 2 + k * 4 == y && t + k == x) ok = true;
    }
  }
  
  // cout << ans << endl;
   cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3684
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<pair<long long, long long>> BA(N);
    for (int i = 0; i < N; i++) cin >> BA[i].second >> BA[i].first;
    sort(BA.begin(), BA.end());

    long long time = 0;
    bool flag = true;
    for (int i = 0; i < N; i++) {
        time += BA[i].second;
        if (time > BA[i].first) {
            flag = false;
            break;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}



//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
  int  a ,b, c, d, e, X, Y ,r;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003][100001]={};

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int min =100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
  scanf("%d", &a);

  for(i=0;i<a;i++){
    scanf("%d", &b);
    if(min>b){
      min=b;
      sum++;
//        printf("cnt %d\n", i);
    }
  }
  printf("%d\n", sum);
  
return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map> 
#include <string>
using namespace std;
 
int main(){
    int i, n;
    cin >> n;
    vector<int> h(n);
    for(i = 0; i < n; i++){
        cin >> h[i];
    }
    for(i = n-1; i >= 0; i--){
        if( h[i+1] >= h[i] || i == n-1) continue;
        else if(h[i] - 1 == h[i+1]) h[i]--;
        else {cout << "No" << endl; return 0;}
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A,B,T;
    cin >> A >> B >> T;
    
    cout << T/A*B << endl;
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int p[n];
    int maxv = -1;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        sum += p[i];
        maxv = max(maxv, p[i]);
    }
    cout << sum - (maxv / 2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>

#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define DOW(i, b, a) for(int i = b; i >= a; i--)
#define maxN 1000000 + 10
const int modi = 1e9 + 7;

using namespace std;

int n;
int pre[maxN];
int dem[maxN];

void enter(){
	cin >> n;
}

void init(){
	FOR(i, 2, n) pre[i] = 0;
	FOR(i, 2, n){
		if(pre[i] == 0){
			pre[i] = i;
			FOR(j, 2, n / i) pre[j * i] = i;
		}
	}
}

void solve(){
	int s = 1;
	FOR(i, 2, n) dem[i] = 0;
	FOR(i, 2, n){
		int t = i;
		while(t != 1){
			dem[pre[t]]++;
			t /= pre[t];
		}
	} 
	FOR(i, 2, n){
		s = (long long)s * (dem[i] + 1) % modi;
	}
	cout << s << endl;
}

void printAns(){

}

int main(){
	enter();
	init();
	solve();
	printAns();
	return 0;
}



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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

class UnionFind
{
  private:
    vector<int> par;
    vector<int> sizes;

  public:
    UnionFind(int N) : par(N), sizes(N, 1)
    {
        rep(i, N) par[i] = i;
    }

    int find(int x)
    {
        if (x == par[x])
            return x;

        return par[x] = find(par[x]);
    }

    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);

        if (x == y)
            return;

        if (sizes[x] < sizes[y])
            swap(x, y);

        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    int size(int x)
    {
        return sizes[find(x)];
    }
};

int main()
{
    int N;

    while (cin >> N, N)
    {
        vector<T> graph;

        int M;
        cin >> M;

        rep(i, M)
        {
            int a, b, c;
            scanf("%d,%d,%d", &a, &b, &c);

            graph.push_back(T{c / 100 - 1, a, b});
        }

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

        UnionFind uf(N);

        int ans = 0;

        for(auto e : graph)
        {
            int cost, from, to;
            tie(cost, from, to) = e;

            if(uf.same(from, to)) continue;

            uf.unite(from, to);
            ans += cost;
        }        

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


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

#define MAX_N 10000000

int x[MAX_N];
int a, cnt;

void prime(int c) {
	for (int i = 2; i < c; i++) {
		for (int j = 2; j <= sqrt(i); j++) {
			if (i%j == 0) {
				goto E;
			}
		}
		x[i] = 1;
	E:;
	}
}

int isprime(int d) {
	cnt = 0;
	for (int i = 2; i <= d / 2; i++) {
		if (x[i] == 1 && x[d - i] == 1) {
			cnt++;
		}
	}
	return cnt;
}

int main() {
	prime(MAX_N);
	while (true) {
		cin >> a;
		if (a == 0) { break; }
		cout << isprime(a) << endl;
	}
}

Measured memory_bytes: 40220
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

int n;
int count;

void
probe(int lv, int x, int s)
{
	int i;

	s -= x;
	if (lv >= n - 1)
	{
		if (s == 0)
			count++;

		return;
	}

	for (i = x + 1; i <= 9 && s - i >= 0; ++i)
		probe(lv + 1, i, s);
}

int
main(int argc, char** argv)
{
	int s;
	int i;

	while (true)
	{
		scanf("%d %d", &n, &s);
		if (n == 0 && s == 0)
			break;

		count = 0;
		for (i = 0; i <= 9 && s - i >= 0; ++i)
			probe(0, i, s);

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

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=5e5+5;
int a[N];

int32_t main(){
    string s;
    cin>>s;
    int n=s.size()+1;
    s="<"+s+">";
    int mn=N;
    a[0]=a[n+1]=-1;
    for(int i=1;i<=n;++i){
        if(s[i-1]=='<')a[i]=a[i-1]+1;
        else a[i]=a[i-1]-1;
        upn(mn,a[i]);
    }
    for(int i=1;i<=n;++i){
        a[i]-=mn;
        dbg(i,a[i]);
    }
    dbg("==");
    int ans;
    // forn(it,10){
        ans=0;
        for(int i=1;i<=n;++i){
            int x=-1;
            if(s[i-1]=='<')upx(x,a[i-1]);
            if(s[i]=='>')upx(x,a[i+1]);
            a[i]=x+1;
            ans+=a[i];
            dbg(a[i]);
        }
        ans=0;
        for(int i=n;i>=1;--i){
            int x=-1;
            if(s[i-1]=='<')upx(x,a[i-1]);
            if(s[i]=='>')upx(x,a[i+1]);
            a[i]=x+1;
            ans+=a[i];
            dbg(a[i]);
        }
    // }
    cout<<ans<<'\n';



    return 0;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
  int main(){
    double W,H,x,y;
    cin >> W >> H >> x >> y;
    bool flag = false;
    if(W == x+x && H == y+y){
      flag = true;
    }
    double ans = H*W/2;
    cout << fixed << setprecision(6) <<ans << " " << flag << endl;     
  }


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

AC = 0
WA = 0
PS = {}
for _ in range(M):
    p, S = input().split()
    tmp = PS.get(p)
    # print(PS)
    if tmp == None:
        if S == "AC":
            PS[p] = S
            AC += 1
        else:
            PS[p] = 1
    elif tmp != "AC":
        if S == "AC":
            PS[p] = S
            AC += 1
            WA += tmp
        else:
            PS[p] += 1
print(AC, WA)

Measured memory_bytes: 21980
#include <iostream>
#include <algorithm>

using namespace std;

const int MAXN = 110;

int a[MAXN];

int main()
{
	int n, k;
	cin >> k >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int tot = 0;
	for (int i = 0; i < n - 1; i++)
		tot += a[i];
	cout << max(0, a[n - 1] - tot - 1) << endl;
}

Measured memory_bytes: 256
//
// Created by moono on 2018/10/27.
//
#include <cmath>
#include <iostream>
#include <string>
using namespace std;


int main() {
    int D, N;
    cin >> D >> N;
    if (N == 100) N++;

    if (D > 0){
        int base = pow(100, D);
        cout << base * N << endl;
    }else{
        cout << N << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define MAXN 100050
#define MAXM
#define MOD
#define INF (1<<25)
#define eps (1e-6)
#define mid ((l+r)>>1)
#define all_edge(u) for(vector <int> :: iterator it = adj[(u)].begin(); it != adj[(u)].end(); ++it)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair <int, int> pii;
typedef pair <LL, int> pli;
typedef pair <int, LL> pil;
typedef pair <LL, LL> pll;
int n, ver[MAXN][2], dfn[MAXN<<6], low[MAXN<<6], st[MAXN<<6], ins[MAXN<<6], top, idcnt, ccnt, col[MAXN<<6], vcnt;
struct node {
	int pos, id, ty;
	bool operator < (const node &x) const {
		if(pos == x.pos) return id < x.id;
		return pos < x.pos;
	}
}a[MAXN<<2];
vector <int> adj[MAXN<<6];
void build(int u, int l, int r) {
	vcnt = max(vcnt, u+2*n);
	if(l == r) return adj[u+2*n].pb(a[l].id + (a[l].ty^1)*n);
	build(u<<1, l, mid), build(u<<1|1, mid+1, r);
	adj[u+2*n].pb((u<<1)+2*n), adj[u+2*n].pb((u<<1|1)+2*n);
}
void link(int u, int l, int r, int tl, int tr, int p) {
//	cout<<u<<' '<<l<<' '<<r<<' '<<tl<<' '<<tr<<' '<<p<<endl;
//	Sleep(100);
	if(tl > tr) return ;
	if(tl <= l && r <= tr) {
//		cout<<"link "<<p<<' '<<u+2*n<<endl;
		return adj[p].pb(u+2*n);
	}
	if(tl <= mid) link(u<<1, l, mid, tl, tr, p);
	if(mid < tr) link(u<<1|1, mid+1, r, tl, tr, p);
}
void tarjan(int u) {
	st[++top] = u, ins[u] = 1;
	dfn[u] = low[u] = ++idcnt;
	all_edge(u) {
		if(!dfn[*it]) tarjan(*it), low[u] = min(low[u], low[*it]);
		else if(ins[*it]) low[u] = min(low[u], dfn[*it]);
	}
	if(low[u] == dfn[u]) {
		int cur; ++ccnt;
		do {
			cur = st[top--], ins[cur] = 0;
			col[cur] = ccnt;
		} while(cur != u);
	}
}
bool check(int x) {
	int L, R; idcnt = ccnt = 0;
	for(ri i = 1; i <= n*2; ++i) adj[i].clear();
	for(ri i = 1; i <= vcnt; ++i) dfn[i] = low[i] = col[i] = 0;
//	cout<<"Checking dis of "<<x<<endl;
	for(ri i = 1; i <= n; ++i) {
//		cerr<<i<<endl;
		for(ri k = 0; k <= 1; ++k) {
			L = lower_bound(a+1, a+n*2+1, node {ver[i][k]-x+1, 0, 0})-a, R = lower_bound(a+1, a+n*2+1, node {ver[i][k]+x, 0, 0})-a-1;
			int pos = lower_bound(a+1, a+n*2+1, node {ver[i][k], i, 0})-a;
//			cerr<<ver[i][k]<<' '<<L<<' '<<pos<<' '<<R<<endl;
			link(1, 1, n*2, L, pos-1, i+k*n);
//			cerr<<"KUAIKULE"<<endl;
			link(1, 1, n*2, pos+1, R, i+k*n);
//			cerr<<"KELIAN"<<endl;
		}
	}
	for(ri i = 1; i <= n*2; ++i) if(!dfn[i]) tarjan(i);
	for(ri i = 1; i <= n; ++i) {
		if(col[i] == col[i+n]) return 0;
	}
	return 1;
}	
int main() {
//	freopen("1.out", "w", stdout);
	scanf("%d", &n);
	for(ri i = 1; i <= n; ++i) 
		scanf("%d%d", &ver[i][0], &ver[i][1]), a[i*2-1] = node {ver[i][0], i, 0}, a[i*2] = node {ver[i][1], i, 1};
	sort(a+1, a+n*2+1);
//	for(ri i = 1; i <= n*2; ++i) cout<<a[i].pos<<' '<<a[i].id<<' '<<a[i].ty<<endl;
	build(1, 1, n*2);
	int l = 0, r = 1e9, ans = 0;
	while(l <= r) {
		if(check(mid)) ans = mid, l = mid+1;
		else r = mid-1;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 172928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
inline ll read(){
    ll res=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
    return res*f;
}
void write(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10|'0');
}
signed main(){
    int a=read();
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++)
        if(i*j==a){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#define int long long
using namespace std;
int ans=(1LL<<31)-1,x[105],n;
signed main(){
	int n;cin>>n;
	for(int i=1;i<=n;++i)cin>>x[i];
	for(int i=1;i<=100;++i){
		int tmp=0;
		for(int j=1;j<=n;++j){
			tmp+=(i-x[j])*(i-x[j]);
		}
		ans=min(ans,tmp);
	}cout<<ans<<endl;
	return 0;
}


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

using namespace std;
using nagai = long long;
#define sz(x) int((x).size())

const int N=200200;
const int mod=1e9+7;
int mu(int a,int b){
	 return (nagai)a*b%mod;
}
void ad(int&a,int b){
	 if((a+=b)>=mod)a-=mod;
}
int pw(int a,int b,int c=1){
	 for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
	 return c;
}
int dv(int a,int b){
	 return mu(a,pw(b,mod-2));
}

int fact[N];
int rfact[N];

int C(int a,int b){
	if(a<b)return 0;
	return mu(fact[a],mu(rfact[b],rfact[a-b]));
}
int inv2=(mod+1)/2;
int badw[N],badb[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	fact[0]=1;
	for(int i=0;i+1<N;++i)
		fact[i+1]=mu(fact[i],i+1);
	rfact[N-1]=dv(1,fact[N-1]);
	for(int i=N-1;i>0;--i)
		rfact[i-1]=mu(rfact[i],i);
	int b,w;
	cin>>b>>w;
	for(int i=1;i<N;++i){
		 badw[i]=dv(mu(inv2,C(i-1,w-1)),pw(2,i-1));
		 ad(badw[i],badw[i-1]);
		 badb[i]=dv(mu(inv2,C(i-1,b-1)),pw(2,i-1));
		 ad(badb[i],badb[i-1]);
	}
//	cerr<<badb[1]<<' '<<badw[1]<<'\n';
	for(int i=1;i<=b+w;++i){
		int prgood=(1-badw[i-1]-badb[i-1]);
		prgood%=mod;
		if(prgood<0)prgood+=mod;
//		cerr<<prgood<<'\n';
		int ans=mu(prgood,inv2);
		ad(ans,mu(badw[i-1],1));
		ad(ans,mu(badb[i-1],0));
		cout<<ans<<'\n';
	}
	return 0;
}



Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int n, q, s, t, x, d, u, j;
typedef pair<int,int> P;
P pr[400005];
set<int> st;
int main(){
    scanf("%d%d", &n, &q);
    for(int i = 0; i < n; i++){
        scanf("%d%d%d", &s, &t, &x);
        pr[u++] = P{s-x, x};
        pr[u++] = P{t-x, x};
    }
    sort(pr, pr+u);
    for(int i = 0; i < q; i++){
        scanf("%d", &d);
        while(j < u && pr[j].first <= d){
            auto it = st.find(pr[j].second);
            if(it == st.end()) st.insert(pr[j].second);
            else st.erase(it);
            j++;
        }
        printf("%d\n", st.empty() ? -1 : *st.begin());
    }
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll MOD = 1000000007ll;
ll N;
map<ll,ll> m;
ll rec(ll n){
	if(n<0ll)return 0ll;
	if(n==0ll)return 1ll;
	map<ll,ll>::iterator it = m.find(n);
	if(it!=m.end())return it->sec;
	return m[n]=(rec(n/2-1)+rec(n/2-!(n&1))+rec(n/2))%MOD;
}
int main(){
	cin >> N;
	cout << rec(N) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
int r,c,d[101][101],sum,i,j,all;
int main(void){
  cin>>r>>c;
  for(i=0;i<r;i++){
    sum=0;
    for(j=0;j<c;j++){
      cin>>d[i][j];
      sum+=d[i][j];
    }
    d[i][c]=sum;
    all+=sum;
  }
  d[r][c]=all;
  for(j=0;j<c;j++){
    sum=0;
    for(i=0;i<r;i++){
      sum+=d[i][j];
    }
    d[r][j]=sum;
  }
  for(i=0;i<r+1;i++){
    for(j=0;j<c+1;j++){
      if(j==0)cout<<d[i][j];
      else cout<<" "<<d[i][j];
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;
//西暦⇒時代の歴
struct Data
{
    string s;
    ll E, W;
};
int main()
{
    int n, w;
    while (cin >> n >> w, n || w)
    {
        int a[20] = {0};

        for (int i = 0; i < n; ++i)
        {
            int v;
            cin >> v;
            a[v / w]++;
        }
        int maxV = 0;
        int cnt = 0;
        for (int i = 0; i <= 10; ++i)
        {
            maxV = max(maxV, a[i]);
            if (a[i])
                cnt = i;

            //cout << a[i] << endl;
        }
        double ans = 0.0;

        for (int i = 0; i <= cnt; ++i)
        {
            double t = (double)(cnt - i) / cnt;
            double tt = (double)t / maxV;
            ans += (double)a[i] * tt;
        }
        ans += 0.01;
        cout << ans << endl;
    }
}


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

int main(void){
    int n,i,b,j;
    int S[13],H[13],C[13],D[13];
    char c;
    char s[256],s2[256];
    
    
    for(i=0;i<13;i++){
        S[i]=H[i]=C[i]=D[i]=0;
    }
    
    fgets(s,256,stdin);
    j=0;
    while (s[j]!='\n'&&s[j]!='\0') {
        j++;
    }
    s[j]='\0';
    n=atoi(s);
    
    if(n<0||52<n){
        printf("error\n");
        return 0;
    }
    
    
    for(i=0;i<n;i++){
        fgets(s,256,stdin);
        j=0;
        while (s[j]!='\n'&&s[j]!='\0') {
            j++;
        }
        s[j]='\0';
        c=s[0];

        j=2;
        
        while (s[j]!='\0'&&s[j]!='\n') {
            s2[j-2]=s[j];
            j++;
        }
        s2[j-2]='\0';
        b=atoi(s2);
        if(b<1||13<b){
            printf("error\n");
            return 0;
        }
        
        switch (c) {
            case 'S':
                S[b-1]=1;
                break;
            case 'H':
                H[b-1]=1;
                break;
            case 'C':
                C[b-1]=1;
                break;
            case 'D':
                D[b-1]=1;
                break;
            default:
                printf("error\n");
                return 0;
                break;
        }
    }
    
    for(i=0;i<13;i++){
        if(S[i]==0){
            printf("S %d\n",i+1);
        }
    }
    for(i=0;i<13;i++){
        if(H[i]==0){
            printf("H %d\n",i+1);
        }
    }
    for(i=0;i<13;i++){
        if(C[i]==0){
            printf("C %d\n",i+1);
        }
    }
    for(i=0;i<13;i++){
        if(D[i]==0){
            printf("D %d\n",i+1);
        }
    }
    
    return 0;
}


Measured memory_bytes: 2100