akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
int n;
struct node{int col[4];
    node nxt(){ return node{col[1],col[2],col[3],col[0]};}
    friend bool operator <(node a,node b)
    {
        for (int i=0;i<4;i++)
            if (a.col[i]!=b.col[i]) return a.col[i]<b.col[i];
        return 0;
    }
}a[410],a1,a2,a3,a4;
map<node,int>mp;
void insert(node x,int v){for (int i=0;i<4;i++,x=x.nxt()) mp[x]+=v;}

ll ans,re;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%d%d%d%d",&a[i].col[0],&a[i].col[1],&a[i].col[2],&a[i].col[3]);    
        insert(a[i],1);    
    }
    for (int i=1;i<=n;i++)
    {
        insert(a[i],-1);
        for (int j=i+1;j<=n;j++)
        {
            insert(a[j],-1);
            for (int t=0;t<4;t++)
            {
                a1=node{a[j].col[1],a[i].col[0],a[i].col[3],a[j].col[2]};
                a2=node{a[i].col[1],a[j].col[0],a[j].col[3],a[i].col[2]};
                a3=node{a[j].col[1],a[j].col[0],a[i].col[1],a[i].col[0]};
                a4=node{a[i].col[3],a[i].col[2],a[j].col[3],a[j].col[2]};
                a[j]=a[j].nxt();                
                if (mp[a1]==0||mp[a2]==0||mp[a3]==0||mp[a4]==0) continue;
                re=1;
                re*=mp[a1];insert(a1,-1);
                re*=mp[a2];insert(a2,-1);
                re*=mp[a3];insert(a3,-1);
                re*=mp[a4];
                insert(a1,1);insert(a2,1);insert(a3,1);
                ans+=re;

            }
            insert(a[j],1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
#define first F
#define second S
#define PB push_back
#define mkp make_pair
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)

typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<int> > vvint;
typedef vector<vector<long long> > vvll;
typedef long long ll;

const ll MOD = 1000000007LL;

int n;
vvint vv;
ll dp[210][210][210];
vvll v;
vint sz;
void add(ll &a, ll b) {
	(a += b) %= MOD;
}

void dfs(int x, int pre) {
	// cout << x << " " << pre << endl;
	for(int y : vv[x]) {
		if(y == pre) continue;
		dfs(y, x);
	}
	if(pre != -1 && vv[x].size() == 1) {
		v[x][1] = 1;
		sz[x] = 1;
		return;
	}
	bool vis = true;
	reep(i, 0, vv[x].size()) {
		int y = vv[x][i];
		if(y==pre) continue;
		if(vis){
			vis=false;
			v[x]=v[y];
			sz[x]=sz[y];
			continue;
		}
		vll tmp(n + 2);
		reep(j, 1, sz[x] + 1) {
			reep(k, 1, sz[y] + 1) {
				reep(l, 1, sz[x] + sz[y] + 1) {
					add(tmp[l], v[x][j]*v[y][k] % MOD * dp[j][k][l] % MOD);
				}
			}
		}
		v[x] = tmp;
		sz[x] += sz[y];
	}
	// cout << "node " << x << endl;
	// rep(i, n) {
	// 	cout << i << " " << v[x][i] << endl;
	// }
	for(int i = n; i >= 0; i--) {
		v[x][i + 1] = v[x][i];
	}
	sz[x]++;
	// cout << "node " << x << endl;
	// rep(i, n) {
	// 	cout << i << " " << v[x][i] << endl;
	// }
}

void mainmain() {
	cin >> n;
	n++;
	vv = vvint(n);
	vint root(n);
	rep(i, n - 2) {
		int a, b;
		cin >> a >> b;
		vv[a].PB(b);
		vv[b].PB(a);
		root[b] = 1;
	}
	rep(i, n - 1) {
		if(!root[i]) {
			vv[n - 1].PB(i);
			vv[i].PB(n - 1);
		}
	}
	dp[0][0][0] = 1LL;
	rep(i, n) {
		rep(j, n) {
			rep(k, n) {
				if(i && k)    add(dp[i][j][k], dp[i - 1][j][k - 1]);
				if(j && k)    add(dp[i][j][k], dp[i][j - 1][k - 1]);
				if(i && j && k) add(dp[i][j][k], dp[i - 1][j - 1][k - 1]);
			}
		}
	}
	v = vvll(n, vll(n + 2));
	sz = vint(n);
	// cout << "n " << n << endl;
	dfs(n - 1, -1);
	ll ans = 0;
	rep(i, n + 1) {
		add(ans, v[n - 1][i]);
	}
	cout << ans << endl;
}


int main() {
	mainmain();
}

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

int main() {
  string a, b; cin >> a >> b;
  string ans;
  if (a.size() == b.size()) {
    if (a == b) ans = "EQUAL";
    else if (a > b) ans = "GREATER";
    else ans = "LESS";
  } else {
    if (a.size() > b.size()) ans = "GREATER";
    else ans = "LESS";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#l = list(map(int, input().split(' ')))

#num = int(input())
#S = str(input())
# 2 * N mas
# i = 1 or 2
# j = between 1 N
# C = 0
#
N=int(input())
A1_list=list(map(int, input().split(' ')))
A2_list=list(map(int, input().split(' ')))
a1_list = [0]
a2_list = [0]
#　累積和
for a1 in A1_list:
    a1_list.append(a1+a1_list[-1])
a1_list.pop(0)
# 累積和2
for a2 in A2_list:
    a2_list.append(a2+a2_list[-1])
a2_list.pop(0)
ans=0
if N == 1:
    ans = a1_list[0]+a2_list[0]
else:
    for i in range(0,N):
        if i > 0:
            tmp = a1_list[i] +  a2_list[-1] - a2_list[i-1]
            if ans < tmp:
                ans = tmp
        else:
            tmp = a1_list[i] +  a2_list[-1]
            if ans < tmp:
                ans = tmp

# print(a1_list)
# print(a2_list)
print(ans)

Measured memory_bytes: 3064
def rm_shuntsu(hand):
	for hai in set(hand):
		if (hai in hand) and (hai+1 in hand) and (hai+2 in hand):
			if len(hand) == 3: return True
			hand1 = hand[:]
			hand1.remove(hai);hand1.remove(hai+1);hand1.remove(hai+2)
			return is_hora(hand1)
	else: return False
		
def rm_kotsu(hand):
	for hai in set(hand):
		if hand.count(hai) >= 3:
			if len(hand) == 3: return True
			hand1 = hand[:]
			hand1.remove(hai);hand1.remove(hai);hand1.remove(hai)
			return is_hora(hand1)
	else: return False
	
def is_hora(hand):
	return rm_shuntsu(hand) or rm_kotsu(hand)
	
while True:
	try:
		hand = map(int, raw_input())
		ans = []
		for tumo in range(1,10):
			if hand.count(tumo) <= 3:
				for janto in set(hand+[tumo]):
					if 2 <= (hand+[tumo]).count(janto):
						hand1 = hand[:]+[tumo]
						hand1.remove(janto);hand1.remove(janto)
						if is_hora(hand1):
							ans.append(tumo)
							break
		print " ".join(map(str, sorted(ans))) if len(ans) > 0 else 0
	except:
		break

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

struct query {
    int no;
    int F;
    char C;
};

const int N_MAX = 1e5 + 1;
vector<query> q;

int main() {
    string str;
    int Q;
    cin >> str >> Q;

    q.resize(Q);
    for (auto &&v : q) {
        cin >> v.no;

        if (v.no == 2) {
            cin >> v.F;
            cin >> v.C;
        }
    }

    bool filp = false;
    string s;
    string e;
    s.reserve(q.size());
    e.reserve(q.size());

    for (auto &v : q) {
        if (v.no == 1) {
            filp = !filp;
        } else if (v.no == 2) {
            bool start = v.F == 1 ? true : false;

            if (!filp) {
                if (start) {
                    s = v.C + s;
                } else {
                    e = e + v.C;
                }
            } else {
                if (start) {
                    e = e + v.C;
                } else {
                    s = v.C + s;
                }
            }
        }
    }

    if (filp) {
        reverse(str.begin(), str.end());
        reverse(s.begin(), s.end());
        reverse(e.begin(), e.end());
        cout << e + str + s << endl;
    } else {
        cout << s + str + e << endl;
    }
}

Measured memory_bytes: 3960
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

static long long Gcd(long long m, long long n){
	long long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int main(){

  long long A,B;
  cin >> A >> B;

  long long n;
  if(A > B)
    n = Gcd(A,B);
  else
    n = Gcd(B,A);

  long long ans;
  ans = A * B / n;

  cout << ans;

  return 0;
  
}




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

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

        int n = sc.nextInt();
        int[] a = new int[n];

        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();

        Arrays.sort(a);

        long sum = 0;
        for(int i=0; i<a.length; i++) {
            sum += a[i];
        }

        System.out.println(a[0] + " " + a[a.length-1] + " " + sum);
    }
}



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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    string s, t;

    cin >> s >> t;

    cout << setprecision(20) << t+s << endl;

    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    long long a[n+1];
    a[0] = 0;
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i-1]+1 < a[i]){
            ans = -1;
            break;
        }
        if(a[i] == 0) continue;
        else if(a[i] == 1) ans++;
        else if(a[i-1]+1 == a[i]) ans++;
        else ans += a[i];
    }
    if(a[1] != 0) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<bitset>
