akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
#define int long long int
#define double long double
using namespace std;
#define INT_MAX 1000000005
#define INF 1000000005
const int MAX_N = 1 << 17;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;


typedef struct{
    int check[8];
    int sum = 0;
    int now;

} checker;
typedef struct {
    std::vector<int> nextnode;
} nenode;




signed main()
{
int n,m;
std::cin >> n >> m;
std::vector<nenode> nodelist(n);
for(int i = 0; i < m; i++){
    int a,b;
    std::cin >> a >> b;
    nodelist[a - 1].nextnode.push_back(b - 1);
    nodelist[b - 1].nextnode.push_back(a - 1);
}

std::queue<checker> path;
int sum = 0;
checker start;
for(int i = 0; i < 8; i++){
    start.check[i] = 0;
}
start.check[0] = 1;
start.sum++;
start.now = 0;
path.push(start);
while(!path.empty()){
    checker now = path.front();
    path.pop();
    if(now.sum == n){
        sum++;
        continue;
    }
    for(int i = 0; i < nodelist[now.now].nextnode.size(); i++){
        if(now.check[nodelist[now.now].nextnode[i]] == 1){
           continue;
        } else {
            checker next;
            for(int k = 0; k < 8; k++){
                next.check[k] = now.check[k];
            }
            next.check[nodelist[now.now].nextnode[i]] = 1;
            next.sum = now.sum + 1;
            next.now = nodelist[now.now].nextnode[i]; 
            path.push(next);
        }
    }
} 
std::cout << sum << std::endl;

return 0;
}

Measured memory_bytes: 640
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int h,w;
vector<string> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h>>w;
    for (int i = 0; i < h; i++)
    {
        string temp;
        cin >> temp;
        a.push_back(temp);
    }
    int count=0;
    rep(i,h){
        rep(j,w){
            if(a[i][j]=='#'){
                count++;
            }
        }
    }
    int count1=1;
    int i=0;
    int j=0;
    while(true){
        while(true){
            if(i==w-1){
                break;
            }
            if(a[j][i+1]=='#'){
                i++;
                count1++;
            }
            else{
                break;
            }
        }
        if(j==h-1)break;
        if(a[j+1][i]=='#'){j++;count1++;}
        else{
            return cout<<"Impossible"<<"\n",0;
        }
    }
    //cout<<i<<" "<<j<<"\n";
    if(count1==count&&i==w-1&&j==h-1)return cout<<"Possible"<<"\n",0;
    else{
        return cout<<"Impossible"<<"\n",0;
    }
}


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

int main() {
  int N,M;
  cin >> N >> M;

  vector<int> a(60);
  vector<int> b(60);
  vector<int> c(60);
  vector<int> d(60);

  for(int i=1;i<=N;i++) {
    cin >> a[i] >> b[i];
  }
  for(int j=1;j<=M;j++) {
    cin >> c[j] >> d[j];
  }

  int ma,mi;
  for(int i=1;i<=N;i++)  {
    ma=-100000000;
    mi=400000000;
    int manum=0,minum=0;
    for(int j=1;j<=M;j++) {
      if(ma<fabs(a[i]-c[j])+fabs(b[i]-d[j])) {
        manum=j;
        ma=fabs(a[i]-c[j])+fabs(b[i]-d[j]);
      }
      if(mi>fabs(a[i]-c[j])+fabs(b[i]-d[j])){
        minum=j;
        mi=fabs(a[i]-c[j])+fabs(b[i]-d[j]);
      }
     // ma=max(ma,fabs(a[i]-c[j])+fabs(b[i]-d[j]));
     // mi=min(mi,fabs(a[i]-c[j])+fabs(b[i]-d[j]));
    }
    cout << minum << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
 
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int a, b, c;
    cin >> a >> b >> c;
    cout << (int)(a * b / 2.0) << endl;
}


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

int main() {

  int N, T, A;
  cin >> N >> T >> A;
  int H[100010];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  double distance;
  double last_dist = (1 << 16);
  int now_top;
  for (int j = 0; j < N; j++) {
    distance = abs(A - (T - H[j] * 0.006));
    if (last_dist > distance) { now_top = j + 1; last_dist = distance;}
  }

  cout << now_top << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
template <class T>
istream &operator>>(istream &s, vector<T> &v) { for (T &x : v) { s >> x; } return s; }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
const ll INF = 1LL<<60;

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

    int N, M;
    cin >> N >> M;
    vi A(M);
    vi C(M, 0);
    rep(i, M) {
        int B; cin >> A[i] >> B;
        rep(j, B) {
            int _c; cin >> _c;
            C[i] |= 1 << (_c - 1);
        }
    }

    vector<vector<ll>> dp(M+1, vector<ll>((1<<N), INF));
    dp[0][0] = 0;

    rep(i, M) {
        rep(j, 1<<N) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j | C[i]], dp[i][j] + A[i]);
        }
    }

    ll ans = dp.back().back();
    if (ans == INF) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;


