akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

const int MX = 200005;

struct Node{
  int val;
  int link[2], par;
}node[MX];

inline int& val(int x){ return node[x].val; }
inline int& par(int x){ return node[x].par; }
inline int& link(int x, int d){ return node[x].link[d]; }
inline int dir(int x){ return node[par(x)].link[0] != x; }

struct splaytree{
  int root;

  void rotate(int n) // To 
  {
    int p = par(n), d = dir(n);
    link(p, d) = link(n, !d);
    if( link(n, !d) ) par(link(n, !d)) = p;

    par(n) = par(p);
    if( par(p) ) link(par(p), dir(p)) = n;

    link(n, !d) = p; par(p) = n;
  }

  void splay(int x, int f = 0){
    if( x == f ) return;
    while(par(x) != f){
      if( par(par(x)) == f );
      else if(dir(x) == dir(par(x))) rotate(par(x));
      else rotate(x);
      rotate(x);
    }
    if( f == 0 ) root = x;
  }
  
  int erase_end(int v){
    int n = root, l = 0, r = 0;
    while(n){
      if( val(n) >= v ) r = n, n = link(n, 0);
      else l = n, n = link(n, 1);
    }
    if( r == 0 ) return 0;
    else if( l == 0 ){
      int tmp = root; root = 0;
      return tmp;
    }
    else{
      splay(l);
      splay(r, l);
      par(r) = 0;
      link(l, 1) = 0;

      return r;
    }
  }
  
  int max_element(int n){
    return link(n, 1)? max_element(link(n, 1)) : n;
  }

  int back(){
    int v = max_element(root); splay(v);
    return v;
  }

  void push_back(int n)
  {
    splay(max_element(root));
    link(root, 1) = n; par(n) = root;
  }

  bool empty(){ return !root; }

  void print(int n){
    if( link(n, 0) ) print(link(n, 0));
    printf("%d ", val(n));
    if( link(n, 1) ) print(link(n, 1));
  }
};

typedef pair<int, splaytree> event;

splaytree A[MX];
set<int> X;
int D[MX];

void print(int t)
{
  printf("%d\n", t);
  for(int c : X){
    printf("%d : ", c);
    A[c].print(A[c].root);
    printf("\n");
  }
}


int main()
{
  int N;
  scanf("%d", &N);
  for(int i = 1; i <= N; i++) scanf("%d", D+i);
  for(int i = 1; i <= N; i++) val(i) = i;
  vector<event> L;
  for(int i = 1; i <= N; i++){
    int d = lower_bound(L.begin(), L.end(), D[i], [](event c, int l){ return c.first > l; }) - L.begin();

    if( L.size() == d ){
      val(D[i]) = D[i];
      splaytree tmp; tmp.root = D[i];
      L.emplace_back(D[i], tmp);
    }
    else{
      L[d].second.push_back(D[i]);
      L[d].first = D[i];
    }
  }
  for(event c : L){
    X.insert(c.first);
    swap(A[c.first], c.second);
  }

  int count = 0;
  int t, mx = N;
  for(t = 0; X.size() > 1; t++){
    int cur = *X.rbegin();
    splaytree lst = A[cur];// swap(lst, A[cur]);
    while(!lst.empty() && lst.back() == mx) lst.erase_end(mx--);
    X.erase(cur);

    while(!lst.empty()){
      int en = lst.back(), st = 0;
      auto it = X.lower_bound(en);
      if( it != X.begin()) st = *prev(it);
      else break;

      int v = lst.erase_end(st);
      A[st].push_back(v);

      int tmp = A[st].back();
      X.erase(st); X.insert(tmp);
      swap(A[st], A[tmp]);
    }
    if( !lst.empty() ){
      int tmp = lst.back();
      swap(A[tmp], lst);
      X.insert(tmp);
    }
  }
  printf("%d\n", t);
}

Measured memory_bytes: 15856
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,m,g[111][111]={},d[111][111]={},s[111]={},r[111]={},f[111]={};
	cin>>n>>m;
	FOR(i,0,111)FOR(j,0,111)g[i][j]=mod;
	FOR(i,0,m){
		int a,b,c;
		cin>>a>>b>>c;
		g[a][b]=c;
		g[b][a]=c;
	}
	FOR(i,1,n){//s
		FOR(j,i+1,n+1){//g
			FOR(k,0,n+1)s[k]=mod;
			FOR(k,0,n+1)r[k]=0;
			FOR(k,0,n+1)f[k]=-1;
			s[i]=0;
			int now=i;
			while(now!=j){
				r[now]=1;
				//cout<<"i:"<<i<<" j:"<<j<<" now:"<<now<<endl;
				FOR(k,1,n+1){
					if(g[now][k]!=mod){
						if(s[now]+g[now][k]<s[k]){
							s[k]=s[now]+g[now][k];
							f[k]=now;
							//cout<<"fk:"<<f[k]<<" s[k]:"<<s[k]<<"(to k:"<<k<<endl;
						}
					}
				}
				int min=mod;
				FOR(k,1,n+1){
					//cout<<"i:"<<i<<" j:"<<j<<" now:"<<now<<" r[k]"<<r[k]<<endl;
					if(r[k]!=0)continue;
					if(min>s[k]){
						min=s[k];
						now=k;
					}
				}
			}
			int tr=j;
			//cout<<"tes"<<endl;
			while(tr!=i){
				//cout<<"i:"<<i<<" j:"<<j<<" now:"<<now<<" f[now]"<<f[now]<<endl;
				d[tr][f[tr]]=d[f[tr]][tr]=1;
				tr=f[tr];
			}
		}
	}
	int cou=0;
	FOR(i,0,n){//s
		FOR(j,i+1,n+1){//g
			//cout<<d[i][j]<<" ";
			if(g[i][j]!=mod&&d[i][j]==0)cou++;
		}
		//cout<<endl;
	}