#include<cassert>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int d[100],a[100];
int main()
{	int n,maxn=0,mn=100; scanf("%d",&n);
	if(n>=24){cout<<"0\n"; return 0;}
	for(rint i=1;i<=n;i++) scanf("%d",&d[i]),mn=min(mn,d[i]);
	if(mn==0){cout<<"0\n"; return 0;}
	if(n==23){cout<<"1\n"; return 0;}
	for(rint i=0;i<(1<<n);i++)
	{	for(rint j=1;j<=n;j++) if(i&(1<<j-1)) a[j]=24-d[j]; else a[j]=d[j];
		int minn=1000;
		for(rint j=1;j<=n;j++)
		{	for(rint k=1;k<j;k++)
			{	int now=max(a[j]-a[k],a[k]-a[j]);
				minn=min(minn,min(now,24-now));
			}
			minn=min(minn,min(a[j],24-a[j]));
		}
		maxn=max(maxn,minn);
	}
	cout<<maxn<<endl;
 	return 0;
}


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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  ll n, k;
  //string s;
  cin >> n >> k;
  
  ll ans = 0;
  vector<ll> A(n);
  
  rep(i,0,k){
    ll d;
    cin >> d;
    rep(i,0,d){
      ll a;
      cin >> a;
      A.at(a-1)++;
    }
  }
  
  rep(i,0,n){
    if(A.at(i) == 0)
      ans++;
  }
      
    
  
  //vector<ll> a(n);
  //queue<ll> q;
  //map<string,ll> d{};
  
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
ac = 0
wa = 0
tle = 0
re = 0
n = int(input())