int main(){
  int h=0;
  rep(i,4){
    char c; cin >> c;
    if(c=='+'){h++;}else{ h--;}
  }
  cout << h << endl;
  return 0;
}


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

int ok = 0,N;

void d(int sum) 
{
	if (ok != 0)return;
	if (sum == N)ok = 1;
	if (sum > N)return;
	d(sum + 4);
	d(sum + 7);
}

int main()
{
	cin >> N;

	d(0);

	if (ok)cout <<"Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))
A = sorted(L)
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if A[i] + A[j] > A[k] and A[i] != A[j] != A[k]:
                ans += 1

print(ans)


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

namespace AtCoder.Contests.ABC164
{
    /// <summary>
    /// 
    /// </summary>
    static class A
    {
        static void Main(string[] args)
        {
            var s = NextInt();
            var w = NextInt();
            Console.WriteLine(s <= w ? "unsafe" : "safe");
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


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

#define p 1000000007

int  main()
{
    int i,n,j,k;
    
    cin >> n;
    int hap[3][n];
    int dp[3][n];
    
    for(i=0;i<n;i++)
        cin >> hap[0][i] >> hap[1][i] >> hap[2][i];
    
    dp[0][0] = hap[0][0];
    dp[1][0] = hap[1][0];
    dp[2][0] = hap[2][0];
    
    for(i=1;i<n;i++)
    {
        dp[0][i] = hap[0][i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i] = hap[1][i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i] = hap[2][i]+max(dp[0][i-1],dp[1][i-1]);
    }
    
    cout << max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])) << endl;
    
}

Measured memory_bytes: 2560
function Main() {
  const input = require("fs").readFileSync("/dev/stdin", "utf-8").trim();
  const lines = input.split('\n');
  const n = lines[0].split(' ')[0];
  const l = lines[0].split(' ')[1];
  const strs = lines.slice(1);
  strs.sort();
  console.log(strs.join(''));
}

Main();


Measured memory_bytes: 12232
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]
t.sort()

l = deque([])
cnt = 0
for i in range(n):
    if len(l) > 0:
        if l[0] + k < t[i]:
            cnt += 1
            l = deque([])
    l.append(t[i])

    if len(l) >= c:
        cnt += 1
        l = deque([])
if len(l) > 0:
    cnt += 1
print(cnt)

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

typedef long long ll;
typedef long double ld;

#define FOR(i,a) for (int i=0;i<(a);++i)
#define FORD(i,a) for (int i=(a)-1;i>=0;i--)
#define FORT(i,a,b) for (int i=(a);i<=(b);++i)
#define FORTD(i,b,a) for (int i=(b);i>=(a);--i)
#define trav(i,v) for (auto i : v)
#define fr first
#define sc second

const int N=1e5+6;
struct node{
    int par,ed,mxed;
    ll sum,mx;
} dsu[N];
int x[N];
void make_node(int i,int k){
    dsu[i].par=i;
    dsu[i].mx=0;
    dsu[i].sum=k;
    dsu[i].ed=0;
    dsu[i].mxed=0;
}

int get(int p){
    if (dsu[p].par==p)return p;
    return dsu[p].par=get(dsu[p].par);
}

void unite(int a,int b,ll len){
    a=get(a);
    b=get(b);
    if (a!=b){
        dsu[a].mxed+=dsu[b].mxed;
        dsu[a].ed+=dsu[b].ed+1;
        dsu[a].sum+=dsu[b].sum;
        dsu[a].mx=max(len,max(dsu[a].mx,dsu[b].mx));
        dsu[b].par=a;
    }
    else{
        dsu[a].mx=max(dsu[a].mx,len);
        dsu[a].ed++;
    }
    if (dsu[a].sum>=dsu[a].mx)dsu[a].mxed=dsu[a].ed;
}
int main(){
    ios_base::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    FOR(i,n){
        cin>>x[i];
        make_node(i+1,x[i]);
    }
    vector<pair<int,pair<int,int> > > v;
    FOR(i,m){
        int l,a,b;
        cin>>a>>b>>l;
        v.push_back({l,{a,b}});
    }
    sort(v.begin(),v.end());
    int ans=0;
    FOR(i,m){
        unite(v[i].sc.fr,v[i].sc.sc,v[i].fr);
        //cout<<v[i].sc.fr<<" "<<v[i].sc.sc<<" "<<v[i].fr<<" "<<qan<<endl;
    }
    cout<<m-dsu[get(1)].mxed<<endl;
    return 0;
}