cout<<cou<<endl;

    return 0;
}


Measured memory_bytes: 384
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()

dp = [99999999]*(n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    k = 6
    while i-k >= 0:
        dp[i] = min(dp[i], dp[i-k]+1)
        k *= 6
    k = 9
    while i-k >= 0:
        dp[i] = min(dp[i], dp[i-k]+1)
        k *= 9
print(dp[n])



Measured memory_bytes: 3828
#include <stdio.h>
#include <iostream>
#include <list>
using namespace std;

class Node
{
private:
public:
	Node();
	int id;
	list<int> next_node_list;
	int next_idx;
	void AddNextNode(int id);
	void SetGroup(int prev_id, int num);
	int group;
	void Init(int id);
};

Node::Node()
{
	group = 0;
	next_idx = 0;
}

void Node::AddNextNode(int id)
{
	next_node_list.push_back(id);
}

Node *Node_list;

void Node::SetGroup(int prev_id, int num)
{
	group = num;

	list<int>::iterator itr;
	itr = next_node_list.begin();
	for (int i = 0; i < next_idx; i++) {
		itr++;
	}
	
	for(; itr != next_node_list.end(); itr++){
		next_idx++;
		if (prev_id != *itr) {
			Node_list[*itr].SetGroup(id, num);
		}
	}
}

void Node::Init(int id)
{
	this->id = id;
}

int main(void)
{
	//input
	int n;
	cin >> n;
	Node_list = new Node[n]();
	for (int i = 0; i < n; i++) {
		Node_list[i].Init(i);
	}
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		Node_list[s].AddNextNode(t);
		Node_list[t].AddNextNode(s);
	}

	//group
	int group = 1;
	for (int i = 0; i < n; i++) {
		if (Node_list[i].group) continue;
		Node_list[i].SetGroup(-1, group);
		group++;
	}
	
	//output
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int s, t;
		cin >> s >> t;
		if (Node_list[s].group == Node_list[t].group && Node_list[s].group != 0) {
			cout << "yes" << "\n";
		}
		else {
			cout << "no" << "\n";
		}
	}
	
	return 0;
}


Measured memory_bytes: 17104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int pos[110];
int main() {
    ios::sync_with_stdio(false);
    int n;cin>>n;
    for(int i=1;i<=n;i++)
        cin>>pos[i];
    int minn=*min_element(pos+1,pos+n+1);
    int maxx=*max_element(pos+1,pos+n+1);
//    int poss=(minn+maxx+1)/2;
//    ll ans=0;
//    for(int i=1;i<=n;i++)
//        ans+=1ll*(pos[i]-poss)*(pos[i]-poss);
//    cout<<ans<<endl;
    ll ans=INT_MAX;
    for(int i=minn;i<=maxx;i++){
        ll xx=0;
        for(int j=1;j<=n;j++){
            xx+=1ll*(pos[j]-i)*(pos[j]-i);
        }
        ans=min(ans,xx);
    }
    cout<<ans<<endl;
    return 0;
}


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

int n, k;
vector<int> a, dp;
int go(int x) {
    if (dp[x] != -1)
        return dp[x];
    int y = 1;
    for (int z : a) {
        if (x >= z)
            y &= go(x - z);
    }
    y ^= 1;
    return dp[x] = y;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> n >> k;
    a.resize(n);
    dp.assign(k + 1, -1);
    for (auto& it : a) cin >> it;
    fill(dp.begin(), dp.begin() + a[0], 0);
    int res = go(k);
    cout << (res ? "First\n" : "Second\n");
    return 0;
}

Measured memory_bytes: 8332
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp


int main() {
    std::cout << std::fixed << std::setprecision(15);
    long long n;
    cin >> n;

    ll dp[50];

    dp[0] = 1;
    dp[1] = 1;

    rep(i,n){
        if(i == 0){
            continue;
        }
        dp[i+1] = dp[i] + dp[i-1];
    }

    cout << dp[n] << endl;

}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }
 
int main() {
  ull n;
  cin >> n;

  vector<ull> p = {};
  vector<ull> q = {};

  each(i, n) {
    ull tmp;
    cin >> tmp;
    p.push(tmp);
  }

  each(i, n) {
    ull tmp;
    cin >> tmp;
    q.push(tmp);
  }

  vector<ull> v(n);
  iota(v.begin(), v.end(), 1);
  ull index = 1;
  ull pp = 0;
  ull qq = 0;
  do {
    vector<ull> current = {};
    for (auto x : v) {
      current.push(x);
    }
    if (current == p) {
      pp = index;
    }
    if (current == q) {
      qq = index;
    }
    index++;
  } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

  cout << ((pp >= qq) ? pp - qq : qq - pp) << endl;
 
  return 0;
}


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