for i in range(n):
    m = input()
    if m == "AC":
        ac = ac + 1
    elif m == "WA":
        wa = wa + 1
    elif m == "TLE":
        tle = tle + 1
    elif m == "RE":
        re = re + 1

print ("AC x " + str(ac) + "\n" + "WA x " + str(wa) + "\n" + "TLE x " + str(tle) + "\n" + "RE x " + str(re))

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using ull = unsigned long long;

constexpr ll kMod = 1000000007;
ll pow2mod(int n) {
  ll ret = 1;
  ll nowpow = 2;
  ll remain = n;
  while (remain > 0) {
    if (remain % 2 == 1) ret = (ret * nowpow) % kMod;
    remain /= 2;
    nowpow = (nowpow * nowpow) % kMod;
  }
  return ret;
}

int main(int argc, char* argv[]) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  /* */
  int n;
  cin >> n;

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

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

  if (n % 2 == 1) {
    // 0 2 2 4 4 ...
    int m = n / 2;  // n = m * 2 + 1
    if (a[0] != 0) { printf("0\n"); exit(EXIT_SUCCESS); }
    for (int j = 0; j < m; ++j) {
      if (a[2 * j + 1] != 2 * (j + 1) || a[2 * j + 2] != 2 * (j + 1)) {
        printf("0\n"); exit(EXIT_SUCCESS);
      }
    }
    printf("%lld\n", pow2mod(m));
  } else {
    // 1 1 3 3 ...
    int m = n / 2;
    for (int j = 0; j < m; ++j) {
      if (a[2 * j] != 2 * j + 1 || a[2 * j + 1] != 2 * j + 1) {
        printf("0\n");  exit(EXIT_SUCCESS);
      }
    }
    printf("%lld\n", pow2mod(m));
  }
  /* */

  return EXIT_SUCCESS;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long R, C, K;
    cin >> R >> C >> K;
    vector<vector<vector<long>>> score(R + 1, vector<vector<long>>(C + 1, vector<long>(4, 0)));
    vector<vector<long>> board(R + 1, vector<long>(C + 1, 0));
    for (long i = 0; i < K; i++)
    {
        long _i, _j, v;
        cin >> _i >> _j >> v;
        board[_i][_j] = v;
    }

    for (long i = 1; i <= R; i++)
    {
        for (long j = 1; j <= C; j++)
        {
            long descent = *max_element(score[i - 1][j].begin(), score[i - 1][j].end());
            score[i][j][3] = max(score[i][j - 1][3], score[i][j - 1][2] + board[i][j]);
            score[i][j][2] = max(score[i][j - 1][2], score[i][j - 1][1] + board[i][j]);
            score[i][j][1] = max(descent + board[i][j], score[i][j - 1][1]);
            score[i][j][1] = max(score[i][j][1], board[i][j]);
            score[i][j][0] = max(descent, score[i][j - 1][0]);
        }
    }
    cout << *max_element(score[R][C].begin(), score[R][C].end()); 
    return 0;
}


