akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    string s;
    cin >> s;

    if(s[2]==s[3] && s[4]==s[5]) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=2e5+10;
const int mod=1e9+7;
int maps[520][520];
struct A
{
    int x1,y1,x2,y2;
    A(int x,int y,int xx,int yy):
        x1(x),y1(y),x2(xx),y2(yy) {}

};
int main()
{
    vector<A> a;
    int h,w;
    cin>>h>>w;
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            cin>>maps[i][j];
        }
    }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w-1; j++)
        {
            if(maps[i][j]%2==1)
            {
                a.push_back(A(i,j,i,j+1));
                maps[i][j+1]++;

            }
        }
    }
    for(int i=1; i<=h-1; i++)
    {
        if(maps[i][w]%2==1)
        {
            a.push_back(A(i,w,i+1,w));
            maps[i+1][w]++;
        }
    }
    printf("%d\n",a.size());
    for(int i=0; i<a.size(); i++)
    {
        printf("%d %d %d %d\n",a[i].x1,a[i].y1,a[i].x2,a[i].y2);
    }

    return 0;
}


Measured memory_bytes: 6360
#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++)
typedef long long ll;

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

  if (B+C-A >= 0) {
    cout << B+C-A << endl;
  }else{
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
const double pi=acos(-1);
int main()
{
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double x=h*60+m;
	x/=720;
	x*=2*pi;
	double y=m/30*pi;
	double z=abs(x-y);
	double ans=sqrt(a*a+b*b-2*a*b*cos(z));
	printf("%.20f\n",ans);
	return 0;
} 

Measured memory_bytes: 3508
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

O=get_nsp
E=get_nsp
i=0
ans=""
N=E.size>O.size ? E.size : O.size
while i<N
  ans+=O[i] if i<O.size
  ans+=E[i] if i<E.size
  i+=1
end
puts ans

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

bool compare(pair<pair<string, int>, int> a, pair<pair<string, int>, int> b) {
  if (a.first.first != b.first.first) {
    return a.first.first < b.first.first;
  } else {
    return a.first.second > b.first.second;
  }
}

int main() {
  int N;
  cin >> N;
  vector<pair<pair<string, int>, int>>  sp(N);
  for (int i=0; i<N; i++) {
    string city;
    int score;
    cin >> city >> score;
    sp[i] = make_pair(make_pair(city, score), i+1);
  }
  sort(sp.begin(), sp.end(), compare);

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

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int a = Integer.parseInt(s.substring(0,1));
      int b = Integer.parseInt(s.substring(1,2));
      int c = Integer.parseInt(s.substring(2,3));
      int d = Integer.parseInt(s.substring(3,4));
      int x1 = a+b+c+d;
      int x2 = a-b+c+d;
      int x3 = a+b-c+d;
      int x4 = a+b+c-d;
      int x5 = a-b-c+d;
      int x6 = a-b+c-d;
      int x7 = a+b-c-d;
      int x8 = a-b-c-d;
      String aa = String.valueOf(a);
      String bb = String.valueOf(b);
      String cc  =String.valueOf(c);
      String dd = String.valueOf(d);
      if(x1==7) System.out.println(aa+"+"+bb+"+"+cc+"+"+dd+"=7");
      else if (x2==7) System.out.println(aa+"-"+bb+"+"+cc+"+"+dd+"=7");
      else if (x3==7) System.out.println(aa+"+"+bb+"-"+cc+"+"+dd+"=7");
      else if (x4==7) System.out.println(aa+"+"+bb+"+"+cc+"-"+dd+"=7");
      else if (x5==7) System.out.println(aa+"-"+bb+"-"+cc+"+"+dd+"=7");
      else if (x6==7) System.out.println(aa+"-"+bb+"+"+cc+"-"+dd+"=7");
      else if (x7==7) System.out.println(aa+"+"+bb+"-"+cc+"-"+dd+"=7");
      else if (x8==7) System.out.println(aa+"-"+bb+"-"+cc+"-"+dd+"=7");
    }
}

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

int main()
{
  int x, n ;
  cin >> x >> n ;
  vector<int> p(n) ;

  for (int i = 0; i < n; i++) {
    int d ;
    cin >> d ;
    p.at(i) = d - x ;
  }

  vector<int> a(200) ;
  a.at(0) = 0 ;
  for (int i = 1; i < 100 ; i++) {
    a.at(2 * i -1 ) = (-1) * i ;
    a.at(2 * i ) = i ;
  }

  for (int i = 0; i < n ; i++) {
    if ( p.at(i) == 0 ) {
      a.at(0) = 101 ;
    }else if ( p.at(i) < 0 ) {
      a.at( (-2)* p.at(i) - 1 ) = 101 ;
    }else {
      a.at( p.at(i) * 2 ) = 101 ;
    }
  }

  for (int i = 0; i < 200 ; i++) {
    if ( a.at(i) != 101 ) {
      cout << a.at(i) + x << endl ;
      break ;
    }
  }
  return 0 ;
}


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

using namespace std;
#define local
#ifdef local

template<class T>
void _E(T x) { cerr << x; }

void _E(double x) { cerr << fixed << setprecision(6) << x; }

void _E(string s) { cerr << "\"" << s << "\""; }