vector< pair<ll,int> > prime_factor(ll n) {
  vector< pair<ll,int> > res;
  for (ll i=2; i*i <= n; i++){
    int x = 0;
    while (n%i == 0){
      n /= i;
      x++;
    }
    if(x != 0) res.emplace_back(i,x);
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

int main(){
  ll n;
  cin >> n;
  int cnt = 0;

  // nを素因数分解して管理
  vector< pair<ll,int> > p_factors = prime_factor(n);
  //cout << factors[2] << endl;

  // 素因数分解のリストから、小さい数を重複なしに取り出しながら n を割れる回数をカウント
  vector <ll> factors();
  for (auto p : p_factors){
    int x=p.second;
    int b = 1;
    while(b <= x){
      x -= b;
      b ++;
      cnt++;
    }
  }

  cout << cnt << endl;


  return 0;
}


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

int main(){
  int N; cin >> N;
  bool check = true;
  rep(i, N) {
    int A; cin >> A;
    if (A % 2 == 1) continue;
    if ((A % 3) * (A % 5) != 0) check = false;
  }

  if (check) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

using namespace std;

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

const LL inf = 1000000000000000;
const LL mod = 1000000007;

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

	LL dist = inf;
	for (LL j = 1; j*j <= n; ++j) {
		if (n % j == 0) {
			LL x = j, y = n/j;
			dist = min(dist, x-1 + y-1);
		}
	}
	cout << dist << endl;
	 
}

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

using namespace std;

int main() {
  int64_t N, D, A;
  cin >> N >> D >> A;
  vector<pair<int64_t, int64_t>> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i].first >> X[i].second;
  }

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

  queue<pair<int64_t, int64_t>> bomb_locations;
  int64_t bomb_counts = 0;
  int64_t answer = 0;

  for (int i = 0; i < N; i++) {
    int64_t enemy_position = X[i].first;

    while (!bomb_locations.empty()) {
      if (bomb_locations.front().first + D < enemy_position) {
	bomb_counts -= bomb_locations.front().second;
	bomb_locations.pop();
      } else {
	break;
      } 
    }

    int64_t enemy_hp = X[i].second;
    int64_t damage = A * bomb_counts;
    int64_t remain_hp = max(enemy_hp - damage, 0L);
    int64_t bomb = (remain_hp + A - 1) / A;
    bomb_locations.push({enemy_position + D, bomb});
    bomb_counts += bomb;
    answer += bomb;
  }

  cout << answer << endl;
  return 0;
}


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

using namespace std;

int N;
int value[22];
int cost[22];

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++) cin >> value[i];
	for (int i = 0; i < N; i++) cin >> cost[i];

	int max = 0;
	for (int i = 0; i < N; i++)
	{
		if (value[i] > cost[i]) max += (value[i] - cost[i]);
	}

	cout << max;
}

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

using namespace std;
typedef         long long int   ll;


#define         input           freopen("input.txt","r",stdin)
#define         output          freopen("output.txt","w",stdout)
#define         si(a)           scanf("%d",&a)
#define         sii(a,b)        scanf("%d%d",&a,&b)
#define         siii(a,b,c)     scanf("%d%d%d",&a,&b,&c)
#define         pi(a)           printf("%d",a)
#define         spc             printf(" ")
#define         bl              printf("\n")
#define         here(a)         printf("#### %d ####",a)
#define         pii             pair<int,int>
#define         fr(i,n)         for(int i=0;i<n;i++)
#define         case(num)       printf("Case %d:",num)
#define         inf             1000000050
#define         MAX             500020