Measured memory_bytes: 5496
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

class DisjointSet{
    public:
        vector<ll> rank,p,siz;

        DisjointSet(){}
        DisjointSet(ll size){
            rank.resize(size,0);
            p.resize(size,0);
            siz.resize(size,1);
            rep(i,size) makeSet(i);
        }

        void makeSet(ll x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(ll x, ll y){
            return root(x) == root(y);
        }

    
        void unite(ll x, ll y){
            x = root(x);
            y = root(y);
            if(rank[x] > rank[y]){
                siz[x] += siz[y];
                p[y] = x;
            }
            else{
                siz[y] += siz[x];
                p[x] = y;
                if(rank[x] == rank[y]) rank[y]++;
            } 
        }
        ll root(ll x){
            if(x != p[x]){
                p[x] = root(p[x]);
            }
            return p[x];
        }

        ll size(ll x){
            return siz[root(x)];
        }

};

 
int main(){
    int N,M,K; cin >> N >> M >> K;
    DisjointSet uf(N);
    vector<int> ans(N);
    rep(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        if(!uf.same(a,b)) uf.unite(a,b);
        ans[a]--;
        ans[b]--;
    }
    rep(i,K){
        int a,b; cin >> a >> b;
        a--; b--;
        if(uf.same(a,b)) ans[a]--,ans[b]--;
    }
    rep(i,N){
        ans[i] += uf.size(i)-1;
        cout << ans[i] << " ";
    }
    cout << endl;


}

Measured memory_bytes: 3584
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C++ (GCC 5.4.1)
*/

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

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[]){
	int n,a,b;
	int nlst = 0;
	int cntp, cntq;

	cin >> n;
	vector<int> p(n), q(n), v(n);

	for(int i = 0; i < n; ++i) cin >> p[i];
	for(int i = 0; i < n; ++i) cin >> q[i];
	for(int i = 0; i < n; ++i) v[i] = i + 1;

	do{
		++nlst;
		cntp = 0;
		cntq = 0;

		for(int i = 0; i < n; ++i){
			if(v[i] == p[i])	++cntp;
			if(v[i] == q[i])	++cntq;
		}
		if(cntp == n)	a = nlst;
		if(cntq == n)	b = nlst;
	}
	while(next_permutation(v.begin(), v.end()));
	
	OUT(abs(a - b)) BR;
	RET;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

typedef long long ll;

const int p = 900000009;

void Sito(vector<int>& P)
{
    vector<bool> p(2500, true);
    p[0] = p[1] = false;
    for (int i = 2; i < 2500; ++i)
        if (p[i])
            for (int j = 2 * i; j < 2500; j += i)
                p[j] = false;
    for (int i = 0; i < 2500; ++i)
        if (p[i])
            P.push_back(i);
}

int Hasz(vector<ll>& a)
{
    int h = 0;
    for (int i = 0; i < a.size(); ++i)
        h = h * p + a[i];
    return h;
}

bool Kw(ll x)
{
    ll pie = sqrt(x);
    if (pie * pie == x)
        return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
    vector<int> P;
    Sito(P);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    map<int, int> M;
    multiset< pair<int, int> > S;
    bool jed = false;
    for (int i = 0; i < n; ++i)
    {
        vector<ll> po, wyk;
        for (int j = 0; j < P.size(); ++j)
        {
            int il = 0;
            while (a[i] % P[j] == 0)
            {
                a[i] /= P[j];
                ++il;
            }
            if (il % 3 != 0)
            {
                po.push_back(P[j]);
                wyk.push_back(il % 3);
            }
        }
        if (a[i] != 1)
        {
            if (Kw(a[i]))
            {
                po.push_back(sqrt(a[i]));
                wyk.push_back(2);
            }
            else
            {
                po.push_back(a[i]);
                wyk.push_back(1);
            }
        }
        if (po.size() == 0)
        {
            jed = true;
            continue;
        }
        vector<ll> odp;
        for (int j = 0; j < wyk.size(); ++j)
        {
            if (wyk[j] == 1)
                odp.push_back(2);
            if (wyk[j] == 2)
                odp.push_back(1);
        }
        int hpo = Hasz(po);
        int hwyk = Hasz(wyk);
        int hodp = Hasz(odp);
        M[hwyk] = hodp;
        M[hodp] = hwyk;
        S.insert(make_pair(hpo, hwyk));
    }
    int odp = 0;
    while (S.size() != 0)
    {
        pair<int, int> a = *S.begin();
        int il1 = 0;
        while (S.size() != 0 && (*S.begin()).first == a.first && (*S.begin()).second == a.second)
        {
            S.erase(S.begin());
            ++il1;
        }
        pair<int, int> b = make_pair(a.first, M[a.second]);
        int il2 = 0;
        while (S.size() != 0 && S.find(b) != S.end())
        {
            S.erase(S.find(b));
            ++il2;
        }
        odp += max(il1, il2);
    }
    if (jed)
        ++odp;
    cout << odp;
    return 0;
}


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

int main() {
    int H, W; cin >> H >> W;
    vector<vector<char>> a(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) cin >> a.at(i).at(j);
    }

    for (int i = 0; i < W + 2; i++) cout << "#";
    cout << endl;

    for (int i = 0; i < H; i++) {
        cout << "#";
        for (int j = 0; j < W; j++) {
            cout << a.at(i).at(j);
        }
        cout << "#" << endl;
    }

    for (int i = 0; i < W + 2; i++) cout << "#";
    cout << endl;
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        readLine();
        String[] input = readLine().split("");
        ArrayList<String> afterSort = new ArrayList<>();

        String before = "";
        for (int i = 0; i < input.length; i++) {
            if (before.equals(input[i])) continue;
            afterSort.add(before = input[i]);
        }

        Print(afterSort.size());
    }

    private static final Scanner __in = new Scanner(System.in);
    private static String readLine() {
        return __in.nextLine();
    }

    private static void Print(int m) {
        System.out.println(m);
    }
}