Measured memory_bytes: 706964
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n,w;
    cin>>n>>w;
    vvi dp(n+1,vi(w+1));//求めるのはdp[0][w]
    vi wei(n+1),val(n+1);
    rep(i,n) cin>>wei[i]>>val[i];
    rep(i,w+1) dp[n][i]=0;
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<=w;j++){
            if(j-wei[i]<0){
                dp[i][j]=dp[i+1][j];//重量オーバーしたらそのまま
            }
            else{
                dp[i][j]=max(dp[i+1][j],dp[i+1][j-wei[i]]+val[i]);
            }
        }
    }
    out(dp[0][w]);

}

Measured memory_bytes: 80256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		var s = rs();
		Console.WriteLine((char)(s[0] + 1));
	}

	public Sol(){
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

namespace TenkaPBC2019C2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());//石の数Ｎ個
            string S = Console.ReadLine();//文字列　．白　＃黒

            int black = 0;
            int white = S.Replace("#", "").Length;//.の数を数えてみる
            int ans = white;
                for (int i = 0; i < N; i++)
                {
                    int counter = 0;
                    if (S.Substring(i, 1) == "#")
                    {
                        black++;
                    }
                    else
                    {
                        white--;
                    }
                    counter=black+white;
                    if (counter < ans)
                    {
                        ans = counter;
                    }
                }
                Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 16604
from fractions import gcd
from functools import reduce

n,x_ = map(int, input().split())
x = list(map(int, input().split()))
x.append(x_)
x.sort()
sa = [x[i+1]-x[i] for i in range(n)]
d = reduce(lambda a,b:gcd(a,b),sa)
print(d)