int main(){

    //input;
    //output;

    string s;

    cin>>s;
    int sum = 0;
    for(int i=s.length()-1;i>=0;i--){
        sum += ('0'-s[i]);
    }

    if(sum % 9 == 0){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;

    return 0;
}
/**
*/


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

void Print(const vector<int>& xs) {
  cout << xs[0] << ", " << xs[1] << ", " << xs[2] << endl;
}

int main() {
  vector<int> xs(3);
  for (auto& x : xs) cin >> x;
  int n_operations = 0;
  while (true) {
    sort(xs.begin(), xs.end());
    // Print(xs);
    if (xs[0] == xs[1] && xs[1] == xs[2]) break;
    if (xs[1] == xs[2]) {
      xs[0] += 2;
    } else {
      if (xs[0] == xs[1]) {
        ++xs[0];
        ++xs[1];
      } else {
        xs[0] += 2;
      }
    }
    ++n_operations;
  }
  cout << n_operations << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
#define SELECTOR(_1, _2, _3, SELECT, ...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__, _rep1, _rep0)(__VA_ARGS__)
#define _rep0(i, n) for (ll i = 0; i < n; ++i)
#define _rep1(i, k, n) for (ll i = k; i < n; ++i)

void solve(){
  // main coding
  int n,m; cin>>n>>m;
  int INF=1<<15;
  vector<vector<int>> dist(n,vector<int>(n,INF)); // adjacency matrix
  vector<vector<int>> E(n); // adjacency list
  rep(_,m) {
    int a,b; cin>>a>>b;
    --a; --b; // 0-indexed
    dist[a][b]=1;
    E[a].push_back(b);
  }
  // Warshall-Floyd
  rep(k,n) rep(i,n) rep(j,n) {
    dist[i][j]=min(dist[i][k]+dist[k][j],dist[i][j]);
  }
  // loop detection
  int len=n+1,v;
  rep(i,n) {
    if(dist[i][i]<len) {
      v=i;
      len=dist[i][i];
    }
  }
  if(len==n+1) {
    cout<<-1<<"\n";
    return;
  }
  const int vm=v;
  vector<int> ans;
  ans.push_back(v);
  while(len){
    --len;
    rep(i,n) if(dist[v][i]==1 && dist[i][vm]==len){
      ans.push_back(i);
      v=i;
      break;
    }
  }
  cout<<ans.size()<<"\n";
  for(int v:ans) cout<<v+1<<"\n";
}

int main(){
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  solve();
  return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long cost=pow(10,7);
    long long n,m,x;
    cin>>n>>m>>x;
    vector<vector<long long>>book(n,vector<long long>(m+1));
    for(long long i=0;i<n;i++){
        for(long long j=0;j<m+1;j++)
            cin>>book[i][j];
    }
    for(long long i=1;i<=(1<<n);i++){
        long long total=0;
        vector<long long>val(m);
        for(long long j=0;j<n;j++){
            if(i & (1<<j)){
                total+=book[j][0];
                for(long long k=0;k<m;k++)
                    val[k]+=book[j][k+1];
            }
        }
        bool flag=1;
        for(long long j=0;j<m;j++){
            if(val[j]<x){
                flag=0;
                break;
            }
        }
        if(flag)
            cost=min(cost,total);
    }
    if(cost==pow(10,7))
        cout<<-1;
    else
        cout<<cost;
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s, t;
    cin>>s>>t;
    for(int i=0; i<n; i++){
        cout<<s[i]<<t[i];
    }
    cout<<"\n";
	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "5 5", "3949 3774 3598 3469 3424" ].parse.expand.solve == 1541 );
	assert( [ "5 3", "7 4 2 6 4" ].parse.expand.solve == 7 );
}



import core.bitop;
import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], as );
}

auto solve( long k, long[] as )
{
	auto ans = long.max;
	foreach( b; 1L .. 1L << as.length )
	{
		if( b._popcnt != k ) continue;
		auto t = 0L;
		auto p = 0L;
		for( auto i = 0L; 0 < b; i++, b >>= 1 )
		{
			if( p < as[ i ] )
			{
				p = as[ i ];
			}
			else if( b & 1 )
			{
				p++;
				t += p - as[ i ];
			}
		}
		ans = min( ans, t );
	}
	return ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    long long a[n],i,l=0,r=0,sum=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=k;i<n;i++)
    {
        if(a[i]>a[i-k])
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }



    return 0;
}


Measured memory_bytes: 5152
#写経
#https://atcoder.jp/contests/abc168/submissions/14421546
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from bisect import bisect_left, bisect_right
INF = 10 **18

def resolve():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for i in range(n)]
    b = [list(map(int, input().split())) for i in range(m)]
 
    X = {-INF, INF}
    Y = {-INF, INF}
    for i in a:
        Y.add(i[2])
    for i in b:
        X.add(i[0])
 
    X = list(sorted(X))
    Y = list(sorted(Y))
    n = len(X) - 1
    m = len(Y) - 1
    wallx = [[False] * m for i in range(n)]
    wally = [[False] * m for i in range(n)]
 
    for x1, x2, y1 in a:
        x1 = bisect_left(X, x1)
        y1 = bisect_left(Y, y1)
        x2 = bisect_right(X, x2) - 1
        for i in range(x1, x2):
            wally[i][y1] = True
 
    for x1, y1, y2 in b:
        x1 = bisect_left(X, x1)
        y1 = bisect_left(Y, y1)
        y2 = bisect_right(Y, y2) - 1
        for i in range(y1, y2):
            wallx[x1][i] = True
 
    cow = [[False] * m for i in range(n)]
    cx = bisect_right(X, 0) - 1
    cy = bisect_right(Y, 0) - 1
    cow[cx][cy] = True
    q = [(cx, cy)]
    ans = 0
 
    while q:
        x, y = q.pop()
        if not x or not y:
            print("INF")
            sys.exit()
        ans += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y])
        if x and not wallx[x][y] and not cow[x - 1][y]:
            cow[x - 1][y] = True
            q.append((x - 1, y))
        if y and not wally[x][y] and not cow[x][y - 1]:
            cow[x][y - 1] = True
            q.append((x, y - 1))
        if x + 1 < n and not wallx[x + 1][y] and not cow[x + 1][y]:
            cow[x + 1][y] = True
            q.append((x + 1, y))
        if y + 1 < m and not wally[x][y + 1] and not cow[x][y + 1]:
            cow[x][y + 1] = True
            q.append((x, y + 1)) 
    print(ans)