template<class A, class B>
void _E(pair<A, B> x) {
    cerr << '(';
    _E(x.first);
    cerr << ", ";
    _E(x.second);
    cerr << ")";
}

template<class T>
void _E(vector<T> x) {
    cerr << "[";
    for (auto it = x.begin(); it != x.end(); ++it) {
        if (it != x.begin()) cerr << ", ";
        _E(*it);
    }
    cerr << "]";
}

void ERR() {}

template<class A, class... B>
void ERR(A x, B... y) {
    _E(x);
    cerr << (sizeof...(y) ? ", " : " ");
    ERR(y...);
}

#define debug(x...) do { cerr << "{ "#x" } -> { "; ERR(x); cerr << "}" << endl; } while(false)
#else
#define debug(...) 114514.1919810
#endif
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f3f3f
#define ll long long
#define db long double
#define eps 1e-3
#define bin(x) cerr << bitset<10>(x) << endl
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define endl "\n"
const ll mod = 1e9 + 7;
const ll maxn = 2e4 + 10;
const db pi = acos(-1.0);
ll qpow(ll a, ll b) {
    ll ret = 1;
    for (; b; a = a * a % mod, b >>= 1) {
        if (b & 1) {
            ret = ret * a % mod;
        }
    }
    return ret;
}

vector<ll> f(maxn), invf(maxn);

ll inv(ll a) {
    return qpow(a, mod - 2);
}

void prework() {
    f[0] = 1;
    _rep(i, 1, maxn - 1) {
        f[i] = f[i - 1] * i % mod;
    }
    invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
    for (ll i = maxn - 2; i >= 0; i--) {
        invf[i] = invf[i + 1] * (i + 1) % mod;
    }
}

ll C(ll n, ll m) {
    if (n > m || m < 0)return 0;
    if (n == 0 || m == n) return 1;
    ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
    return res;
}

string a[maxn];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    ll res = t.size();
    _rep(i, 0, s.size() - t.size()){
        ll diff = 0;
        _for(j, 0, t.size()){
            if(s[i+j] != t[j]){
                diff++;
            }
        }
        res = min(res, diff);
    }
    cout << res << endl;
}

Measured memory_bytes: 4252
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;


bool is_ok(int64 N,int64 K){
    // debug("A")
    // debug(mp(N,K))
    while(N%K==0){
        N/=K;
    }
    // debug(mp(N,K))
    return N%K==1;
}