Measured memory_bytes: 16432
#include<cstdio>
#include<cstring>
#include<algorithm>
int n,P,a;
long long ans,f[5010];
template<class T>
inline void read(T&a){
	char c=getchar();
	for(a=0;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
}
int main(){
	read(n);read(P);f[0]=1;
	for(int i=1;i<=n;i++){
		read(a);
		for(int j=5000;j>=a;j--)f[j]+=f[j-a];
	}
	for(int i=0;i<=5000;i++)
		if(((i&1)^P)==0)ans+=f[i];
	printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP((i), 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
int L = 55560;
bool a[55560];
int main() {
    memset(a, true, L);
    REP(i, 2, sqrt(L)) {
        if(a[i]) {
            for(int j=0; i*(j+2)<L; j++) {
                a[i*(j+2)] = false; 
            }
        }
    }
    int N; cin >> N;
    int ans = 0;
    for(int i=0, j=2; i<N; j++) {
        if(j%5 == 1 && a[j]) {cout << j << " "; i++;}
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
	string s;
    cin >> s;
    if(s=="SUN"){
      cout << 7 << endl;
    }else if(s=="MON"){
      cout << 6 << endl;
    }else if(s=="TUE"){
      cout << 5 << endl;
    }else if(s=="WED"){
      cout << 4 << endl;
    }else if(s=="THU"){
      cout << 3 << endl;
    }else if(s=="FRI"){
      cout << 2 << endl;
    }else{
      cout << 1 << endl;
    }
    return 0;
  } 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
 
int n,a,b,i,s[100];
int main()
{ 
cin >> n;
for(i=0;i<n;i++){
cin >> s[i];
}
sort(s,s+n, greater<int>());
for(i=0;i<n;i++){
if(i%2==0){a=a+s[i];
}else{b=b+s[i];
}
}
printf("%d",a-b);
}

Measured memory_bytes: 256
//AcFreak

#include<bits/stdc++.h>
#define lint long long int 
#define mp make_pair
#define pb push_back
#define f first
#define INF (lint )(1e9)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s second
#define endl '\n'
#define pii pair<int,int >
using namespace std;

struct pointer{
	int f,s;
};

bool sorter(pointer a,pointer b)
{
	if(a.f == b.f)
		return a.s<b.s;

	return a.f<b.f;
}
int main()
{__
      
	int n,m,i;
	cin>>n>>m;

	int cc=0;

	vector<pointer>arr(m);
	for(i=0;i<m;i++)
		cin>>arr[i].f >> arr[i].s;

	sort(arr.begin(), arr.end(),sorter);

	int miny=INF;
	for(i=0;i<m;i++)
	{
		miny=min(arr[i].s,miny);
		if(arr[i].f >= miny){
			cc++;
			miny=arr[i].s;	
		}
	}


	cout<<cc+1<<endl;
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++) cin>>p[i];
  int ans=0;
  int posi=0;
  while(posi<n){
    if(p[posi]==posi+1){
      ans++;
      posi+=2;
    }
    else posi++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 768
# import sys
# input = sys.stdin.readline
import itertools
import collections


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    h, w = input_list()
    grids = [list(input()) for i in range(h)]
    dist = [[-1]*w for _ in range(h)]

    black_cells = collections.deque()
    for hi in range(h):
        for wi in range(w):
            if grids[hi][wi] == '#':
                black_cells.append((hi, wi))
                dist[hi][wi] = 0

    print(bfs(h, w, black_cells, dist))


def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 154588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        public static void Main()
        {
            while (true)
            { int sss = 0;
                string a = Console.ReadLine();
                if (a == null) break;
                int b = int.Parse(a);
                for(int c = 0; c < 10; c++)
                {
                    for(int d = 0; d < 10; d++)
                    {
                        for(int e = 0; e < 10; e++)
                        {
                            if (b - e - d - c > -1 && b - e - d - c < 10) sss++;
                        }
                    }
                }
                Console.WriteLine(sss);
            }
        }
    }
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, M;
ll mk[100],i,j;
int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,N){
        ll kk;
        scanf("%lld", &kk);
        fornum(j,0,kk){
            ll aa;
            scanf("%lld",&aa);
            mk[aa]++;
        }
    }
    ll ans = 0;
    fornum(i,0,M){
        if(mk[i+1]==N){
            ans++;
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let p: i64 = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect();

    let odd = a.iter().filter(|&x| x % 2 == 1).count();
    let even = n - odd;

    let ans = if even == n {
        if p == 1 {
            0
        } else {
            1i64 << n
        }
    } else {
        1i64 << (n - 1)
    };

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fastAF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mapll map<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define deb(x) cout<<x
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
void swap(auto*,auto*);
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastAF
    ll n; cin>>n; ll a[n]; for(ll i=0;i<n;i++) cin>>a[i];
    ll sum=0;
    for(ll i=0;i<n-1;i++)
    {
    	sum+=max((ll)0,a[i]-a[i+1]);
    	a[i+1]=max(a[i+1],a[i]);
    }
    cout<<sum<<endl;
}
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;
}

Measured memory_bytes: 5196
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

#define ll long long
#define REP(i,n) for(int i=0;i<n;++i)
using namespace std;

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


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1<<29;
/****** define constant end ********/

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) { return a.first < b.first; }

void sort2vectors(
    vector<ll> &av,
    vector<ll> &bv) { // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
  ll n = av.size();
  vector<pair_t> p(n);
  vector<ll> av2(n), bv2(n);
  for (ll i = 0; i < n; i++)
    p[i] = make_pair(av[i], bv[i]);
  sort(p.begin(), p.end(), comp);
  for (ll i = 0; i < n; i++) {
    av2[i] = p[i].first;
    bv2[i] = p[i].second;
  }
  av = av2;
  bv = bv2;
}
/****** define variable start ******/
ll n, m;
vl s, c;

/******* define variable end *******/
ll solve() {
	cin >> n >> m;
	s.resize(m);
	c.resize(m);
	bool first_keta = false;
	REP(i, m){
		cin >> s[i] >> c[i];
		if(s[i] == 1){
			first_keta = true;
		}
		if(s[i] > n){
			cout << -1 << endl;
			return 0;
		}
	}
	sort2vectors(s,c);
	REP(i, m-1){
		if(s[i] == s[i+1] && c[i] != c[i+1]){
			cout << -1 << endl;
			return 0;
		}
    }
    vl kazu(n);
	REP(i, n){
		kazu[i] = -1;
	}
    REP(j, m) { kazu[s[j]-1] = c[j]; }

    if(first_keta && kazu[0] != 0){
		REP(i, n){
			if(kazu[i] == -1){
				cout << 0;
            } else {
                cout << kazu[i];
            }
        }
		cout << endl;
		return 0;
	}
	if(!first_keta && n == 1){
		cout << 0 << endl;
		return 0;
	}
	if(!first_keta){
		cout << 1;
        for (ll i = 1; i < n; i++) {
            if (kazu[i] == -1) {
				cout << 0;
            }else{
				cout << kazu[i];
			}
        }
		cout << endl;
		return 0;
    }
	if(kazu[0] == 0 && n != 1){
		cout << -1 << endl;
	}else{
		cout << 0 << endl;
	}

	return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    
    return (int)end_solve;
}


Measured memory_bytes: 256
#include<stdio.h>

void maxheap(int);
void swap(int,int);
int num;
int array[2000001];

int main(){

   int i;
  scanf("%d",&num);
  for(i = 1;i <= num;i++){
    scanf("%d",&array[i]);
  }
  for(i = num / 2;i >= 1;i--){
    maxheap(i);
  }
  for(i = 1;i <= num;i++){
    printf(" %d",array[i]);
  }
  printf("\n");
  return 0;
}

void maxheap(int i){
  int left = 0;
  int right = 0;
  int largest = 0;
  int change;

  left = 2 * i;
  right = 2 * i + 1;

  if(left <= num && array[left] > array[i]){
    largest = left;
  }
  else{
    largest = i;
  }
  if(right <= num && array[right] > array[largest]){
    largest = right;
  }
  if(largest != i){
    change=array[i];
    array[i]=array[largest];
    array[largest]=change;
    maxheap(largest);
  }
}



Measured memory_bytes: 3676
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;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 all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,k;
	cin >>n>>k;
	set<int>ans;
	int ansv=0;
	int d;
	int bef;
//	vector<vector<int>>a(k);
	rep(i,k){
		cin>>d;
		rep(i,d){
			cin>>bef;
			//a[i].push_back(bef);
			ans.insert(bef);
		}
	}
	for(int i=1;i<=n;i++){
	
			if (ans.lower_bound(i) ==ans.end() or *ans.lower_bound(i) != i)
			{
				ansv++;
			}
	}
	cout<<ansv<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,mx= 0,mn = 1000000001;
    cin >> n;
    int ara[n];
    for(int i =0; i < n;i++)
    {
        cin >> ara[i];
    }
    for(int i =0; i < n;i++)
    {
        if(ara[i] > mx) mx = ara[i];
        if(ara[i] < mn) mn = ara[i];
    }
    cout << mx-mn << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct { template <typename T> operator T() { T x; cin >> x; return x; } } IN;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int a,b;
    cin>>a>>b;
    stringstream ss;
    ss<<"\\d{"<<a<<"}-\\d{"<<b<<"}";
    regex re(ss.str());
    string s;
    cin>>s;
    cout<<(regex_match(s,re)?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from heapq import heappush, heappop

n, m = li()
a = list(li())

heap = []
for ai in a:
    heappush(heap, -ai)

for _ in range(m):
    cur = -heappop(heap)
    heappush(heap, -(cur // 2))

ans = 0
for hi in heap:
    ans += -hi
print(ans)

Measured memory_bytes: 60952
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int getsn (int n) {
  int sn = 0;
  while (n > 0) {
    sn += n % 10;
    n /= 10;
  }
  return sn;
}

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

  int sn = getsn(n);
  cout << (n % sn == 0 ? "Yes" : "No") << endl;



  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(void) {
  char S[200001];
  cin >> S;
  int Ans = 1;
  int mode = 0;
  for (int i = 1; S[i] != '\0'; i++) {
    // printf("S[%d]=%c mode=%d Ans=%d\n", i, S[i], mode, Ans);
    if (mode == 0) {
      if (S[i - 1] != S[i]) {
        Ans++;
      } else {
        mode = 1;
      }
    } else if (mode == 1) {
      Ans++;
      mode = 2;
    } else if (mode == 2) {
      Ans++;
      mode = 0;
    }
  }
  cout << Ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


void dfs(int v){
}

signed main() {
  int N;
  cin >> N;

  vector<int> color(N-1);
  vector<int> used(N);
  vector<vector<pair<int, int>>> graph(N);
  int a, b;
  REP(i, N-1){
    cin >> a >> b;
    a--; b--;
    graph[a].push_back(make_pair(b, i));
    graph[b].push_back(make_pair(a, i));
  }

  REP(i, N) sort(ALL(graph[i]));
  int ans = 0;
  REP(i, N){
    ans = max(ans, (int)graph[i].size());
  }

  REP(i, N){
    int cnt = 0;
    vector<int> v(ans, 0);

    REP(j, graph[i].size()){
      int k = graph[i][j].second; // 番号
      if(used[k]){// 塗られている
        v[color[k]] = 1;
        continue;
      }
      while(v[cnt] != 0){
        cnt++;
      }
      v[cnt] = 1;
      color[k] = cnt;
      used[k] = 1;
    }
  }


  cout << ans << endl;
  REP(i, N-1){
    cout << color[i]+1 << endl;
  }

  return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

#define OUT(a) { cout << int(a) << "\n"; exit(0); }

auto prime_factor = [](ll x){map<ll, int> xfact;for(int i=2; (ll)i*i<=x; i++) {while(x % i == 0) {xfact[i]++;x /= i;}}if(x > 1) xfact[x]++;return std::move(xfact);};

int main() {
  int n; cin >> n;
  int64_t sum = 0;
  rep(i, n) {
    int a; cin >> a;
    auto m = prime_factor(a);
    sum += m[2];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import sys
 
def bubble_sort(C, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if C[j][1] < C[j - 1][1]:
                C[j], C[j - 1] = C[j - 1], C[j]
                 
    return C
def selection_sort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
 
        C[i], C[minj] = C[minj], C[i]
     
    return C
fin = sys.stdin
 
N = int(fin.readline())
A = fin.readline().split()
B = A[:]
 
A = bubble_sort(A, N)
B = selection_sort(B, N)
 
print(" ".join(A))
print("Stable")
 
print(" ".join(B))
if A == B:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> a)
{

    RSORT(a);
    ll ans = 0;
    for (int i = 1; i <= N; i++)
    {
        ans += a[i * 2 - 1];
    }
    cout << ans << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(3 * N);
    for (int i = 0; i < 3 * N; i++)
    {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

const int MAX = 100000;
int main() {
	int n;
	static int a[MAX];
	cin >> n;
	for (int i = 0;i < n;i ++) cin >> a[i];
	int max = 0;
	for (int i = 0;i < n;i ++) if (max < a[i]) max = a[i];
	int r = 0;
	for (int i = 0;i < n;i ++) {
		if (max <= a[i]) continue;
		if (abs(max - r * 2) > abs(max - a[i] * 2)) r = a[i];
	}
	cout << max << " " << r;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

あるa_jを考えます
この時、a_iはなるべく大きい値にしたいはずです(その方が必ず値が大きくなります)
よって、a_iはmax(a)であるので、a_jのみ探せば良いです
後はa_jに関しては、a_i/2に最も近い値を探せば良いです
*/

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

typedef long long ll;

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

    int N;

    cin >> N;

    vector<vector<pair<int, int> > > u(N);
    vector<bool> c(N);
    vector<int> ans(N);

    for(int i = 0; i < N - 1; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        u[x].push_back(make_pair(y, z));
        u[y].push_back(make_pair(x, z));
    }

    stack<pair<int, int> > s;

    s.push(make_pair(0, 0));
    ans[0] = 0;

    while(!s.empty()) {
        pair<int, int> x = s.top();
        s.pop();
        for(int i = 0; i < u[x.first].size(); i++) {
            int v = x.second;
            int t = u[x.first][i].first;
            if(!c[t]) {
                c[t] = true;
                if(u[x.first][i].second % 2 == 1) {
                    v++;
                    v %= 2;
                }
                ans[t] = v;
                s.push(make_pair(t, v));
            }
        }
    }

    for(int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}

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

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

  map<int,int> m;
  rep(i,0,N-1) {
    int n;
    cin >> n;
    if (3200 <= n) n = 3200;
    m[n/400]++;
  }

  int a1 = 0, a2 = 0;
  rep(i,0,7) if (m.count(i) != 0) a1++;
  a2 = a1 + m[8];
  if (a1 == 0) a1 = 1;

  cout << a1 << ' ' << a2 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A=sc.nextInt();
        int B=sc.nextInt();
        int sum=0;
        int temp=0;
        int tempSum=0;
        for(int i=1;i<=N;i++){
            temp=i;
            tempSum=0;
            while(temp/10 != 0){
                tempSum+=temp%10;
                temp/=10;
            }
            tempSum+=temp;
            if(tempSum>=A && tempSum<=B){
                sum+=i;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21972
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    int64_t n;
    cin >> n;
    cout << n*n*n << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

#define SIZE (1 << 16)

int main() {
    while (1) {
        int n, m;
        
        cin >> n >> m;
        if (n == 0) {
            break;
        }

        int light[30], button[30], dp[31][SIZE] = { 0 };
        int b;
        for (int i = 0; i < n; i++) {
            light[i] = 0;
            for (int j = 15; j >= 0; j--) {
                cin >> b;
                light[i] += (b << j);
            }
        }
        for (int i = 0; i < m; i++) {
            button[i] = 0;
            for (int j = 15; j >= 0; j--) {
                cin >> b;
                button[i] += (b << j);
            }
        }
        dp[0][light[0]] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < SIZE; j++) {
                if (dp[i][j] > 0) {
                    for (int k = 0; k < m; k++) {
                        int point = 0, field = (j | light[i]);
                        int temp = (field & button[k]);
                        field -= temp;
                        while (temp > 0) {
                            point += (temp & 1);
                            temp >>= 1;
                        }
                        dp[i + 1][field] = max(dp[i + 1][field], dp[i][j] + point);
                    }
                }
            }
        }
        
        int ans = 0;
        for (int i = 0; i < SIZE; i++) {
            ans = max(ans, dp[n][i]);
        }
        cout << ans - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 9104