resolve()

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

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

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

        int[][] map = new int[3][3];
        boolean ans = false;

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                map[i][j] = scanner.nextInt();
            }
        }


        for (int i = 0; i <= 100; i++) {
            for (int j = 0; j <= 100; j++) {
                for (int k = 0; k <= 100; k++) {
                    int ok = 0;
                    int[] b = {map[0][0] - i, map[1][1] - j, map[2][2] - k};

                    if(i + b[1] == map[0][1])ok++;
                    if(i + b[2] == map[0][2])ok++;
                    if(j + b[0] == map[1][0])ok++;
                    if(j + b[2] == map[1][2])ok++;
                    if(k + b[0] == map[2][0])ok++;
                    if(k + b[1] == map[2][1])ok++;

                    if(ok == 6)ans = true;
                }
            }
        }


        if(ans){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }



}




Measured memory_bytes: 40916
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n,m;
int w[30][30];
int flag[1200000];

int main()
{
    for (int i=1; i<=1000; ++i)
        flag[i*i]=1;
    cin>>n>>m;
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=m; ++j)
            cin>>w[i][j];
    int ans=0;
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=n; ++j)
        {
            int tmp=0;
            for (int k=1; k<=m; ++k) 
                tmp += (w[i][k]-w[j][k])*(w[i][k]-w[j][k]);
            ans += flag[tmp];
        }
    cout<<ans/2<<endl;
    
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  sort(d.begin(), d.end());
  int ans = 1;
  if (n != 1) {
    for (int i = 1; i < n; i++) {
      if (d[i] != d[i - 1]) ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
	int f, b , cnt = 0;
	string s;
	cin >> s;
	f = 0, b = s.size() - 1;
	while(f<=b){
	  if(s[f] == s[b]){//端が一致で無視.
	  	f++;
	  	b--;
	  }
	  else if((s[f] != 'x') && (s[b] != 'x')){
	  	cout << -1 << endl;
	  	return 0;
	  }
	  else if(s[f] == 'x'){
	  	cnt++;
	  	f++;
	  }
	  else{//s[b] == 'x'
	  	cnt++;
	  	b--;
	  }
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 512
from functools import reduce


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

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x = sorted(x)
y = []
for i in range(len(x)-1):
    y.append(x[i+1]-x[i])
print(reduce(gcd, y))


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

int main ()
{
    double MAX, MIN;
    double n;
    cin >> n;
    MAX = MIN = n;
    while (cin >> n) {
        if (MAX < n) {
            MAX = n;
        } else if (MIN > n) {
            MIN = n;
        }
    }
    cout << (MAX - MIN) << endl;

    return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll n,k,ans=0;
vector<ll> loop(ll s,vector<ll> a){
    vector<bool> cnt(200002,false);
    vector<ll> S;
    if(s>0){
        S.push_back(s);
        cnt[s]=1;
    }
    For(i,0,n){
        if(!cnt[a[i]]){
            S.push_back(a[i]);
            cnt[a[i]]=1;
        }
        else{
            while(cnt[a[i]]){
                cnt[S[S.size()-1]]=0;
                S.pop_back();
            }
        }
    }
    return S;
}
void Main(){
    cin>>n;
    cin>>k;
    vector<ll> a(n);
    vector<vector<ll>> b(200002);
    For(i,0,n){
        cin>>a[i];
        b[a[i]].push_back(i);
    }
    ll init=0,cnt=0;
    ll place,num;
    vector<ll> lp;
    while(true){
        cnt++;
        lp.push_back(init);
        ll now=init;
        if(now==0)place=0;
        else place=b[now][0]+1;
        here:;
        if(place==n)break;
        num=a[place];
        auto itr=upper_bound(ALL(b[num]),place);
        if(b[num].end()-itr==0)init=num;
        else{
            place=*itr+1;
            now=a[place];
            goto here;
        }
    }
    init=lp[(k-1)%cnt];
    vector<ll> S;
    S=loop(init,a);
    /*愚直にやっても間に合わない
    For(i,0,k){
        S=loop(init,a);
        if(S.size()>0) init=S[0];
        else init=0;
    }
    それはそうなんだよな*/
    For(i,0,S.size()) cout<<S[i]<<" ";
    cout<<endl;
}
int main(){
    Main();
    return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;







int main() {

	int n, d;
	cin >> n >> d;

	VVI x(n, VI(d));
	REP(i, n)REP(j, d)cin >> x[i][j];

	int ans = 0;

	REP(i, n) {
		FOR(j, i + 1, n) {
			int cur = 0;
			REP(k, d) {
				cur += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			}
			int l = 0;
			while (l*l < cur)l++;
			if (l*l == cur)ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
cnt1 = 0
now1 = 0
cnt2 = 0
now2 = 0
#+-+-
for i in range(n):
    if i%2==0:
        now1 += a[i]
        if now1>0:
            pass
        else:
            cnt1 += 1-now1
            now1 =1
    else:
        now1 +=a[i]
        if now1<0:
            pass
        else:
            cnt1 += -(-1-now1)
            now1 = -1
#-+-+
#+-+-
for i in range(n):
    if i%2==1:
        now2 += a[i]
        if now2>0:
            pass
        else:
            cnt2 += 1-now2
            now2 =1
    else:
        now2 +=a[i]
        if now2<0:
            pass
        else:
            cnt2 += -(-1-now2)
            now2 = -1

print(min(cnt1,cnt2))

Measured memory_bytes: 63984
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n, k;
    cin >> n >> k;

    cout << (int)(log10(n) / log10(k)) + 1 << "\n";

    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	int N;
	ll H;
	cin >> N >> H;
	vector<ll> a(N);
	vector<ll> b(N);
	ll max_a = 0;
	for (int i = 0; i < N; ++i) {
		cin >> a[i] >> b[i];
		max_a = max(max_a, a[i]);
	}

	ll sum_b = 0;
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		if (max_a <= b[i]) {
			sum_b += b[i];
			++cnt;
		}
	}

	if (sum_b >= H) {
		sort(b.begin(), b.end(), greater<ll>());
		ll sum = 0;
		for (int i = 0; i < N; ++i) {
			sum += b[i];
			if (sum >= H) {
				cout << i + 1 << endl;
				return 0;
			}
		}
	}

	H = H - sum_b;
	ll res = ((H + max_a - 1) / max_a) + cnt;
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1792
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var gachaList = mutableListOf<String>()
    repeat(n) {
        gachaList.add(sc.next())
    }
    var gachaList_distinct: List<String> = gachaList.distinct()
    println(gachaList_distinct.size)
}

Measured memory_bytes: 73740
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

if a == 1:
    print("Hello World")

elif a == 2:
    inputb = input().split()
    inputc = input().split()

    b = int(inputb[0])
    c = int(inputc[0])
    
    print(b + c)

Measured memory_bytes: 38256
#include <stdio.h>
#include <stdlib.h>

int main(){
	int N, i, ans;
	scanf("%d", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	for(ans = 0; ; ans++){
		for(i = 0; i < N; i++){
			if(A[i] % 2 != 0){
				printf("%d\n", ans);
				return 0;
			}
		}
		for(i = 0; i < N; i++){
			A[i] /= 2;
		}
	}
}

Measured memory_bytes: 128
#coding:utf-8
ans = []
while True:
    JOI=0
    IOI=0
    try:
        string=raw_input()
    except EOFError:
        break
    length=len(string)
    for i in xrange(length-2):
        if string[i] == 'J':
            if (string[i+1] == 'O' and string[i+2] == 'I'):
                JOI += 1
        if string[i] == 'I':
            if (string[i+1] == 'O' and string[i+2] == 'I'):
                IOI += 1
    ans.append(JOI)
    ans.append(IOI)
for i in ans:
    print i

Measured memory_bytes: 4240
#include <stdio.h>

int n, A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2100
#include<stdio.h>
static const int N=100;
int main(){
  int M[N][N];
  int i,j,n,u,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j) printf(" ");
      printf("%d",M[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 636
#include <cstdio>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    scanf("%d", &n);
    ll res[n][21];
    int nums[n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= 20; j++) res[i][j] = 0;
    }
    for (int i = 0; i < n; i++) scanf("%lld", &nums[i]);
    res[0][nums[0]] = 1;
    for (int i = 1; i < n-1; i++) {
        for(int j = 0; j <= 20; j++){
            if (j-nums[i] >= 0 && j-nums[i] <= 20) res[i][j] += res[i-1][j-nums[i]];
            if (j+nums[i] >= 0 && j+nums[i] <= 20) res[i][j] += res[i-1][j+nums[i]];
        }
    }
    printf("%lld\n", res[n-2][nums[n-1]]);
    return 0;
}



Measured memory_bytes: 2740
#include<iostream>
#include<string>
#include<stack>

using namespace std;

int main() {

	stack<int> num;
	while (1) {
		string in;
		cin >> in;
		if (in == "+" || in == "-" || in == "*") {
			int a, b;
			b = num.top();
			num.pop();
			a = num.top();
			num.pop();
			if (in == "+")num.push(a + b);
			if (in == "-")num.push(a - b);
			if (in == "*")num.push(a * b);
		}
		else if (cin.eof())break;
		else num.push(stoi(in));
	}

	cout << num.top() << endl;

	return 0;
}


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

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

int main(){
  ll x;
  cin >> x;

  ll t = sqrt(2*x);
  if(((1+t)*t)/2>=x) cout << t;
  else cout << t+1;
}

Measured memory_bytes: 3580
#!/usr/bin/python

import itertools

def main():
    anthenas = []
    for _ in range(5):
        anthenas.append(int(input()))
    k = int(input())

    for v in  itertools.combinations(anthenas, 2):
        d = abs(v[1] - v[0])
        if d > k:
            msg = ':('
            break
        msg = 'Yay!'
    
    print(msg)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
sum_com = 0
distinct_a = sorted(list(set(a)), reverse=True)
comfort = {i: 0 for i in distinct_a}
comfort[a[0]] = 1
max_com = 0

for ai in a[1:]:
    sum_com += distinct_a[max_com]
    if distinct_a[max_com] == ai:
        comfort[distinct_a[max_com]] += 1
    else:
        comfort[distinct_a[max_com]] -= 1
        comfort[ai] += 2
        if comfort[distinct_a[max_com]] == 0:
            max_com += 1

print(sum_com)


Measured memory_bytes: 39696
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskC   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int M = in.nextInt();
        int ans = 0;
        int x[] = new int[M];
        for (int i=0; i<=M-1; i++) {
            x[i] = in.nextInt();
        }
        Arrays.sort(x);
        int xs[] = new int[M-1];
        for (int i=0; i<=M-2; i++) {
            xs[i] = x[M-1-i] - x[M-2-i];
        }
        Arrays.sort(xs);
        for (int i=0; i<=M-2-(N-1); i++) {
                ans+=xs[i];
        }
        out.println(ans);
    }

}
}



Measured memory_bytes: 50992
#include <stdio.h>

int A[200000];

int main(void)
{
	int q, com, x, it = 0;
	scanf("%d", &q);
	while (q--) {
		scanf("%d", &com);
		if (com == 0) {
			scanf("%d", &x);
			A[it++] = x;
		}
		else if (com == 1) {
			scanf("%d", &x);
			printf("%d\n", A[x]);
		}
		else {
			it--;
		}
	}
	return 0;
}


Measured memory_bytes: 2460
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d%d",&a,&b);
  int i,c[3],max;
  c[0]=a+b;
  c[1]=a-b;
  c[2]=a*b;
  max=c[0];
  for(i=0;i<=2;i++)if(c[i]>=max)max=c[i];
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 128
u, s, e, w, n, d = map(int, input().split())
insts = input()
for inst in insts:
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w
print(u)

Measured memory_bytes: 7644
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
char s[N];
int main() {
    int s, w;   cin >> s >> w;
    if (w >= s) {
        cout << "unsafe";
    }
    else {
        cout << "safe";
    }
#ifndef ONLINE_JUDGE
    system("pause");
#endif
    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll ans = a[0];
  multiset<pair<int, int>, greater<>> s = {{a[1], a[0]}, {a[1], a[0]}};
  for (int i = 2; i < n; ++i) {
    auto it = s.begin();
    s.erase(it);
    ans += it->first;
    s.insert({a[i], it->first});
    s.insert({a[i], it->second});
  }
  cout << ans;
}

Measured memory_bytes: 13552
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<endl;}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
}

int main(){
  int a,b,c;cin>>a>>b>>c;
  cout<<max({a,b,c})*9+a+b+c<<endl;

  return 0;
}

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

int main() {
  int y,m,d;
  char a, b;
  cin >> y >> a >> m >> b >> d;
  
  if (m <= 4){
    cout << "Heisei" << endl;
  }
  else {
    cout <<"TBD"<< endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//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 inf = 1LL << 60;

long long dp[100010];

int main(){
  int n,min1;
  int i;
  cin >> n;
  vector<int> h(n);

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

  for(i=0;i<100010;++i){
    dp[i]=inf;
  }

  dp[0]=0;

  for(i=1;i<n;++i){
    min1=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    dp[i]=min1;
    if(i>1) {
      min1=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
      dp[i]=min1;

    }
  }

  cout << dp[n-1] << endl;
  return 0;

}


Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>

int main(void){
	int h, m, s;

	while(1){
		scanf("%d %d %d", &h, &m, &s);
		if(h == -1 && m == -1 && s == -1) break;

		int time = h*3600 + m*60 + s;
		int rem = 2*3600 - time;
		
		printf("%02d:%02d:%02d\n", rem/3600, (rem % 3600)/60, rem % 60);
		rem = rem * 3;
		printf("%02d:%02d:%02d\n", rem/3600, (rem % 3600)/60, rem % 60);
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
	char a[4],b[4];
	scanf("%s %s",a,b);
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
n=int(input())
s=input()
from itertools import groupby as gb
head=0
m=0
for k,v in [(a,len(list(b))) for a,b in gb(s)]:
    if k==")":
        if m<v:head+=v-m;m=0
        else:m-=v
    else:
        m+=v
print("("*head+s+")"*m)

Measured memory_bytes: 3064
n, m = map(int, input().split())
ac = [0] * n
pen = [0] * n
pen_count = 0
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if ac[p] == "AC":
        continue
    elif s == "AC":
        ac[p] = "AC"
    else:
        pen[p] += 1
 
for i in range(n):
    if ac[i] == "AC":
        pen_count += pen[i]
 
print(ac.count("AC"), pen_count)

Measured memory_bytes: 4596
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
char mas[30][30];
int W,H,sum;
int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0};
void dfs(int x, int y);
int main(){
  int sx,sy;
  while(1){
    sum = 0;
    cin >> W >> H;
    if(W == 0 && H == 0)break;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	cin >> mas[i][j];
	if(mas[i][j] == '@'){
	  sx = j;
	  sy = i;
	}
      }
    }
    dfs(sx,sy);
    cout << sum << endl;
  }
}
void dfs(int x, int y){
  sum++;
  mas[y][x] = '#';
  for(int i = 0; i < 4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx >= 0 && nx < W && ny >= 0 && ny < H && mas[ny][nx] != '#'){
      dfs(nx,ny);
    }
  }
}

Measured memory_bytes: 1168
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N, M = map(int, input().split())

G = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    G[L].append((R, -D))
    G[R].append((L, +D))

ans = [None] * (N + 1)

def calc(i):
    ans[i] = 0
    stack = [i]
    while stack:
        now = stack.pop()
        for next_, d in G[now]:
            if ans[next_] == None:
                ans[next_] = ans[now] + d
                stack.append(next_)
            else:
                if ans[now] + d != ans[next_]:
                    return False
    return True

for i in range(1, N + 1):
    if ans[i] == None:
        if calc(i):
            pass
        else:
            print ('No')
            exit()


max_ = -10 ** 10
min_ = +10 ** 10
for i in ans[1:]:
    max_ = max(max_, i)
    min_ = min(min_, i)

if max_ - min_ > 10 ** 9:
    print ('No')
else:
    print ('Yes')

Measured memory_bytes: 66620
#include<bits/stdc++.h>
#define mxn 1000010
#define LL long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
using namespace std;
int sl,fh;
char s[4];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	scanf("%s",s);
	sort(s,s+4);
	if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2]) puts("Yes");
	else puts("No");
	return 0;
}

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x[] = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        int dist = 0;
        for (int i = 0; i < n; i++) {
            dist += Math.min(2 * x[i], 2 * Math.abs(x[i] - k));
        }
        System.out.println(dist);
    }
}