//約数列挙
vector<int64> divs(int64 n){
    int64 copy = n;
    vector<int64> res;
    for(int64 i=1;i*i<=copy;i++){
        if(n%i==0){
            res.push_back(i);
            if(i*i!=n) res.push_back(n/i);
        }
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 N;
    cin >> N;
    int ans = 0;
    bool add_one = true;
    set<int64> exist;
    for(int64 K=2;K*K<=N;K++){
    // for(int64 K=2;K<=N;K++){
        if(is_ok(N,K)){
            ans++;
            // debug(K)
            exist.insert(K);
        }
    }

    auto div = divs(N-1);
    for(auto d:div){
        if(d!=1 and exist.find(d) == exist.end() ){
            // debug(d)
            ans++;
        }
    }


    cout << ans+1 << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;

struct Stack{
	ll value[200];
	int t=0;
	void emplace(ll x){
		value[t++]=x;
	}
	void pop(){
		value[--t]=0;
	}
	ll top(){
		return value[t-1];
	}
};

int main(){
	vector<string> v;
	string str;
	while(cin>>str){
		v.emplace_back(str);
	}
	
	Stack stk;
	for(int i=0;i<(int)v.size();++i){
		if(v[i]=="+"||v[i]=="-"||v[i]=="*"){
			ll r=stk.top(); stk.pop();
			ll l=stk.top(); stk.pop();
			if(v[i]=="+") stk.emplace(l+r);
			if(v[i]=="-") stk.emplace(l-r);
			if(v[i]=="*") stk.emplace(l*r);
		}else{
			ll num=stoll(v[i]);
			stk.emplace(num);
		}
	}
	
	cout<<stk.top()<<endl;
}



Measured memory_bytes: 3168
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std; 
int main()
{
	int a[110];
	int flag,k;
	memset(a,0,sizeof(a));
	while(cin>>a[1])
	{
		flag=0;
		for(int i=2;;i++)
		{
			if(a[i-1]%2)
			a[i]=3*a[i-1]+1;
			else
			a[i]=a[i-1]/2;
			if(i%10==0)
			cout<<endl;
			for(int j=i-1;j>=1;j--)
			{
				if(a[i]==a[j])
				{
					k=i;
					flag=1;
					break;
				}
			}
			if(flag)
			break;
		}
		cout<<k<<endl;
	}
	return 0;
}

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

int main(){
  int tate, yoko;
  cin >> tate >> yoko;
  string picture;
  for(int t = 0;t < yoko + 2;t++){
    cout << "#";
  }
  cout << endl;
  for(int t = 0;t < tate;t++){
    cout << "#";
    cin >> picture;
    cout << picture << "#" << endl;
  }
  for(int t = 0;t < yoko + 2;t++){
    cout << "#";
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,K,L;
double T,U,V;
bool getca[10500];
const int INF=1e9;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}
int main()
{
  cin >> N >> K >> T >> U >> V >> L;
  memset(getca,false,sizeof(getca));
  for (int i = 0; i <N; i++)
  {
      int c;
      cin >> c;
      getca[c]=true;
  }
  int pos=0;
  int carrot=0;
  double time=0.0;
  double speedup=0;
  while(pos<L)
  {
      pos++;
      if(speedup>1e-9) time+=1.0/V;
      else time+=1.0/U;
      if(speedup>1e-9) speedup-=(1.0/V);
      if(carrot>0 && speedup<1e-9) 
      {
          carrot--;
          speedup=T;
      }
      if(getca[pos])
      {
          if(speedup<1e-9 || carrot==K) speedup=T;
          else carrot++;
      }
      //cout << pos << ' ' << time << ' ' << speedup << endl;
  }
  cout << fixed << setprecision(9) << time << endl;
  return 0;
}



Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
const int N = 55555;
bitset<5*N+1> vis;
vector<int> p, s[5];
int n,v[55];
void pre()
{
    vis[0] = vis[1] = 1;
    for (int i = 2; i * i <= 5 * N; ++i)
        for (int j = i * i; j <= N; j += i)
            vis[j] = 1;
    for (int i = 2; i <= N; ++i)
        if (!vis[i])
            p.push_back(i);
    for (int x : p)
        s[x % 5].push_back(x);
    for (int i = 0; i < 5; ++i)
        cerr << s[i].size() << endl;
}
void dfs(int i,int j)
{
    if (i == n) {
        for (int k = 0; k < n; ++k)
            cout << v[k] << " \n"[k == n- 1];
        exit(0);
    }
    for (; j < p.size(); ++j) {
        bool ok = 1;
        for (int a = 0; a + 3 < i && ok; ++a)
            for (int b = a + 1; b + 2 < i && ok; ++b)
                for (int c = b + 1; c + 1 < i && ok; ++c)
                    for (int d = c + 1; d < i && ok; ++d)
                        ok = ok && vis[v[a] + v[b] + v[c] + v[d] + p[j]];
        if (ok) {
            v[i] = p[j];
            dfs(i+1,j+1);
        }
    }
}
int main()
{
    pre();
    cin >> n;
    for (int i = 0; i < n; ++i)
        cout << s[1][i] << " \n"[i == n - 1];
}


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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int d =a-b;
  if(d>=c) cout<<0<<endl;
  else cout<<c-d<<endl;
}

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

typedef long long int ll;

const int MAX_N = 100001;
ll _data[MAX_N];

int main(){
  for(int i = 0 ; i < MAX_N ; i++){
    _data[i] = 0;
  }

  ll N, sum;
  cin >> N;
  sum = 0;
  for(int i = 0 ; i < N ; i++){
    ll a; cin >> a;
    _data[a]++;
    sum += a;
  }
  ll Q;
  cin >> Q;
  for(int i = 0 ; i < Q ; i++){
    ll b,c;
    cin >> b >> c;
    sum += -1 * _data[b]*b + _data[b]*c;
    _data[c] += _data[b];
    _data[b] = 0;
    cout << sum << endl;
  }
  return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

void arrange(string& a, string& b) {
	reverse(ALL(a));
	reverse(ALL(b));
	
	int ma = max(a.size(), b.size());
	
	while (a.size() < ma) a += "0";
	while (b.size() < ma) b += "0";
	
	reverse(ALL(a));
	reverse(ALL(b));
}

int main() {
	string a, b;
	cin >> a >> b;
	
	arrange(a, b);
	
	if (a < b) puts("LESS");
	if (a > b) puts("GREATER");
	if (a == b) puts("EQUAL");
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int[] numArray = parseInt(getSplitLine(line));

        int x;
        int y;
        if (numArray[0] > numArray[1]) {
            x = numArray[0];
            y = numArray[1];
        } else {
            x = numArray[1];
            y = numArray[0];
        }

//計算
        int tmp;
        while ((tmp = x % y) != 0) {
            x = y;
            y = tmp;
        }

        System.out.println(y);
    }

    private static String[] getSplitLine(String line) {
        return line.split("\\s");
    }

    private static int[] parseInt(String[] line) {
        int[] numArray = new int[line.length];
        for (int i = 0; i < line.length; i++) {
            numArray[i] = Integer.parseInt(line[i]);
        }
        return numArray;
    }
}


Measured memory_bytes: 24368
#include <vector>
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;

unordered_set<char> m;

int main(void)
{
	string s;
	ll k;
	cin >> s;
	cin >> k;

	for (auto c : s) {
		m.insert(c);
	}
	if (m.size() == 1) {
		cout << (s.size() * k) / 2 << endl;
		return 0;
	}
	if (s[0] != s.back()) {
		char p = 0;
		int t = 0;
		int sum = 0;
		for (int i = 0; i < s.size(); i++) {
			if (p != s[i]) {
				sum += t / 2;
				p = s[i];
				t = 1;
			}
			else{
				t++;
			}
		}
		sum += t / 2;
		cout << sum * k << endl;
		return 0;
	}
	else {
		char f = s[0];
		ll a = 0;
		ll c = 0;
		for (int i = 0; i < s.size(); i++) {
			if (f != s[i]) {
				c = i;
				break;
			}
			else {
				a++;
			}
		}
		ll d = 0;
		ll b = 0;
		for (int i = s.size() - 1; i >= 0; i--) {
			if (f != s[i]) {
				d = i+1;
				break;
			}
			else {
				b++;
			}
		}
		char p = 0;
		ll t = 0;
		ll sum = 0;
		for (int i = c; i < d; i++) {
			if (p != s[i]) {
				sum += t / 2;
				p = s[i];
				t = 1;
			}
			else {
				t++;
			}
		}
		sum += t / 2;
		ll tSum = a / 2 + b / 2 + (a + b) / 2 * (k - 1);
		tSum += sum * k;
		cout << tSum << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<P> g[100000];
int d[100000];
int p[17][100000];
bool used[100000];
void dfs0(int x){
	used[x]=1;
	for(auto pr:g[x]){
        int y=pr.first;
		if(!used[y]){
			d[y]=d[x]+1;
			p[0][y]=x;
			dfs0(y);
		}
	}
}
void init_lca(){
    dfs0(0);
	for(int i=1; i<17; i++){
        for(int x=0; x<n; x++){
            p[i][x]=p[i-1][p[i-1][x]];
        }
    }
}
int lca(int a, int b){
    if(d[a]>d[b]) swap(a, b);
    int a1=a, b1=b;
    int dd=d[b]-d[a], i=0;
    while(dd>0){
        if(dd%2==1){
            b1=p[i][b1];
        }
        dd/=2;
        i++;
    }
    if(a1==b1) return a1;
    for(int i=16; i>=0; i--){
        if(p[i][a1]!=p[i][b1]){
            a1=p[i][a1], b1=p[i][b1];
        }
    }
    return p[0][a1];
}
vector<int> v[100010];
vector<int> vm[100010];
int c[100010]; ll dist[100010];
int cx[100010]; ll y[100010];
ll cnt[100010], dc[100010], ds;
ll ans[100010];
void dfs(int x){
    used[x]=1;
    for(auto i:v[x]){
        ans[i]+=(ds-dc[cx[i]]+cnt[cx[i]]*y[i]);
    }
    for(auto i:vm[x]){
        ans[i]-=2*(ds-dc[cx[i]]+cnt[cx[i]]*y[i]);
    }
    for(auto pr:g[x]){
        int y=pr.first;
        if(used[y]) continue;
        int i=pr.second;
        cnt[c[i]]++;
        dc[c[i]]+=dist[i];
        ds+=dist[i];
        dfs(y);
        cnt[c[i]]--;
        dc[c[i]]-=dist[i];
        ds-=dist[i];
    }
}
int main()
{
    int q;
    cin>>n>>q;
    for(int i=0; i<n-1; i++){
      int a, b;
        cin>>a>>b>>c[i]>>dist[i];
        a--; b--;
        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }
    init_lca();
    for(int i=0; i<q; i++){
        int ui, vi; cin>>cx[i]>>y[i]>>ui>>vi;
        ui--; vi--;
        v[ui].push_back(i);
        v[vi].push_back(i);
        vm[lca(ui, vi)].push_back(i);
    }
    fill(used, used+n, 0);
    dfs(0);
    for(int i=0; i<q; i++) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 30588
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>

using namespace std;

long long int A, a, n, m, y, s;
string str_1, str_2, str_3;
long long int x[2][30000];


int gcd(int m, int n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	// ユークリッドの方法
	while (m != n)
	{
		if (m > n) m = m - n;
		else         n = n - m;
	}
	return m;
}
int lcm(int m, int n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}


int main() {
	cin >> n >> m;
	cin >> str_1 >> str_2;

	for (int i = 0; i < gcd(n, m); i++) {
		if (str_1[i*n / gcd(n, m)] != str_2[i*m / gcd(n, m)]) {
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << n * m / gcd(n, m) << '\n';
	return 0;
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int K;
    cin>>K;
    vector<string> a(100005,string(11,0));
    for(int i=1;i<=9;i++) a[i][0]=i+'0';
    for(int i=10;i<=K;i++){
        a[i]=a[i-1];
        int k=0;
        while(a[i][k]!=0&&((a[i][k+1]!=0&&a[i][k]>a[i][k+1])||a[i][k]=='9')) k++;
        if(a[i][k]==0){
            a[i][k]='1';
            for(k--;k>=0;k--) a[i][k]='0';
        }else{
            a[i][k]+=1;
            for(k--;k>=0;k--) a[i][k]=max(char(a[i][k+1]-1),'0');
        }
    }
    ford(i,a[K].size()){
        if(a[K][i]!=0) cout<<a[K][i];
    }
    return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
 int a,b,c,res; cin>>a>>b>>c;
 res=c-(a-b);
 if(res<0)res=0;
 cout<<res<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<algorithm>
#define N 1100
#define INF 2<<30
using namespace std;
map<string,int>mp;
void bfs()
{
    int p;
    mp.clear();
    string ss="01234567";
    queue<string>q;
    int dir[4]= {1,-1,4,-4};
    q.push(ss);
    mp[ss]=0;
    while(!q.empty())
    {
        string now=q.front();
        q.pop();
        for(int i=0; i<8; i++)
        {
            if(now[i]=='0')
            {
                p=i;
                break;
            }
        }
        for(int k=0; k<=3; k++)
        {
            int tx=p+dir[k];
            if((k==1&&p==4)||(k==0&&p==3))
                continue;
            string next=now;
            if(tx>=0&&tx<8)
            {
                swap(next[tx],next[p]);
                if(mp[next]==0)
                {
                    mp[next]=mp[now]+1;
                    q.push(next);
                }
            }
        }
    }
}
int main()
{
    string s,str;
    bfs();
    while(getline(cin,s))
    {
        str.clear();
        for(int i=0; i<s.length(); i++)
        {
            if(s[i]!=' ')
                str=str+s[i];
        }
        cout<<mp[str]<<endl;
    }
    return 0;
}

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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




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

    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

if n == 1:
    print(a[0] + b[0])
    exit()

ans = sum(b) + a[0]
temp = ans

for i in range(1, n):
    temp += a[i]
    temp -= b[i - 1]
    ans = max(temp, ans)

print(ans)

Measured memory_bytes: 3064
n=int(input())
#m=int(input())
#r=[input() for _ in range(n)]
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    left=min(a[i],b[i])
    ans+=left
    a[i]-=left
    b[i]-=left
    right=min(a[i+1],b[i])
    ans+=right
    a[i+1]-=right
    b[i]-=right
print(ans)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    rep (i, s.size()) cout << "x";
    cout << endl;

    return 0;
}



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

import sys
import os

scores = [0]

for s in sys.stdin:
    p, s = map(int, s.split(','))
    if p == s == 0:
        break
    else:
        scores.append(s)

score_set = set(scores)
score_set = list(score_set)
score_set.sort(reverse=True)

for s in sys.stdin:
    n = int(s)

    teams_score = scores[n]
    print(score_set.index(teams_score) + 1)

Measured memory_bytes: 7524
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


# 豎守畑迚・ edge縺ｯN*N縺ｮ2谺｡蜈・・蛻・ cap縺ｧ騾溘￥縺ｪ縺｣縺・
class Flow():
    def __init__(self, e, N):
        self.E = e
        self.N = N

    def max_flow(self, s, t):
        r = 0
        e = self.E

        def f(c, cap):
            v = self.v
            v[c] = 1
            if c == t:
                return cap
            for i in range(self.N):
                if v[i] or e[c][i] <= 0:
                    continue
                cp = min(cap, e[c][i])
                k = f(i, cp)
                if k > 0:
                    e[c][i] -= k
                    e[i][c] += k
                    return k
            return 0

        while True:
            self.v = [None] * self.N
            fs = f(s, inf)
            if fs == 0:
                break
            r += fs

        return r

def main():
    n,m = LI()
    aa = [LI() for _ in range(m)]

    e = [[0] * n for _ in range(n)]
    for a,b,c in aa:
        e[a][b] = c

    fl = Flow(e, n)
    r = fl.max_flow(0, n-1)

    return r

# start = time.time()
print(main())
# pe(time.time() - start)






Measured memory_bytes: 9212
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int[] Alph = new int[26];

   for(int j = 0; j < 26; j++){
	   Alph[j] = 0;
   }

 while(true){
	 String line = br.readLine();
	 if(line == null ) break;

	 String[] token = line.split("");
	 for (int i = 0; i < token.length; i++){
		   String str = token[i].toLowerCase();

		   for(char ch:  str.toCharArray()){
		     if(Character.isLetter(ch)){
			   Alph[ch - 'a'] ++;
		     }
		   }
	   }

 }

   for(int i = 0; i<26 ; i++){
	   System.out.println( (char)('a'+i) + " : " + Alph[i] );
   }



  }
}

Measured memory_bytes: 25376
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  int count = 0;
  string s;
  cin >> s;
  
  for(int i = 0; i < 3; i++)
  {
    for(int j = 0; j < 3; j++)
    {
      if(s[i] == s[j])
      {
        count++;
      }
    }
  }
  
  if(count > s.size())
  {
    cout << "No";
  }
  else
  {
    cout << "Yes";
  }
}

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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

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

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a = b; return true;} return false; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    string s; cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m,a[100001],kyori[100001],sum,i,x,ima;
	cin>>n>>m;
	for(i=1;i<n;i++) cin>>a[i];
	for(i=0;i<=n;i++) kyori[i]=0;
	ima=1;
	for(i=0;i<m;i++){
		cin>>x;
		if(x>=0){
			kyori[ima]++;
			ima=ima+x;
			kyori[ima]--;
		}
		else{
			kyori[ima]--;
			ima=ima+x;
			kyori[ima]++;
		}
	}
	for(i=1;i<=n;i++) kyori[i]=kyori[i]+kyori[i-1];
	sum=0;
	for(i=1;i<n;i++)sum=(sum+kyori[i]*a[i])%100000;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3864
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;


ll ans,mx,mn,sum;
int main(){
	string s;
	cin>>s;
	if(s[0]=='a'||s[0]=='e'||s[0]=='i'||s[0]=='o'||s[0]=='u'){
		cout<<"vowel";
	}
	else cout<<"consonant";
}

Measured memory_bytes: 256
table = ('a'..'z').to_a

while line = gets
  encoded = line.chomp.split('')
  for i in 0...table.size do
    decoded = ''
    for j in 0...encoded.size do
      index = table.index(encoded[j])
      if index
        decoded += table[(index + i) % (table.size)]
      else
        decoded += encoded[j]
      end
    end

    if decoded =~ /\b(the|this|that)\b/
      puts decoded
      break
    end
  end
end

Measured memory_bytes: 8792
#include <bits/stdc++.h>
#define ll long long
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb(x) push_back(x)
#define F first
#define S second
#define mp(x,y) make_pair(x,y)
using namespace std;


void solve(){
	int n,k;
	cin>>n;
	cin>>k;
	vector<int> v(n);
	for(int &i:v){
		cin>>i;
	}
	/*
	for(auto x:v){
		cout<<x<<"  ";
	}
	cout<<endl;*/                                                                
	vector<int> dp(n);
	dp[0]=0;
	loop(i,1,n){
		int j=1;
		int ans=INT_MAX;
		while(i-j>=0 && j<k+1){
		    ans=min(ans,dp[i-j]+abs(v[i]-v[i-j]));
		    j++;
		}
		dp[i]=ans;
	}
	cout<<dp[n-1]<<endl;
	return;
}       


int main(){
	ios_base::sync_with_stdio(false);
        cin.tie(NULL);
      //  freopen("input.txt","r",stdin);

	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 1024
S = input()
if S[0] == "A":
    cnt = 0
    for i in range(2,len(S)-1):
        if S[i] == "C":
            cnt += 1
    if cnt == 1:
        S = S.replace("A","").replace("C","")
        cnt2 = 0
        for i in range(len(S)):
            if S[i].islower():
                cnt2 += 1
        if cnt2 == len(S):
            print("AC")
            exit()

print("WA")

Measured memory_bytes: 3064
N, M = map(int, input().split())
P_Y = {i: list(map(int, input().split())) for i in range(M)}
P_city = [0] * N
P_res = [None] * M

for i, (p, y) in sorted(P_Y.items(), key=lambda x: x[1][1]):
    P_city[p-1] += 1
    P_res[i] = (p, P_city[p-1])

for p, y in P_res:
    print("{0:06d}{1:06d}".format(p, y))

Measured memory_bytes: 56956
#include <bits/stdc++.h>
using namespace std;
int main(){
  int R, C, K;
  cin >> R >> C >> K;
  vector<int> r(K), c(K), v(K);
  for (int i = 0; i < K; i++){
    cin >> r[i] >> c[i] >> v[i];
    r[i]--;
    c[i]--;
  }
  vector<vector<int>> value(R, vector<int>(C, 0));
  for (int i = 0; i < K; i++){
    value[r[i]][c[i]] = v[i];
  }
  vector<vector<vector<long long>>> dp(R, vector<vector<long long>>(C, vector<long long>(4, 0)));
  if (value[0][0] != 0){
    dp[0][0][1] = value[0][0];
  }
  for (int i = 0; i < R; i++){
    for (int j = 0; j < C; j++){
      if (i > 0){
        for (int k = 0; k < 4; k++){
          dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k]);
        }
        if (value[i][j] != 0){
          dp[i][j][1] = max(dp[i][j][1], dp[i][j][0] + value[i][j]);
        }
      }
      if (j > 0){
        for (int k = 0; k < 4; k++){
          dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
          if (value[i][j] != 0 && k < 3){
            dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j - 1][k] + value[i][j]);
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 4; i++){
    ans = max(ans, dp[R - 1][C - 1][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 673284
#include <stdio.h>
int a,b;

int main()
{
	scanf("%d %d",&a,&b);
	if(a>12){
		printf("%d",b);
		return 0;
	}
	else if(a>=6 && a<=12){
		printf("%d",b/2);
		return 0;
	}
	else printf("0");
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<string>
#include<iostream>

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

using namespace std;

int main(){
	while(1){
		string s,tmp;
		while(1){
			getline(cin,tmp);
			if(tmp=="") break;
			s+=tmp;
		}
		string a; getline(cin,a);
		getline(cin,tmp);
		if(a=="") break;

		int m=a.length();
		bool b[128]={};
		rep(i,m) b[a[i]]=true;

		int n=s.length();
		int j_ans,w_ans=2*n,c_ans=0;
		int cnt[128]={},cnt2=0;
		for(int i=0,j=0;i<n;i++){
			if(cnt[s[i]]==0 && b[s[i]]) cnt2++;
			cnt[s[i]]++;

			if(cnt2==m){
				while(j<i && cnt[s[j]]>1 || cnt[s[j]]==1 && !b[s[j]]){
					cnt[s[j]]--;
					j++;
				}
				if(i-j+1<w_ans){
					j_ans=j;
					w_ans=i-j+1;
					c_ans=1;
				}
				else if(i-j+1==w_ans){
					c_ans++;
				}
			}
		}

		cout<<c_ans<<endl<<endl;
		if(c_ans>0){
			string ans=s.substr(j_ans,w_ans);
			for(int i=0;i<w_ans;i+=72){
				for(int j=i;j<min(i+72,w_ans);j++) cout<<ans[j];
				cout<<endl;
			}
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#define CLR(array) memset( array, 0, sizeof array )
typedef long long int ll;
using namespace std;

#define MAXH (20+5)
#define MAXW (20+5)

struct node{
	int y,x; int dist;
	node() {}
	node( int _y, int _x, int _d ) : y(_y),x(_x),dist(_d) {}
};

int h,w;
char maze[MAXH][MAXW];
char vis[MAXH][MAXW];
int dirx[4] = { 0, 1, 0, -1 };
int diry[4] = { 1, 0, -1, 0 };

ll BFS( int y, int x ){
	queue<node> q;
	node t,start;
	CLR(vis);

	start = node( y, x, 0 );
	q.push(start);
	vis[y][x] = 1;

	ll res = 0;
	while( !q.empty() ){
		start = q.front();
		q.pop();

		// printf("%d %d: %d\n", start.y, start.x, start.dist );

		res = start.dist;
		t.dist = start.dist + 1;

		for( int i = 0; i < 4; i++ ){
			t.y = start.y + diry[i];
			t.x = start.x + dirx[i];
			if( t.y < 0 || t.y >= h )	continue;
			if( t.x < 0 || t.x >= w )	continue;
			if( maze[t.y][t.x] == '#' )	continue;
			if( vis[t.y][t.x] )			continue;

			vis[t.y][t.x] = 1;
			q.push(t);
		}
	}

	return res;
}

int main(){

	cin >> h >> w;
	for( int i = 0; i < h; i++ )
		cin >> maze[i];

	ll res = 0;
	int t;
	for( int i = 0; i < h; i++ ){
		for( int j = 0; j < w; j++ ){
			if( maze[i][j] != '#' ){
				res = max( res, BFS(i,j) );
			}
			
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n; cin >> n;
  vector<pair<ll,ll>> robots(n);
  rep(i,n) {
    ll x,l; cin >> x>>l;
    robots[i] = pair<ll,ll>(x,l);
  }
  sort(robots.begin(), robots.end(), [](pair<ll,ll> a, pair<ll,ll> b) { return (a.first+a.second < b.first + b.second);});
  ll rightMost = robots[0].first + robots[0].second;
  int ans =1;

  for (int i=1; i<n; i++) {
    if (rightMost <= robots[i].first-robots[i].second) {
      rightMost = robots[i].first + robots[i].second;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int h, w, m;
    cin >> h >> w >> m;
    map<int, int> mpRow, mpCol;
    set<P> target;
    rep(i,m){
        int hi, wi;
        cin >> hi >> wi;
        hi--; wi--;
        mpCol[wi]++;
        mpRow[hi]++;
        target.insert(make_pair(hi, wi));
    }
    int mxRowCnt = 0, mxColCnt = 0;
    for(auto mp : mpRow) mxRowCnt = max(mxRowCnt, mp.second);
    for(auto mp : mpCol) mxColCnt = max(mxColCnt, mp.second);
    set<int> stRow, stCol;
    for(auto mp : mpRow) if (mxRowCnt == mp.second) stRow.insert(mp.first);
    for(auto mp : mpCol) if (mxColCnt == mp.second) stCol.insert(mp.first);
    int ans = mxRowCnt + mxColCnt;
    bool ok = false;
    for(int sr : stRow){
        for(int sc: stCol){
            if (target.find(make_pair(sr, sc)) == target.end()){
                ok = true;
                break;
            }
        }
    }
    if (ok) cout << ans << endl;
    else cout << ans-1 << endl;
    return 0;
}

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

using namespace std;

#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");

typedef long long i64;
const int nmax = 700;

bool ok;
bool viz[nmax + 1];

int albe, negre;
int col[nmax + 1];
vector<int> g[nmax + 1];
int e[nmax + 1][nmax + 1];

bool d[nmax + 1][nmax + 1];

void dfs (int nod, int x) {
    col[nod] = x;
    viz[nod] = 1;

    if (x == 0)
        ++ albe;
    else
        ++ negre;

    for (auto i : g[nod]) {
        if (viz[i] == 0) {
            dfs(i, x ^ 1);
        } else if (col[i] != (x ^ 1)) {
            ok = 0;
        }
    }
}

int main() {
    fin.sync_with_stdio(false); fin.tie(); fout.tie();

    int n, m;
    fin >> n >> m;

    for (int i = 1; i <= m; ++ i) {
        int x, y;
        fin >> x >> y;
        e[x][y] = 1;
        e[y][x] = 1;
    }

    for (int i = 1; i <= n; ++ i) {
        for (int j = i + 1; j <= n; ++ j) {
            if (e[i][j] == 0) {
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }

    ok = 1;
    vector<pair<int, int>> v;
    v.push_back({0, 0});
    for (int i = 1; i <= n; ++ i) {
        if (viz[i] == 0) {
            albe = negre = 0;
            dfs(i, 0);

            v.push_back({albe, negre});
        }
    }

    if (ok == 0) {
        fout << "-1\n";
        return 0;
    }

    d[0][0] = 1;

    int s = 0;

    for (int i = 1; i < (int)v.size(); ++ i) {
        s += v[i].first + v[i].second;
        for (int j = v[i].first; j <= s; ++ j) {
            d[i][j] |= d[i - 1][j - v[i].first];
        }

        for (int j = v[i].second; j <= s; ++ j) {
            d[i][j] |= d[i - 1][j - v[i].second];
        }
    }

    int k = (int)v.size() - 1;
    int ans = 1 << 30;
    for (int i = 0; i <= n; ++ i) {
        if (d[k][i] == 1) {
            ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
    }

    fout << ans << "\n";
    return 0;
}


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

    class Program
    {
        static void Main(string[] args)
        {
            string[] strInputArray;
            List<string> inputList = new List<string>();
            int a = 0;
            int b = 0;
            string op = "";
            do
            {
                strInputArray = Console.ReadLine().Split(' ');
                if (!strInputArray[1].Equals("?"))
                {
                    inputList.Add(strInputArray[0]);
                    inputList.Add(strInputArray[1]);
                    inputList.Add(strInputArray[2]);
                }
            } while (!strInputArray[1].Equals("?"));


            for (int i = 1; i <= (inputList.Count / 3); i++)
            {
                a = int.Parse(inputList[(i * 3) - 3]);
                op = inputList[(i * 3) - 2];
                b = int.Parse(inputList[(i * 3) - 1]);
                if (op.Equals("+"))
                {
                    Console.WriteLine(a + b);
                }
                if (op.Equals("-"))
                {
                    Console.WriteLine(a - b);
                }
                if (op.Equals("*"))
                {
                    Console.WriteLine(a * b);
                }
                if (op.Equals("/"))
                {
                    Console.WriteLine(a / b);
                }
            }
            Console.ReadLine();
        }
    }


Measured memory_bytes: 15972
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,k,i,j,srx[200001],sry,t,p;
int main(){
   scanf("%d%d",&n,&k);
   for(i=1;i<=n;++i){
   scanf("%d",&t);
   srx[t]++;
   } 
   sort(srx+1,srx+n+1);
   for(i=n;i>n-k;--i) 
   sry+=srx[i]; 
   printf("%d",n-sry); 
   return 0;
}

Measured memory_bytes: 896
n = int(input())
a = input().split()
a.sort()
# print(a)

max_x = 10 ** 18

result = 1
for x in a:
    result *= int(x)
    if result == 0 or result > max_x:
        break

if result > max_x:
    print(-1)
else:
    print(result)

Measured memory_bytes: 19484
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long ans = A - B;
  if (K % 2 == 1)
    ans *= -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;

int main() {
  // 標準入力が早くなる。Cスタイルの入出力とC++スタイルの入出力を混合させてはならない。
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int a, b;

  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


Measured memory_bytes: 3632
# ABC104D

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))

M = 10**9+7
s = input()
n = len(s)
anum = [None] * n # s[:i+1]のAの数
cnum = [None] * n # s[i+1:]のCの数
hnum1 = [None] * n
hnum2 = [None] * n
acount = 0
ccount = 0
hcount1 = 0
hcount2 = 0
for i,(c,cc) in enumerate(zip(s, s[::-1])):
    if c in "A":
        acount += 1
    if c=="?":
        hcount1 += 1
    anum[i] = acount
    hnum1[i] = hcount1
    if cc in "C":
        ccount += 1
    if cc=="?":
        hcount2 += 1
    cnum[-(i+1)] = ccount
    hnum2[-(i+1)] = hcount2
ans = 0
hn = hnum1[-1]
for i,c in enumerate(s):
    if i in (0, n-1):
        continue
    if c=="B":
        ans += (anum[i-1]*cnum[i+1]*pow(3, hn, M))
        if hn>=1:
            ans += (anum[i-1]*hnum2[i+1]*pow(3, hn-1, M))
            ans += (hnum1[i-1]*cnum[i+1]*pow(3, hn-1, M))
        if hn>=2:
            ans += (hnum1[i-1]*hnum2[i+1]*pow(3, hn-2, M))
    if c=="?":
        ans += (anum[i-1]*cnum[i+1]*pow(3, hn-1, M))
        if hn>=2:
            ans += (anum[i-1]*(hnum2[i+1])*pow(3, hn-2, M))
            ans += (hnum1[i-1]*cnum[i+1]*pow(3, hn-2, M))
        if hn>=3:
            ans += (hnum1[i-1]*hnum2[i+1]*pow(3, hn-3, M))
    ans %= M
#     print(ans)
print(ans)

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

#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;

const ll mod = 1000000007;
ll po(ll k, ll n ){ 
      if(n==1) return k%mod;
      else{
        ll a=po(k,n/2)%mod;
        if(n%2==0) return (a*a)%mod;
        else return (((a*a)%mod)*k)%mod;
      }
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r" , stdin);
  // freopen("output.txt", "w" , stdout);
  //#endif
  int t=1;
  //cin >> t;
  while(t--){
    int n;
    cin >> n;
    string s;
    cin >> s;
    char x;
    int i=0, c=0;
    while(i<n){
      x=s[i];
      c++;
      while(s[i]==x && i<n) i++;
    }
    cout << c << endl;

  }

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[214514];
int main(){
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		ll a;
		cin>>a;
		if(i%2&&a%2)ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3576