akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>

#define NIL -1

using namespace std;

typedef struct {int parent,left,right;} Node;

Node T[100000];

void depth(int D[],int id,int d){
    D[id] = d;
    if (T[id].right != NIL) depth(D,T[id].right,d);
    if (T[id].left != NIL) depth(D,T[id].left,d+1);
}

int decide_type(int id){
    if (T[id].left != NIL && T[id].parent != NIL) {
        return 1;
    }else if (T[id].parent != NIL){
        return 2;
    }else{
        return 0;
    }
}

void Child_id(int id){
    if (T[id].left == NIL) {
        cout << "[]" << endl;
    }else{
        id = T[id].left;
        cout << "[" << id;
        while (T[id].right != NIL) {
            cout << ", " << T[id].right;
            id = T[id].right;
        }
        cout << "]" << endl;
    }
}

int main(){
    int root=0;
    int D[100000];
    int N;
    cin >> N;
    for (int  i = 0; i < N; i++) {
        T[i].left = NIL;
        T[i].right = NIL;
        T[i].parent = NIL;
    }
    for (int i = 0; i < N; i++) {
        int id,count;
        cin >> id >> count;
        int child,beforchild = -1;
        
        for (int c = 0; c < count; c++) {
            cin >> child;
            T[child].parent = id;
            if (c == 0) T[id].left = child;
            if (beforchild != -1) T[beforchild].right = child;
            beforchild = child;
        }
    }
    while (T[root].parent != NIL) {
        root = T[root].parent;
    }
    depth(D,root,0);
    char type[3][32] = {"root, ",
        "internal node, ",
        "leaf, "};
    
    
    for(int i = 0; i < N; i++){
        printf("node %d: parent = %d, depth = %d, %s",i,T[i].parent,D[i],type[decide_type(i)]);
        Child_id(i);
    }
    
    return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n,a[200010];
int l,r,mid;

bool check(int lim){
	if(lim==1)return is_sorted(a,a+n);
	map<int,int>mp;
	for(int i=1;i<n;i++){
		if(a[i-1]<a[i])continue;
		mp.erase(mp.upper_bound(a[i]),mp.end());
		int now=a[i];
		mp[now]++;
		while(now){
			if(mp[now]==lim){
				mp.erase(now);
				now--;
				mp[now]++;
			}
			else break;
		}
		if(now==0)return false;
	}
	return true;
}

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

void solve(){
	r=n;
	while(r-l>1){
		mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid;
	}
	cout<<r<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"
#include "functional"
#include <math.h>


using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)

//C
int main(void) {
	double n, k;
	cin >> n >> k;
	long num =  floor(n / k);
	long long n1 = 0, n2 = 0, n3 = 0;
	if ((int)k % 2 == 1) {
		if (num > 0) {
			n1 = num;
		}
		if (num > 1) {
			n2 = num * (num - 1) * 3;
		}
		if (num > 2) {
			n3 = num * (num - 1) * (num - 2);
		}
		cout << n1 + n2 + n3 << endl;
	}
	else {
		long amari = n - num * k;
		long long num2 = amari >= k / 2 ? num + 1 : num; // k/2の倍数の個数
		if (num > 0) {
			n1 = floor(n / k);
		}
		if (num > 1) {
			n2 = num * (num - 1) * 3;
		}
		if (num > 2) {
			n3 = num * (num - 1) * (num - 2);
		}
		if (num2 > 0) {
			n1 += num2;
		}
		if (num2 > 1) {
			n2 += num2 * (num2 - 1) * 3;
		}
		if (num2 > 2) {
			n3 += num2 * (num2 - 1) * (num2 - 2);
		}
		cout << n1 + n2 + n3 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct iofix
{
   ios_base::Init i;
   iofix() {
      cin.sync_with_stdio(0);
      cin.tie(0);
      cout.sync_with_stdio(0);
      cout.tie(0);
      cout.precision(10);
      cout << fixed;
   }
} iofix;

void solve(){
      int32_t N; cin >> N;
      map<string, int64_t>mp;
      for(int i=0;i < N;i++){
           string s; cin >> s;
           mp[s] += 1;
      }
      cout << "AC x  "  << mp["AC"]  << "\n";
      cout << "WA x  "  << mp["WA"]  << "\n";
      cout << "TLE x  " << mp["TLE"] << "\n";
      cout << "RE x  "  << mp["RE"]  << "\n";
}

int main(){
// #ifndef Judge
//     freopen("in.txt","r",stdin);
//     freopen("out.txt","w",stdout);
// #endif
   	solve();

#ifndef Time
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
}

Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+1;
std::vector<int> edge[N];
int mi = 1e9;
pair<int,int> nd;
pair<int,int> cend_1;
int par[N];

long long Fabs(long long a)
{
  if (a<0)a*=-1;
  return a;
}
int main(){
  std::vector<long long> a, s;
  int n, i;
  cin >>n;
  for(i=0;i<n;i++)
  {
    long long x, y;
    cin >> x>>y;
    a.push_back(x+y);
    s.push_back(x-y);
  }
  sort(a.begin(), a.end());
  sort(s.begin(), s.end());
  long long ans = *(--a.end())-a[0];
  ans = max(ans, *(--s.end())-s[0]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8976
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Train Ticket

            //4つの数字を取得
            var numbers = GetSourceNumbers().ToList();

            string formula = GetFormulaToBeSeven(numbers);
            Console.WriteLine(formula);
        }

        static IEnumerable<int> GetSourceNumbers()
        {
            string line = Console.ReadLine().TrimEnd();

            for(int i = 0; i < 4; i++)
            {
                string s = line.Substring(i, 1);
                yield return int.Parse(s);
            }
        }

        static string GetFormulaToBeSeven(List<int> numbers)
        {
            var opVariations = GetOpVariations().ToList();
            
            foreach(var op in opVariations)
            {
                int sum = numbers[0];
                string formula = numbers[0].ToString();

                for(int i = 1; i < 4; i++)
                {
                    if (op[i] == '0')
                    {
                        sum += numbers[i];
                        formula += "+" + numbers[i];
                    }
                    else
                    {
                        sum -= numbers[i];
                        formula += "-" + numbers[i];
                    }
                }

                if (sum == 7)
                {
                    return formula += "=7";
                }
            }

            return null;
        }

        static IEnumerable<string> GetOpVariations()
        {
            for(int i = 0; i < 8; i++)
            {
                decimal num = ConvertNumberingFromDecimal(i, 2);

                //後続の処理でindexを揃えるために、先頭にゼロを追加
                yield return num.ToString("000#");
            }
        }

        static decimal ConvertNumberingFromDecimal(decimal sourceNumber, int bit)
        {
            //[summary]10進法の数字をn進法に変換
            //変換方法については、以下リンクの最下部を参照
            //http://manabi.matiralab.com/binary/

            var list = new List<decimal>();
            decimal num = sourceNumber;

            //元の数字が"n"で割れなくなるまで繰り返し
            while (num >= bit)
            {
                decimal mod = num % bit;
                list.Add(mod);

                num = Math.Floor(num / bit);
            }

            list.Add(num);

            //記憶した数字の順番を入れ替える
            list.Reverse();

            //Listの値を結合して、数字に変換
            string s = string.Join("", list);
            return decimal.Parse(s);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main(){
    string s,t;
    cin >> s >> t;
    int len = t.size();
    int cnt = 0;
    REP(i,s.size()-len+1){
        int tmp = 0;
        REP(j,len){
            if (s[i+j] == t[j]) tmp++;
        }
        cnt = max(tmp,cnt);
    }
    cout << len - cnt << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0)); 
const double EPS = 1e-9;
const double mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

struct edge { int to; ll cost; };

int N, Q, K;
vector<edge> g[100010];
ll d[100010];


void dijk(int s){
    priority_queue<int> pq;
    pq.push(s);
    d[s] = 0;

    while(!pq.empty()){
        int u = pq.top(); pq.pop();
        for(edge v : g[u]){
            if(d[v.to] > d[u] + v.cost){
                d[v.to] = d[u] + v.cost;
                pq.push(v.to);
            }
        }
    }
}


int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> N;
    rep(i, N-1){
        int a, b; ll c;
        cin >> a >> b >> c;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }

    cin >> Q >> K;
    fill(d, d+N+1, INFL);
    dijk(K);

    rep(i, Q){
        int x, y;
        cin >> x >> y;
        cout << d[x] + d[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 10096
a = []

while True:
    H, W = map(int, input().split())
    if H != 0 or W != 0:
        a.append([H, W])
    else:
        break

for i in range(0, len(a)):
    print('#' * a[i][1])
    for j in range(0, a[i][0]-2):
        print('#' + '.' * (a[i][1]-2) + '#')
    print('#' * a[i][1])
    print('')




Measured memory_bytes: 5624
s = input()
n = len(s)
if s == s[::-1] and s[:(n - 1) // 2] == s[:(n - 1) // 2][::-1] and s[(n + 1) // 2:] == s[(n + 1) // 2:][::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int N,T;
long ans,t,now;
main()
{
	cin>>N>>T;
	for(int i=0;i<N;i++)
	{
		cin>>t;
		if(now<t)
		{
			now=t+T;
			ans+=T;
		}
		else
		{
			ans+=t+T-now;
			now=t+T;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(int argc, char **argv) {
    long X;
    std::cin >> X; // 0 y= X <<= 10^9

    // Greedy should work.
    auto c500 = X / 500;
    auto remainder = X % 500;
    auto c5 = remainder / 5;
    auto happiness = c500 * 1000 + c5 * 5;

    std::cout << happiness << std::endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    string s;
    cin >> s;
    bool c = false;
    rep(i,sz(s)) {
        if(s[i] == 'C') c = true;
        if(c && s[i] == 'F') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}   

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#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 SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#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 INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int N;
    int result = 1;
    cin >> N;
    VI H(N);
    REP(i,N){cin >> H[i];}
    int high=H[0];
    REP(i,N-1){
        if(high<=H[i+1]){
            result++;
            high=H[i+1];
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
N=int(input())
S=[0 for i in range(N)]
for i in range(N):
  S[i]=str(input())
c = collections.Counter(S)
p=max(c.values())
T=[]
for i in c:
  if c[i]==p:
    T.append(i)
T=sorted(T)
for i in range(len(T)):
  print(T[i])

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

int main(){
  int n, m, total=0, a;
  cin >> n >> m;
  rep(i,m){
    cin >> a;
    total += a;
  }
  if(n >= total) cout << n - total << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#define MAX_W 50
#define MAX_H 50
using namespace std;

int w, h;
int t[MAX_H][MAX_W];

void PRINT() {
  for(int i = 0; i < h; ++i) {
    for(int j = 0; j < w; ++j) {
      cout << t[i][j] << ' ';
    }
    cout << endl;
  }
  cout << endl;
}

// 深さ優先探索
// 現在位置(y, x)
void dfs(int y, int x) {
  t[y][x] = 8;

  for(int dx = -1; dx <= 1; dx++) {
    for(int dy = -1; dy <= 1; dy++) {
      // 現在位置を(nx, ny)に更新
      int nx = x + dx;
      int ny = y + dy;

      // (nx, ny)は部屋の中か？ & t[nx][ny]は陸か？ を判定
      if(0 <= nx && nx < w && 0 <= ny && ny < h && t[ny][nx] == 1) {
        dfs(ny, nx);
        //PRINT();
      }
    }
  }
  return;
}

void solve() {
  int cnt = 0;
  for(int y = 0; y < h; ++y) {
    for(int x = 0; x < w; ++x) {

      if(t[y][x] == 1) {
        dfs(y, x);
        cnt++;
      }
      
    }
  }
  cout << cnt << endl;
}

int main() {
  while(cin >> w >> h && w && h) {

    for(int i = 0; i < h; ++i) {
      for(int j = 0; j < w; ++j) {
        cin >> t[i][j];
      }
    }
    solve();
  }
  return 0;
}



Measured memory_bytes: 3232
#include<iostream>
using namespace std;
int n, m;
int a[101];
bool search(int v);
int main()
{	
	while (true){
		cin >> m >> n;
		if (m == 0 && n == 0)break;
		for (int i = 0; i < n; i++){
			cin >> a[i];
		}
		int l, r;
		l = 0; r = 1 << 24;
		for (int i = 0; i < 100; i++){
			int mi = (l + r) / 2;
			if (search(mi))r = mi;
			else l = mi;
		}
		cout << r << endl;
	}
}
bool search(int v){
	int n2=0, m2=0,b=0;
	while (n2 < n&&m2 < m){
		if (b + a[n2] <= v){
			b += a[n2];
			n2++;
		}
		else{
			b = 0;
			m2++;
		}
	}
	if (n2 == n&&m2 < m)return true;
	return false;
}

Measured memory_bytes: 1156
let n, h, w = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let ab_s = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let _ = Array.fold_left (fun c (a, b) -> if a >= h && b >= w then c + 1 else c) 0 ab_s |> Printf.printf "%d\n"

Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;


	boolean check(String s, char c) {
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i) != c) {
				return false;
			}
		}
		return true;
	}

	int f(String s, char c) {
		if(check(s,c)) {
			return 0;
		}

		StringBuffer sb = new StringBuffer();

		for(int i=0;i<s.length()-1;i++) {
			if(s.charAt(i) == c || s.charAt(i+1) == c) {
				sb.append(c);
			}else {
				sb.append(s.charAt(i));
			}
		}

		return f(sb.toString(), c) + 1;

	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String s = sc.next();

		sc.close();

		int ans = Integer.MAX_VALUE;

		for(char c='a';c<='z';c++) {
			ans = Math.min(ans, f(s,c));
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 23508
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef unsigned long long ul;

ul power(ul m, ul n, ul M){
	ul tmp = 1;

	if(n > 0){
		tmp = power(m, n/2, M);
		if(n%2 == 0)
			tmp = (tmp * tmp) %M;
		else
			tmp = (((tmp * tmp) %M) *m) %M;
	}
	return tmp;
}

int main(){

	int m, n;
	cin>>m>>n;
	
	cout<<power(m, n, 1000000007)<<endl;

	return 0;
}

Measured memory_bytes: 1156
# AGC039A - Connection and Disconnection
from itertools import groupby


def main():
    S = input().rstrip()
    K = int(input())
    cnt = [len(tuple(s)) for _, s in groupby(S)]  # count of continuous characters
    if S[0] == S[-1] and K > 1:
        if len(cnt) == 1:  # one character
            ans = cnt[0] * K // 2
        else:  # first (= last) character in S + characters inside S
            ans = cnt[0] // 2 + cnt[-1] // 2 + (cnt[0] + cnt[-1]) // 2 * (K - 1)
            ans += sum(i // 2 for i in cnt[1:-1]) * K
    else:
        ans = sum(i // 2 for i in cnt) * K
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    int N;
    cin >> N;
    if(N < 10) cout << N << endl;
    else if(N < 100) cout << 9 << endl;
    else if(N < 1000) cout << N - 90 << endl;
    else if(N < 10000) cout << 909 << endl;
    else if(N < 100000) cout << N - 9090 << endl;
    else cout << 90909 << endl;
}

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

#define INF 100000

using namespace std;

int main() {
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  vector<int> a(N), b(N), c(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<vector<int> > > dp(2);
  for (int i = 0; i < 2; i++) {
    dp[i].resize(N * 10 + 1);
    for (int j = 0; j <= N * 10; j++) {
      dp[i][j].resize(N * 10 + 1, INF);
    }
  }
  dp[0][0][0] = 0;
  for (int i = 1; i <= N; i++) {
    int ic = i % 2, ip = (i + 1) % 2;
    for (int j = 0; j <= N * 10; j++) {
      for (int k = 0; k <= N * 10; k++) {
        if (j >= a[i-1] && k >= b[i-1]) {
          dp[ic][j][k] = min(dp[ip][j][k], dp[ip][j-a[i-1]][k-b[i-1]] + c[i-1]);
        } else {
          dp[ic][j][k] = dp[ip][j][k];
        }
      }
    }
  }

  int n = 1, ans = INF;
  while(Ma * n <= N * 10 && Mb * n <= N * 10) {
    ans = min(ans, dp[N % 2][Ma * n][Mb * n]);
    n++;
  }
  if (ans == INF) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }


  return 0;
}


Measured memory_bytes: 1536
IDENTIFICATION DIVISION.
PROGRAM-ID. A-Strings.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP    PIC X(201).
01 S      PIC X(100).
01 T      PIC X(100).
01 S-LEN  PIC 9(3).
01 T-LEN  PIC 9(3).
 
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED ALL ' '
      INTO S   COUNT S-LEN
           T   COUNT T-LEN.
      
  DISPLAY  T(1:T-LEN) S(1:S-LEN).

  STOP RUN.


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define pb(x)                    push_back(x)
#define all(a)                   a.begin(), a.end()
#define dbg(a)                   cout<< #a <<" --> "<<(a)<<endl;
#define IO                       ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define read                     freopen("tst.txt","r",stdin)
#define write                    freopen("out.txt","w",stdout)
typedef long long ll;
using namespace std;






main(){
//read;
IO;

double t;
int x;
cin>>x;
int n = x/2 + x%2;
t = x;
t = (double)n/t;
printf("%.10f",t);



return 0;
}


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

int main() {
  vector<int> a(3);
  for(int i = 0; i < 3; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  cout << a.at(0) + a.at(1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#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 SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int N;
	cin >> N;
	vector<pair<int,int> > red;
	vector<pair<int, int> > blue;

	bool R[100];
	REP(i, 100) {
		R[i] = true;
	}
	REP(i, N) {
		int x, y;
		cin >> x >> y;
		red.push_back(make_pair(x, y));
	}
	REP(i, N) {
		int x, y;
		cin >> x >> y;
		blue.push_back(make_pair(x, y));
	}
	SORT(blue);
	REP(i, N) {
		//cout << blue[i].first << " " << blue[i].second << endl;
	}
	int ans = 0;
	REP(i, N) {
		int a=-1,b=-1;
		REP(j, N) {
			
			if (blue[i].first > red[j].first) {
				if (blue[i].second > red[j].second) {
					if (red[j].second > b && R[j]) {
						a = j;
						b = red[j].second;
						//cout << b << endl;
					}
				}
			}
		}
		//cout << a << endl;
		if (a != -1) {
			R[a] = false;
			ans++;
		}
	}
	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[100000],b[100000],d,m,n,o;
  cin>>m;
  for(i=0;i<m;i++){
    cin>>n>>o;
    for(j=0;j<n;j++){
      cin>>a[j];
      if(j)
	b[j-1]=a[j]-a[j-1];
    }
    sort(b,b+n-1);
    if(o<n){
      d=a[n-1]-a[0];
      for(j=0;j<o-1;j++)
	d-=b[n-j-2];
    }else
      d=0;
    cout<<d<<endl;
  }
  return 0;
}

Measured memory_bytes: 1648
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<int, pi> node;
#define oset tree<pi, null_type,greater<pi>, rb_tree_tag,tree_order_statistics_node_update>

#define N 100005
vector<int> adj[N];
vector<lli> we[N];
int ans[N];
bool vis[N];

void dfs(int u)
{
    vis[u] = 1;
    for(int i=0; i<adj[u].size(); i++){
        int v = adj[u][i];
        lli w = we[u][i];
        if(vis[v] == 0){
            if(w%2){
                ans[v] = !ans[u];
            }
            else{
                ans[v] = ans[u];
            }
            dfs(v);
        }
    }
}

int main()
{
    int n;
    cin >> n;
    for(int i=1; i<n; i++){
        int u, v;
        lli w;
        cin >> u >> v >> w;
        adj[u].push_back(v);
        adj[v].push_back(u);
        we[u].push_back(w);
        we[v].push_back(w);
    }
    dfs(1);
    for(int i=1; i<=n; i++){
        cout << ans[i] << "\n";
    }

    return 0;
}


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

using namespace std;

int main(){
	string s;
	vector<char> fr,b;
	cin>>s;
	int q,rev=0;
	cin>>q;
	while(q--){
		int t;
		cin>>t;
		if(t==1){
			rev++;
		}
		else{
			char x;
			int f;
			cin>>f>>x;
			if(f==1&&rev%2==0)fr.push_back(x);
			else if(f==1&&rev%2==1)b.push_back(x);
			else if(f==2&&rev%2==0)b.push_back(x);
			else fr.push_back(x);
		}
	}
	string t;
	for(int i=fr.size()-1;i>=0;i--)t+=fr[i];
	t+=s;
	for(int i=0;i<b.size();i++)t+=b[i];
	if(rev&1)reverse(t.begin(),t.end());
	cout<<t<<"\n";
}


Measured memory_bytes: 1368
n,m=map(int,input().split())
l=[0]*(n+1)
mod=10**9+7
M=set([int(input()) for _ in range(m)])
for i in M:
    l[i]=-1
l[0]=1
for i in range(n):
    if l[i]!=-1:
        if l[i+1]!=-1:
            l[i+1]=(l[i+1]+l[i])%mod
        if i+2<=n:
            if l[i+2]!=-1:l[i+2]=(l[i+2]+l[i])%mod
print(l[n])

Measured memory_bytes: 13984
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, c, k := nextInt(), nextInt(), nextInt()
	t := nextInts(n)
	sort.Sort(sort.IntSlice(t))

	ans := 1
	canRide, leave := c-1, t[0]+k
	for i := 1; i < n; i++ {
		if canRide > 0 && t[i] <= leave {
			canRide--
		} else {
			ans++
			canRide = c - 1
			leave = t[i] + k
		}
	}

	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 3072
#include <set>
#include <vector>
#include <iostream>
using namespace std;
using oppo = set<int>;

bool same_dices(int *d1,int *d2) {
	oppo o105 {d1[0],d1[5]},o114 {d1[1],d1[4]},o123 {d1[2],d1[3]};
	oppo o205 {d2[0],d2[5]},o214 {d2[1],d2[4]},o223 {d2[2],d2[3]};
	set<oppo> s1 {o105,o114,o123};
	set<oppo> s2 {o205,o214,o223};
	bool same = false; // default to not the same
	if (s1 == s2) {
		if (o105 == o205 || o105 == o214) {
			while (!(d1[0] == d2[0] && d1[5] == d2[5])) {
				// roll dice 2 in direction of north
				int temp = d2[0];
				d2[0] = d2[1];
				d2[1] = d2[5];
				d2[5] = d2[4];
				d2[4] = temp;
			}
		} else if (o105 == o223) {
			while (!(d1[0] == d2[0] && d1[5] == d2[5])) {
				// roll dice 2 in direction of east
				int temp = d2[0];
				d2[0] = d2[3];
				d2[3] = d2[5];
				d2[5] = d2[2];
				d2[2] = temp;
			}
		}
		while (!(d1[1] == d2[1] && d1[4] == d2[4])) {
			// rotate dice 2
			int temp = d2[1];
			d2[1] = d2[2];
			d2[2] = d2[4];
			d2[4] = d2[3];
			d2[3] = temp;
		}
		if (d1[2] == d2[2]) {
			same = true;
		} else if (d1[0] == d1[5] && d1[2] == d2[3]) {
			same = true;
		}
	}
	return same;
}

int main() {
	int n;
	cin >> n;
	vector<int[6]> dice(n);
	// input dice
	for (int i = 0;i != n;++i) {
		for (int j = 0;j != 6;++j) {
			cin >> dice[i][j];
		}
	}
	bool all_different = true; // default to all different
	for (int i = 0;i != n-1;++i) {
		for (int j = i+1;j != n;++j) {
			if (same_dices(dice[i],dice[j])) {
				all_different = false;
				break;
			}
		}
		if (!all_different) {
			break;
		}
	}
	cout << (all_different ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3116
#include<iostream>
#include<string>


using namespace std;
int main(){

    int a,b;
    string c,d;

    cin >> a>>b;
    if(a*b%2==0){    
        c="Even";
    }else{
        c="Odd";
    };
    
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#import numpy as np

n,a,b=map(int,input().split())
#M=10**8
M=2*10**5+1
Mod=10**9+7
fac=[0]*M
finv=[0]*M
inv=[0]*M
ans=pow(2,n,Mod)-1

#finvに逆元、facに階乗のmod
"""
def COMinit():
  fac[0]=fac[1]=1
  finv[0]=finv[1]=1
  inv[1]=1
  for i in range(2,M):
    fac[i]=(fac[i-1]*i%Mod)%Mod
    inv[i]=Mod-inv[Mod%i]*(Mod//i) %Mod
    finv[i]=(finv[i-1]*inv[i]%Mod)%Mod
"""

def COMinit():
  fac[0]=n%Mod
  fac[1]=(fac[0]*(n-1))%Mod
  finv[0]=finv[1]=1
  inv[1]=1
  for i in range(2,M):
    fac[i]=(fac[i-1]%Mod*(n-i))%Mod
    inv[i]=Mod-inv[Mod%i]*(Mod//i) %Mod
    finv[i]=(finv[i-1]*inv[i]%Mod)%Mod
def COM(n,k):
  if n<k:
    return 0
  if n<0 or k<0:
    return 0
  return (fac[k-1]*(finv[k]%Mod))%Mod

COMinit()
ans-=(COM(n,a)+COM(n,b))
print(ans%Mod)


Measured memory_bytes: 43504
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 998244353
#define inf 100000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
pll p[10];
//indexing starts from 1
ll bit[1000009],N;
void update(ll x,ll value)
{
      for(;x<=N;x+=x&-x)
      {
        bit[x]+=value;
        bit[x]%=mod;
        bit[x]+=mod;
        bit[x]%=mod;
    }
}
ll query(ll x)
{
     ll sum=0;
     for(;x>0;x-=x&-x)
     {
        sum+=bit[x];
        sum%=mod;
        sum+=mod;
        sum%=mod;
    }
     return sum;
}
void solve()
{
    N=200009;
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    ll x,y;
    for(ll i=0;i<k;i++)
    {
        cin>>x>>y;
        p[i]={x,y};
    }
    update(1,1);
    update(2,-1);
    for(ll i=1;i<n;i++)
    {
        ll val=query(i);
        for(ll j=0;j<k;j++)
        {
            update(i+p[j].ff,val);
            update(i+p[j].ss+1,-val);
        }
    }
    cout<<query(n);
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}

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

constexpr int MAXN = 1e5 + 1;
int freq[MAXN];

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

    long long sum = 0;
    for (int i = 0, x; i < n; i++)
    {
        cin >> x;
        freq[x]++;
        sum += x;
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int prev, next;
        cin >> prev >> next;
        int delta = next - prev;
        freq[next] += freq[prev];
        sum += delta * freq[prev];
        freq[prev] = 0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n;
	cin >> n;
	int a;
	vector<int> v;
	rep(i,n){
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	bool flag = 0;
	//だめなら1になるflag
	if (n%2==1) {
		if (v[0]!=0) {
			flag = 1;
		}
		for (int i=1;i<n;i+=2) {
			if (v[i]==i+1&&v[i+1]==i+1) {
				continue;
			}
			else {
				flag = 1;
				break;
			}
		}
	}
	else {
		for (int i=0;i<n;i+=2) {
			if (v[i]==i+1&&v[i+1]==i+1) {
				continue;
			}
			else {
				flag = 1;
				break;
			}
		}
	}

	if (flag) {
		cout << "0" << endl;
	}
	else {
		ll cn = n/2;
		ll ans = 1;
		rep(i,cn){
			ans *= 2;
			ans %= 1000000007;
		}
		
		cout << ans << endl;
	}
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i = 0;i<n;++i)
#define fri(i,a,b) for(int i= a;i<=b;++i)
#define fro(i,a,b) for(int i= a;i>=b;--i)
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define fi first
#define se second
#define pb(x) push_back(x)
#define  mp(x,y) make_pair(x,y)
#define endl  "\n"
#define  ii  pair<int,int>
#define  LL  long long
#define  maxm(a,b,c)  max(a,max(b,c))
long a[100010],w[100010],dp[110][100010],result;
long knap(int n,int s)
{
	if(n<0 || s<=0)return  0;
	//debug(dp[n][s]);
	if(dp[n][s]!=-1)return dp[n][s];
	
	if(w[n]>s)
	{
	result = knap(n-1,s);
//	dp[n][s]= result;
	}
	else
	{
		long item1= knap(n-1,s);
		long item2 =a[n]+knap(n-1,s-w[n]);
		result = max(item1,item2);
	}
	dp[n][s]= result;
	return result;
}
int main()
{
long n,s;
cin>>n>>s;
fri(i,1,n){
	cin>>w[i];
	cin>>a[i];
}
memset(dp,-1,sizeof(dp));
cout<<knap(n,s);
}

Measured memory_bytes: 86400
#include <iostream>

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

using namespace std;

//??????n?????????a?????????x???????????°true?????????????????°false?????????
bool binary_search(int a[], int n, int x) {
    int l = 0, r = n;
    while (r - l > 0) {
        int mid = (l + r) / 2;
        if(a[l]==x){
        	return true;
        }
        l++;
    }
    return false;
}

int n;
int S[100005];
int q;
int main() {
    int ans = 0;
    cin >> n;
    rep(i, n) cin >> S[i];
    cin >> q;
    rep(i, q) {
        int t;
        cin >> t;
        if (binary_search(S, n, t)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3424
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long
const int N = 4005;
const ll mod = 1e9+7;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}

void solve()
{
    int n,x,y;
    cin>>n>>x>>y;
    
    map<int,int>mp;

    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int d = abs(i-j);
            d = min(d,abs(x-i)+1+abs(y-j));
            d = min(d,abs(y-i)+1+abs(x-j));
            mp[d]++;
        }
    }

    for(int i=1;i<=n-1;i++){
        cout<<mp[i]<<"\n";
    }
    return;
}
// how r u bro

Measured memory_bytes: 3724
#include <stdio.h>

int main(void)
{
  int i;

  int freq[100];
  for (i=0; i<100; ++i) {
    freq[i] = 0;
  }

  int n;
  int mode = 0;
  while (scanf("%d", &n) != EOF) {
    ++freq[n-1];
    mode = (mode > freq[n-1]) ? mode : freq[n-1];
  }

  for (i=0; i<100; ++i) {
    if (mode == freq[i]) {
      printf("%d\n", i + 1);
    }
  }

  return 0;
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/abc151/tasks/abc151_c
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

vector<bool> vc[100005];

int main()
{
    lli n,m,p[100005],i,c=0,pen=0;
    char s[100005][4];
    cin>>n>>m;
    for(i=1;i<=m;i++)
    {
        cin>>p[i]>>s[i];
        vc[p[i]].push_back((s[i][0]=='W' ? 0 : 1));
    }
    for(i=1;i<=n;i++)
    {
        lli flag=0,j;
        for(j=0;j<vc[i].size();j++)
        {
            if(vc[i][j]==1)
            {
                flag=1;
                break;
            }
        }
        if(flag)
        {
            c++;
            pen+=j;
        }
    }
    cout<<c<<" "<<pen<<"\n";
    return 0;
}

Measured memory_bytes: 11588
#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i] -= i+1;
    sort(a.begin(), a.end());
    int b = a[n/2];
    ll ans = 0;
    rep(i, n) ans += abs(a[i] - b);
    cout << ans << endl;
}


Measured memory_bytes: 3988
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int mod = 1e9 + 7;

int n , x , y , z;
int dp[50][1 << 18];

int main() {
	scanf("%d %d %d %d" , &n , &x , &y , &z);
	int st = (1 << (x + y + z - 1)) | (1 << (y + z - 1)) | (1 << (z - 1));
	dp[0][0] = 1;
	int ans = 1;
	for (int i = 1; i <= n; ++i) {
		ans = (LL)ans * 10 % mod;
		for (int j = 0; j < (1 << (x + y + z)); ++j) {
			if(dp[i - 1][j] && (j & st) != st) {
				for (int k = 1; k <= 10; ++k) {
					int now = (j << k) | (1 << (k - 1));
					now &= (1 << (x + y + z)) - 1;
					dp[i][now] = (dp[i][now] + dp[i - 1][j]) % mod;
				}
			} 
		}
	}
	for (int i = 0; i < (1 << (x + y + z)); ++ i) {
		if((i & st) != st) ans = ((ans - dp[n][i]) % mod + mod) % mod;
	}
	printf("%d" , ans);
	return 0;
}

Measured memory_bytes: 20508
N=int(input())
A,B=[map(int,input().split()) for _ in range(2)]
cnt1,cnt2=0,0
for a, b in zip(A,B):
    if b-a >= 2:
        cnt2 += (b-a)//2
    elif b-a < 0:
        cnt1 += (a-b)
print("Yes" if cnt1<=cnt2 else "No")

Measured memory_bytes: 41968
class UnionFind():
    """ Union-Find木の実装（ランクあり） """
    def __init__(self, n):
        self.n = n
        self.parent = [-1]*(n+1)    # parent 親 マイナスだったら根で、絶対値が集合の数
        self.rank   = [0]*(n+1)     # rank 深さ

    def root(self, x):
        """ 木の根を求める """
        if self.parent[x] < 0:      # xが根
            return x
        else:
            self.parent[x] = self.root(self.parent[x])  # 経路圧縮
            return self.parent[x]
            
    def unite(self, x, y):
        """ xとyの属する集合を併合 """
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return 0
        elif self.rank[x] > self.rank[y]:
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        else:
            self.parent[y] += self.parent[x]
            self.parent[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def isSame(self, x, y):
        """ xとyが同じ集合に属するか否か """
        return self.root(x) == self.root(y) or x==y
    
    def size(self, x):
        """ xと同じ集合に属する数 """
        return -self.parent[self.root(x)]


N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    A, B = map(int, input().split())
    A -= 1; B -= 1
    uf.unite(A, B)
ans = 0
for i in range(N):
    ans = max(ans, uf.size(i))
print(ans)


Measured memory_bytes: 81460
import sys
N, M = map(int, input().split())
a = list(map(int, input().split()))

def gcd(a, b):
    while b :
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

c = 1
s = 0
for i in range(N):
    a[i] //= 2
    if a[i] % 2 == 0 and s == 0:
        if i != 0:
            print(0)
            sys.exit()
        while a[i] % 2 == 0:
            a[i] //= 2
            s += 1
        c *= 2 ** s
    elif s != 0:
        if a[i] < 2 ** s or a[i] % (2 ** s) != 0 or (a[i] // (2 ** s)) % 2 == 0:
            print(0)
            sys.exit()   
    c = lcm(c, a[i])
    
print((M // c) // 2 + (M // c) % 2)

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

ll gcd(ll a, ll b) {
    while ( b != 0 ) {
        ll t = b;
        b = a % b;
        a = t;
    }
    return a;
}

ll solve() {
    ll A, B;
    cin >> A >> B;
    ll g = gcd(A,B);
    ll ans = A / g * B;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

int main(void) {
  int A, B; cin >> A >> B;

  if ((A+B)%3 == 0 || A%3 == 0 || B%3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;

  double m[n],sa;
  for(int i = 0;i < n;i++) cin >> m[i];
  sort(m,m+n);
  sa = m[1] - m[0];
  
  for(int i = 2;i <=n-3;i++){
    if(sa > m[i]-m[i-1]) sa = m[i] - m[i-1];
  }

  double ans1 = (m[n-1]+m[n-2])/sa;
  double ans2 = (m[n-1]+m[n-4])/(m[n-3]-m[n-2]);
  double ans3 = (m[n-3]+m[n-4])/(m[n-1]-m[n-2]);
  

  if(ans1 >= ans2 && ans1 >= ans3) printf("%.6f\n",ans1);
  else if(ans2 >= ans3) printf("%.6f\n",ans2);
  else printf("%.6f\n",ans3);
  return (0);
}

Measured memory_bytes: 3260
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/
#include<bits/stdc++.h>
#define mod 1000000007
#define modc 998244353
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define deb(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << " " << x << " " <<  #y << " " << y << endl
#define deb3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " "  << z << endl;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using namespace std;
template <class T>
string to_binary(T n)
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
bool perfectSq(T n)
{
	if(sqrt(n) == floor(sqrt(n)))
		return true;
	else
		false;
}
void solve()
{
	int i,j;
	ll sum = 0,prod = 1;
	int n,m;
	cin >> n >> m;
	ll h[n];
	for(auto &x : h)
		cin >> x;
	map<int,int>b1,b2;
	while(m--)
	{
		int a,b;
		cin >> a >> b;
		if(h[b-1] < h[a-1])
			b1[b] = -1;
		else if(h[b-1] > h[a-1])
			b1[a] = -1;
		else
			b1[a] = b1[b] = -1;
	}
	for(i=1;i<=n;i++)
		if(b1[i] == 0)
			sum++;
	cout << sum << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll X;
    cin >> X;
    ll a = (360*X)/__gcd(360LL,X);
    cout << ll(a/X) << endl;
}


Measured memory_bytes: 3632