Measured memory_bytes: 21076
n = int(input())
buf = []
ans = 0

for i in range(n):
  lists = list(input())
  lists.sort()
  s = "".join(lists)
  buf.append(s)
  
buf.sort()
same= 0
sent= buf[0]

for i in range(1,n):
  if buf[i]==sent:
    same += 1
  else:
    sent = buf[i]
    ans += (same*(same+1))//2
    same = 0
  
ans += (same*(same+1))//2

print(ans)  


Measured memory_bytes: 10612
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    ll n, k; cin>>n>>k;
    vector<int> t(n), d(n);
    vector<vector<int>> kinds(n);
    for(int i=0; i<n; i++){
        cin>>t[i]>>d[i];
        t[i]--;
        kinds[t[i]].eb(d[i]);
    }

    vector<P> v;
    for(int i=0; i<n; i++){
        sort(kinds[i].begin(), kinds[i].end(), greater<int>());
        for(int j=0; j<kinds[i].size(); j++){
            v.eb(P(kinds[i][j], j==0?1:0));
        }
    }

    sort(v.begin(), v.end(), greater<P>());
    ll tsum=0, dsum=0;
    vector<int> normal;
    for(int i=0; i<k; i++){
        tsum+=v[i].sc;
        dsum+=v[i].fs;

        if(v[i].sc==0){
            normal.eb(v[i].fs);
        }
    }

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

    ll ans=tsum*tsum+dsum;
    int cnt=0;
    for(int i=k; i<n; i++){
        if(v[i].sc==1){
            tsum+=v[i].sc;
            dsum+=v[i].fs;
            if(cnt<normal.size()) dsum-=normal[cnt++];
            else break;
        }
        chmax(ans, tsum*tsum+dsum);
    }
    cout << ans << endl;
}

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