Measured memory_bytes: 32448
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=998244353;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
string X;
map<int, LL> memo;

LL Calc(int a) {
  int b = N/a;
  LL t = 0;
  rep(i, b) {
    t = t*2;
    if (X[i] == '1') ++t;
    t %= MOD;
  }

  bool nope = false;
  rep(i, N) {
    int idx = i%b;
    int val = X[idx]-'0';
    int times = i/b;
    if (times%2) {
      val = 1-val;
    }
    if (X[i]-'0' < val) {
      nope = true;
      break;
    }

    if (X[i]-'0' > val) {
      break;
    }
  }

  if (!nope) {
    ++t;
    //t += MOD-1;
    if (t >= MOD) t -= MOD;
  }
  return t;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> N;
  cin >> X;
  
  LL ans = 0;
  rreps(a, 1, N+1) {
    if (a%2 == 0) continue;
    if (N%a) continue;
    memo[a] = Calc(a);
    //cout << a << ": " << memo[a] << endl;
    for (int t=a*3; t<=N; t+=a+a) {
      if (N%t) continue;
      assert(t%2);
      assert(memo.count(t));
      memo[a] += MOD - memo[t];
      if (memo[a] >= MOD) memo[a] -= MOD;
    }
    //cout << a << ": " << memo[a] << endl;
    int b = N/a;
    ans += 2 * memo[a] * b;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 720
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad 

main :: IO ()
main = readLn >>= main'
    where
        main' n = replicateM (n - 1) breads >>= mapM_ print . solve

solve :: [[Int]] -> [Int]
solve ([c, s, f] : xs) = calc (s + c) xs : solve xs
solve _ = [0]

calc :: Int -> [[Int]] -> Int
calc n ([c, s, f] : xs) = calc (f * (max sr nr) + c) xs
    where
        sr = s `div` f
        (r, m) = n `divMod` f
        nr
            | m > 0 = r + 1
            | otherwise = r
calc n _ = n

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

Measured memory_bytes: 1148
#include<bits/stdc++.h>
/*#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>*/
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define rep1(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>(b);--i)
#define per1(i,a,b) for(int i=a;i>=(b);--i)
#define LL long long
#define inf 0x7f7f7f7f
#define N 10010
using namespace std;
int a[N];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int i=0;
	while(~scanf("%d",&a[i++]));
	sort(a,a+i-1,cmp);
	printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
}



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

int N;
#define int long long

signed main()
{
  cin >> N;
  map<int, int> input;

  vector<int> ball(N);
  for (int i = 0; i < N; i++)
  {
    int num;
    cin >> num;
    input[num]++;
    ball[i] = num;
  }
  long long ans = 0;
  for (auto i = input.begin(); i != input.end(); ++i)
  {
    if (i->second > 1)
    {
      ans += (i->second) * (i->second - 1) / 2;
    }
  }
  for (int k = 0; k < N; k++)
  {
    int num = input[ball[k]];
    if (ans - (num - 1) > 0)
    {
      cout << ans - (num - 1) << endl;
    }
    else
    {
      cout << 0 << endl;
    }
  }
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(5);
  rep(i,n){
    string s; cin>>s;
    char c=s[0];
    if(c=='M') a[0]++;
    if(c=='A') a[1]++;
    if(c=='R') a[2]++;
    if(c=='C') a[3]++;
    if(c=='H') a[4]++;
  }
  ll ans=0;
  
  rep(i,5){
    irep(j,i+1,5){
      irep(k,j+1,5){
        ans+=a[i]*a[j]*a[k];
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.awt.Point;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
     
    static int n, k, s;
    
    static int count;
    static int[] shugo;
    
    static void dfs(int index)
    {
    	if(index == k)
    	{
    		int sum = 0;
    		for (int i = 0; i < shugo.length; i++) sum += shugo[i];
    		if(sum == s) count++;
    		return;
    	}
    	
    	int prenum = 0;
    	if(index != 0) prenum = shugo[index - 1];
    	for (int i = prenum+1; i <= n; i++) {
			shugo[index] = i;
			dfs(index + 1);
		}
    	
    }
    
    static void start()
    {
    	count = 0;
    	shugo = new int[k];
    	
    	dfs(0);
    	
    	System.out.println(count);
    }
     
    public static void main(String[] args)
    {
        Scanner sca = new Scanner(System.in);
        
        
        
        while(true)
        {
        	n = sca.nextInt();
        	k = sca.nextInt();
        	s = sca.nextInt();
        	
        	if(n == 0) break;
            
            start();
        }
        
    }
}

Measured memory_bytes: 20588
#-*-coding:utf-8-*-

import sys

def main():
    x,y = map(int,input().split())

    if x >= y:
        print("No")

    else:
        for crane in range(x+1):
            for turtle in range(x+1-crane):
                if crane+turtle==x and 2*crane+4*turtle==y:
                    print("Yes")
                    sys.exit()
        print("No")

if __name__ == "__main__":
    main()

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

int main(){
    int N;
    cin >> N;
    string S,T;
    cin >> S >> T;
    for(int i=0;i<N;i++){
        cout << S[i] << T[i];
    }
    cout << endl;
    return 0;
}

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

int main()
{
   int k;
  cin>>k;
  int a,b;
 cin>>a>>b;
  int i=a;
  for(;i<=b;i++)
  {
    if(i%k==0)
    {cout<<"OK";
     break;
    }
  }
  
  if(i>b)cout<<"NG";
  
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG




int main() {
  ll N;
  cin >> N;
  vector<ll> ans(10007);
  //vector<vector<int>> data(3, vector<int>(4));

  //int x, y, z;

  for (int x = 1; x <= 99; x++){
    for (int y = 1; y <= 99; y++){
      for (int z = 1; z <= 99; z++){
        int tmp = x*x + y*y + z*z + x*y + y*z + z*x;
        if (tmp > 10000) continue;
        ans[tmp]++;
      }
    }
  }
  for(int i=1; i<=N;i++){
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define MAX 110
#define INF 100000000
using namespace std;

int main(){
    int n,p[MAX],i,j,l,k,q;
    int m[MAX][MAX]={};
    cin>>n;
    for(i=0;i<n;i++)cin>>p[i]>>p[i+1];
    for(i=1;i<=n;i++)m[i][i]=0;
    for(l=2;l<=n;l++){
        for(i=1;i<=n-l+1;i++){
            j=i+l-1;
            m[i][j]=INF;
            for(k=i;k<j;k++){
                q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
                m[i][j]=min(m[i][j],q);
            }
        }
    }
  cout<<m[1][n]<<endl;
}

  




Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
map<string, int> mp;
string str[4] = { "AC","WA","TLE","RE" };
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < 4; i++)
		mp[str[i]] = 0;
	for (int i = 0; i < n; i++) {
		string temp;
		cin >> temp;
		mp[temp]++;
	}
	for (int i = 0; i < 4; i++) {
		cout << str[i] << " x " << mp[str[i]] << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int g[102], m;
int cnt;

void shell_sort(int n, int *a)
{
	int i, j, h, lim;
	int key;

	lim = n / 9;		// 要素数/9
	if (lim < 40) lim = 40;
	
	g[0] = 1;
	m = 0; do m++, g[m] = 3*g[m-1]+1;
	while (g[m] < n && g[m] <= lim);

	cnt = 0, h = g[m-1];
	while (h > 0) {
		for (i = h; i < n; i++) {
			key = a[i];
			j = i-h; while (j >= 0 && a[j] > key) {
				cnt++;
				a[j+h] = a[j];
				j -= h;
			}
			a[j+h] = key;
		}
		h /= 3;
	}
}

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int i;
	if (n == 0) { pc('0'); return; }
	i = 0; while (n) buf[i++] = n%10 +'0', n /= 10;
	while (i) pc(buf[--i]);
}

int a[1000002];

int main()
{
	int N, i;

	N = in(); for (i = 0; i < N; i++) a[i] = in();

	shell_sort(N, a);
	
	mypr(m), pc('\n');
	mypr(g[m-1]); for (i = m-2; i >= 0; i--) pc(' '), mypr(g[i]); pc('\n');
	mypr(cnt), pc('\n');
	for (i = 0; i < N; i++) mypr(a[i]), pc('\n');

	return 0;
}



Measured memory_bytes: 5492
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int i,j,c=1,d[3010][3010],f[3010][3010];
int main(){
  char a[3010],b[3010],s[3010]={};
  scanf("%s %s",a,b);
  for(i=0;a[i];i++){
    for(j=0;b[j];j++){
      if(a[i]==b[j]){
	d[i+1][j+1]=d[i][j]+1;
	f[i+1][j+1]=3;
      }
      if(d[i+1][j+1]<d[i+1][j]){
	d[i+1][j+1]=d[i+1][j];
	f[i+1][j+1]=2;
      }
      if(d[i+1][j+1]<d[i][j+1]){
	d[i+1][j+1]=d[i][j+1];
	f[i+1][j+1]=1;
      }
      //printf("%d:%d ",d[i][j],f[i][j]);
    }//printf("%d:%d\n",d[i][j],f[i][j]);
  }
  //for(j=0;b[j];j++)printf("%d:%d ",d[i][j],f[i][j]);
  //printf("%d:%d\n",d[i][j],f[i][j]);
  while(c){//printf("%d %d\n",i,j);
    c=f[i][j];
    if(c==3)s[d[i][j]]=a[i-1];
    if(c&1)i--;
    if(c&2)j--;
  }
  printf("%s\n",s+1);
}


Measured memory_bytes: 70784
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0

for i in range(N):
    if B[i] >= A[i] and (B[i]-A[i]) >= A[i+1]:
        ans += A[i] + A[i+1]
        A[i] = 0
        A[i+1] = 0
    elif B[i] >= A[i] and (B[i]-A[i]) < A[i+1]:
        ans += B[i]
        A[i+1] -=  (B[i]-A[i])
        A[i] = 0
    else:
        ans += B[i]
        A[i] -= B[i]
        
print(ans)

Measured memory_bytes: 19648
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner dataScanner = new Scanner(System.in);
        int numCards = Integer.parseInt(dataScanner.nextLine());
        String[] dataStr = dataScanner.nextLine().split(" ");
        int[] dataInt= new int[numCards];
        for (int i = 0; i < numCards; i++) {
            dataInt[i] = Integer.parseInt(dataStr[i]);
        }
        Arrays.sort(dataInt);
        int diff = 0;
        for (int i = 0; i < numCards; i++) {
            if (i % 2 == 0) {
                diff = diff + dataInt[numCards - i - 1];
            } else {
                diff = diff - dataInt[numCards - i - 1];
            }
        }
        System.out.println(diff);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int parent[100001];
int ans[100001];
pair<char,int> query[100001];

void Init(int n){

    for(int i=1;i<=n;++i)
        ans[i] = parent[i];

}

int Find(int x){ 
    
    return x==ans[x]?x:(ans[x]=Find(ans[x])); 

}

void Union(int x, int y){
   
    ans[Find(x)] = Find(y); 

}

int main(){

    cin.sync_with_stdio(false);

    while(1){

        int N,Q;
        cin >> N >> Q;

        if(N==0 && Q==0)break;

        parent[1] = 1;

        for(int i=2;i<=N;++i){

            int x;

            cin >> x;

            parent[i] = x;

        }

        Init(N);

        int cnt = 0;

        for(int i=0;i<Q;++i){

            string str;
            int x;

            cin >> str >> x;

            if(str[0]=='M' && ans[x] == x)continue;

            query[cnt].first  = str[0];
            query[cnt].second = x;
            ++cnt;

            if(str[0]=='M') ans[x] = x;

        }

        long long sum = 0;

        for(int i=cnt-1;i>=0;--i){

            pair<char,int> p = query[i];

            if(p.first == 'Q'){

                sum += Find(p.second);

            } else {

                Union(p.second, parent[p.second]);

            }

        }
       
        cout << sum << endl;

    }

    return 0;

}

Measured memory_bytes: 2920
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>

int main(void) {
    int64_t N;
    scanf("%lld", &N);
    int64_t arr[N];
    int64_t i;
    for (i=0; i < N; ++i) {
        scanf("%lld", arr+i);
    }
    int64_t psum=0, ans=0;
    for (i=0; i < N; ++i) {
        ans+=(arr[i]*psum);
        psum+=arr[i];
        ans%=(int64_t)(1e9+7);
        psum%=(int64_t)(1e9+7);
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 3288
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            if (n == 1) {
                if (a[0] == k) out.println("POSSIBLE");
                else out.println("IMPOSSIBLE");
                return;
            }
            Arrays.sort(a);
            int gcd = -1;
            int max = 0;
            for (int i = 0; i < n; i++) {
                max = Math.max(max, a[i]);
                if (a[i] == k) {
                    out.println("POSSIBLE");
                    return;
                }
                if (i > 0) {
                    int temp = gcd(a[i], a[i - 1]);
                    if (gcd == -1) gcd = temp;
                    else gcd = gcd(temp, gcd);
                }

            }
            if (k % gcd == 0 && k <= max) out.println("POSSIBLE");
            else out.println("IMPOSSIBLE");
        }

        public int gcd(int a, int b) {
            if (b == 0) return a;
            return gcd(b, a % b);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

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

    }
}



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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;

    char prev = s[0];
    for (int i = 1; i < 4; ++i){
        if(prev == s[i]){
            cout << "Bad" << endl;
            return 0;
        }
        prev = s[i];
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

using namespace std;

int n, a[2020];
bitset<4000002> dp, cur;

int main(){

    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a + i);

    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        cur = dp<<a[i];
        dp |= cur;
    }

    deque<int> v;
    for (int i = 1; i <= 2000 * 2000; i++) {
        if (dp[i]) v.push_back(i);
    }

    while ((int)v.size() > 2) {
        v.pop_front();
        v.pop_back();
    }

    cout << v[0] << endl;

    return 0;
}


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

#define ll long long
#define MAX 10005
int main()
{
            ll q,n;
            cin>>q>>n;
            map<long long,long long>f,f1;

            ll ac=0,wa=0,sum=0;

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

                    if(s1=="AC" && f[a]==0){
                        ac++;

                        wa+=f1[a];

                        f[a]=1;
                    }
                    if(f[a]==0){

                        f1[a]++;
                    }



            }


        cout<<ac<<" "<<wa<<endl;

       return 0;
}

Measured memory_bytes: 12800
a,b,c=map(int,input().split())
k=int(input())
t=0
while True:
  if a>=b:
    b=b*2
    t=t+1
  elif b>=c:
    c=c*2
    t=t+1
  if a<b and b<c:
    print("Yes")
    break  
  elif t==k:
    print("No")
    break

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

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }

    int q;
    cin >> q;
    for(int i = 0; i < q; ++i){
        int b, m, e;
        cin >> b >> m >> e;
        rotate(a.begin() + b, a.begin() + m, a.begin() + e);
    }

    for(int i = 0; i < a.size(); ++i){
        if(i){
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3160
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long

int n, m;
int a[1000];

int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d%d", &n, &m);
  int s = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  int threshold = s;
  sort(a, a + n);
  reverse(a, a + n);
  if(a[m - 1] * 4 * m >= threshold) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
def isStable(lis1, lis2):
    ret = True
    for i in range(len(lis1)-1):
        if lis1[i][1] == lis1[i+1][1]:
           ret = (lis1[i+1] in lis2[(lis2.index(lis1[i])+1):]) and ret
    return ret
    
N = int(input())
cards = input().split()

B = list(cards)
for i in range(N):
    for j in range(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            temp = B[j]
            B[j] = B[j-1]
            B[j-1] = temp

print(' '.join(B))
print('Stable' if isStable(B, cards) else 'Not stable')

S = list(cards)
for i in range(N):
    minj = i
    for j in range(i, N):
        if S[j][1] < S[minj][1]:
            minj = j
    temp = S[i]
    S[i] = S[minj]
    S[minj] = temp

print(' '.join(S))
print('Stable' if isStable(S, cards) else 'Not stable')


    

Measured memory_bytes: 7800
n,m = map(int,input().split())
a = []
for _ in range(m):
    a.append(list(map(int, input().split())))
a.sort(reverse=True)

ans = 1
p = n+1
for i in range(m):
    if p == n+1:
        p = a[i][0]

    elif p < a[i][1]:
        pass
    else:
        p = a[i][0]
        ans += 1
print(ans)


Measured memory_bytes: 27872
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;
int has[1000001];
int coun[1000001];

int main()
{
	int n;s(n);
	vector<int> vec(n+1);
	
	for(int i = 0;i<n;i++)
	{
		cin>>vec[i];
		
		if(coun[vec[i]] >= 2) continue;
		
		coun[vec[i]]++;
		
		for(int j = vec[i];j<=1000000;j+=vec[i]) has[j]++;
		
	}
	
	int ans = 0;
	
	for(int i = 0;i<n;i++)
	{
		if(has[vec[i]] == 1) ans++;	
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11756
#include<iostream>

using namespace std;

int main()
{
    int num = 0;
    int a[10000] = { };
    long int max = -1000000, min = 1000000, sum = 0;
    
    cin >> num;
    
    for(int i = 0; i < num; i++){
        cin >> a[i];
        
        if(max < a[i])
            max = a[i];
        if(min > a[i])
            min = a[i];
        
        sum += a[i];
    }
    
    cout << min << " " << max << " " << sum << endl;
    
    return 0;
}

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

int main() {
  string str1, str2, str3;
  cin >> str1 >> str2 >> str3;
  char A = str1.at(0);
  char B = str2.at(0);
  char C = str3.at(0);
  cout << A;
  cout << B;
  cout << C << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i, N) {
		cin >> A.at(i);
	}
	vector<int> answer(N);
	rep(i, N) {
		answer.at(A.at(i) - 1) = i + 1;
	}
	rep(i, N - 1) {
		cout << answer.at(i) << " ";
	}
	cout << answer.at(N - 1) << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する

int main(){
    int x;
    cin >> x;
    if(x < 1200){cout << "ABC";}else{cout << "ARC";}
}

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

int main()
{
    string s;
    cin >> s;
    
    string days[] = 
    {
        "SUN",
        "MON",
        "TUE",
        "WED",
        "THU",
        "FRI",
        "SAT"
    };

    for (int i = 0; i < 7; i++)
    {
        if (s == days[i])
        {
            cout << 7 - i << endl;
        }
    }

    return 0;
}


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

public static class Program {
    public static void Main() {
        long[] nda=Console.ReadLine().Split().Select(long.Parse).ToArray();
        long n=nda[0];
        long d=nda[1];
        long a=nda[2];

        var data=new List<Tuple<long,long>>();
        for(int i=0;i<n;i++){
            long[]xh=Console.ReadLine().Split().Select(long.Parse).ToArray();
            data.Add(new Tuple<long,long>(xh[0],(xh[1]+a-1)/a));
        }
        data.Sort();

        long ans=0;
        long now=0;
        long[] lazy=new long[n+1];
        int j=0;
        for(int i=0;i<n;i++){
            long x=data[i].Item1;
            long h=data[i].Item2;
            now-=lazy[i];
            h=Math.Max(0,h-now);
            ans+=h;
            now+=h;
            while(j<n&&data[j].Item1<=x+2*d)j++;
            lazy[j]+=h;
        }
        Console.WriteLine(ans);
    }
}

/*
まず、爆弾は固定ダメージですから、HP をすべて A で割っておくことで、A = 1 としてよいです。
敵を座標でソートして、敵を左から順に、なるべく右に爆弾を置いて倒します。
このとき巻き添えになる敵がたくさんいたら間に合いませんから、それは隣接差で遅延評価しましょう。
配列を用意して、それの累積和が与えたダメージになるようにしておきましょう。
ただし、累積和をとってはいけません。せっかく順番に動いていますから、現在の累積和を管理しておきましょう。
*/


Measured memory_bytes: 29400
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e2+10;
typedef long long ll;
ll a[maxn][maxn], n, m, ans;
ll cnt[maxn];
bool vis[maxn];
//ll st[maxn];

int main() {
    scanf("%lld%lld", &n, &m);
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=m; ++j)
            scanf("%lld", &a[i][j]);
    }
    ans = n, vis[0] = 1;
    for (int k=1; k<=m; ++k) {
        memset(cnt, 0, sizeof(cnt));
        ll mx = -1, pos = 1;
        for (ll i=1; i<=n; ++i) {
            for (ll j=1; j<=m; ++j) {
                if(!vis[a[i][j]]) {
                    ++cnt[a[i][j]];
                    break;
                }
            }
        }
        for (int i=1; i<=m; ++i) if(mx<cnt[i]) mx=cnt[i], pos=i;
        vis[pos] = 1;
        ans = min(ans, mx);
    }
    printf("%lld\n", ans);
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] d = new int[n];
		int num1 = 0;
		int num2 = 0;

		int cntarc = 0;
		int cntabc = 0;

		int cnt = 0;

		for (int i = 0; i < d.length; i++) {
			d[i] = sc.nextInt();
		}

		Arrays.sort(d);
		num1 = d[((d.length -1) / 2) + 1];
		num2 = d[(d.length -1) / 2];

		System.out.println(num1 - num2);

	}
}

Measured memory_bytes: 51308