typedef long long LL;

#define INF 1000000000
#define INF_LL_YJ 1145141919810364364

using namespace std;

#define MAX_N 100005
int N;
LL A[MAX_N];

void input()
{
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
}

void calcGCD()
{
  if(N == 1){
    return;
  }
  LL tmpGCD = __gcd(A[0], A[1]);
  for (int i = 2; i < N; i++) {
    tmpGCD = __gcd(tmpGCD, A[i]);
  }
  for (int i = 0; i < N; i++) {
    A[i] /= tmpGCD;
  }
}

bool solve(int turn = 0)
{
  int GuCnt = 0;
  int index = 0;

  for (int i = 0; i < N; i++) {
    if(A[i] % 2 == 0){
      GuCnt++;
    }
    else{
      index = i;
    }
  }

  if(GuCnt % 2 == 1){
    return turn == 0;
  }
  else{
    if(N-GuCnt >= 2){
      return turn != 0;
    }
    else if(N-GuCnt == 1){
      if(A[index] == 1){
        return turn != 0;
      }
      A[index]--;
      calcGCD();
      int nextTurn = turn+1;
      nextTurn %= 2;
      return solve(nextTurn);
    }
  }

}

int main()
{
  input();

  if(solve()){
    cout << "First" << endl;
  }
  else{
    cout << "Second" << endl;
  }

  return 0;
}


Measured memory_bytes: 1152
#include<iostream>

using namespace std;

int n, A[50];

int solve(int i, int m) {
	if (m == 0)
		return 1;
	if (i >= n)
		return 0;
	
	//	??????????????????????????????
	//	?????? A[i] ?§??????????????????????????????? 
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	
	return res;
}
 
int main() {
	int q, M, i;
	
	cin >> n;
	
	for (int i = 0; i < n; i++)
		cin >> A[i];
	
	cin >> q;
	
	for (int i = 0; i < q; i++) {
		cin >> M;
		
		if (solve(0, M))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	
	return 0;
} 

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    string S;
    cin >> S;
    for (int i = 0; i < S.length(); i++) {
        cout << 'x';
    }
    cout << endl;
}



Measured memory_bytes: 256