akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p; //後半は0で増加・1で平坦・2で減少
 
struct pos{
  vector<ll> points[3];
  void add_point(p point){
    points[point.second].push_back(point.first);
  }
  void points_sort(){
    REP(i,3) sort(points[i].begin(),points[i].end());
  }
  vector<double> times(){
    points_sort();
    vector<double> res;
    res.push_back(0);
    if(!points[0].empty()&&!points[1].empty()&&(points[0].front()<points[1].front()))
    res.push_back(points[1].front()-points[0].front());
    if(!points[1].empty()&&!points[2].empty()&&(points[1].front()<points[2].front()))
    res.push_back(points[2].front()-points[1].front());
    if(!points[0].empty()&&!points[2].empty()&&(points[0].front()<points[2].front()))
    res.push_back((points[2].front()-points[0].front())*1.0/2);
    if(!points[0].empty()&&!points[1].empty()&&(points[0].back()<points[1].back()))
    res.push_back(points[1].back()-points[0].back());
    if(!points[1].empty()&&!points[2].empty()&&(points[1].back()<points[2].back()))
    res.push_back(points[2].back()-points[1].back());
    if(!points[0].empty()&&!points[2].empty()&&(points[0].back()<points[2].back()))
    res.push_back((points[2].back()-points[0].back())*1.0/2);
    return res;
  }
  double min_pos(double t){
    double res = INF;
    if(!points[0].empty()) res = min(res, points[0].front()+t);
    if(!points[1].empty()) res = min(res, (double) points[1].front());
    if(!points[2].empty()) res = min(res, points[2].front()-t);
    return res;
  }
  double max_pos(double t){
    double res = -INF;
    if(!points[0].empty()) res = max(res, points[0].back()+t);
    if(!points[1].empty()) res = max(res, (double) points[1].back());
    if(!points[2].empty()) res = max(res, points[2].back()-t);
    return res;
  }
};
 
int main(){
  int n; cin >> n;
  pos X, Y;
  REP(i,n){
    ll x,y; char d;
    cin >> x >> y >> d;
    switch (d) {
      case 'R':
      X.add_point(p(x,0));
      Y.add_point(p(y,1));
      break;
      case 'L':
      X.add_point(p(x,2));
      Y.add_point(p(y,1));
      break;
      case 'U':
      X.add_point(p(x,1));
      Y.add_point(p(y,0));
      break;
      case 'D':
      X.add_point(p(x,1));
      Y.add_point(p(y,2));
      break;
    }
  }
  vector<double> times;
  for(double time: X.times()) times.push_back(time);
  for(double time: Y.times()) times.push_back(time);
  double ans = 1e30;
  for(double t: times){
    ans = min(ans,(X.max_pos(t)-X.min_pos(t))*(Y.max_pos(t)-Y.min_pos(t)));
  }
  printf("%.10f\n",ans);
  return 0;
}

Measured memory_bytes: 2288
#include <bits/stdc++.h>
using namespace std;
int main() {
   string s1,s2;
   cin >> s1;
   cin >> s2;
   int c=0;
   for(int i=0;i<3;i++){
    if(s1[i]==s2[i])
    c++;
   }
   cout << c << endl;
    return 0;
}


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

const int MAX_V=100000;
const int MAX_E=500000;
const int INF=INT_MAX;

struct E{
  int to,cost;
  E(int t, int c) : to(t),cost(c) {};
};
typedef pair<int,int> pii;

int v;                          // 頂点数
vector<E> g[MAX_V];             // 隣接リスト
int d[MAX_V];                   // 頂点sからの最短距離


void dijkstra(int s){
  // 準備
  fill(d,d+v,INF);
  d[s]=0;
  priority_queue<pii,vector<pii>, greater<pii> > q; // greater<pii>でfirstが小さい順に取り出せるようにする
  q.push(pii(0,s));

  // 頂点ｓから各頂点への最短距離の計算
  while(!q.empty()){
    //　まだ確定していない頂点のうち距離が最小のものを探す
    // その頂点に関しては、最短距離が確定する
    pii p=q.top();
    q.pop();
    int from=p.second;
    if(d[from]<p.first)continue; // 最短距離でなければ無視
    // ここまでくれば頂点fromは最短距離確定

    // 最短距離が確定した頂点に隣接する頂点の情報を更新
    for(int i=0;i<g[from].size();++i){
      int to=g[from][i].to;
      int cost=g[from][i].cost;

      if(d[to]>d[from]+cost){   // 最短距離となりうる場合
        d[to]=d[from]+cost;
        q.push(pii(d[to],to));  // 最短距離の候補をヒープに挿入
      }
    }

  }
}

int main() {
  // 入力
  // gv : 頂点の数
  // ge : 辺の数
  // gr : 始点
  int gv,ge,gr;
  cin>>gv>>ge>>gr;
  v=gv;

  for(int i=0;i<ge;++i){
    // 入力
    // ga : 辺の始点
    // gt : 辺の終点
    // gd : 辺の重み
    int gs,gt,gd;
    cin>>gs>>gt>>gd;
    g[gs].push_back(E(gt,gd));   // 2頂点間の辺の情報を記録
  }

  dijkstra(gr);

  // 出力は、頂点grから各頂点への最短距離
  for(int i=0;i<v;++i){
    if(d[i]!=INF)
      cout<<d[i]<<endl;
    else                        // 頂点iに行けない場合
      cout<< "INF"<<endl;
  }

  return 0;
}



Measured memory_bytes: 12908
#include <iostream>

using namespace std;

int main()
{
	int X, Y,ans = 0;
	cin >> X >> Y;
	switch (X)
	{
	case 1:
		ans += 300000;
		break;
	case 2:
		ans += 200000;
		break;
	case 3:
		ans += 100000;
		break;

	}
	switch (Y)
	{
	case 1:
		ans += 300000;
		break;
	case 2:
		ans += 200000;
		break;
	case 3:
		ans += 100000;
		break;

	}
	if (X == Y and X == 1)
		ans += 400000;
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int k,s;
    std::cin >> k >> s;
    long long res = 0;
    for(int i = 0; i <= k; i ++){
        for(int j = 0; j <= k; j ++){
            int tmp = s - i - j;
            if (tmp <= k && tmp >= 0) res ++;
        }
    }
    std::cout << res;
}

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

int main(void){
    int N;
    std::string a, b, ans = "No";
    std::cin >> a >> b;
    N = stoi(a + b);

    for (int i=1; i<500; ++i){
        if (N == i*i) {
            ans = "Yes";
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

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

#define ll long long int
#define mem(n) memset(n,0,sizeof(n))
#define LCM(a,b) (a / __gcd(a,b) ) * b
#define gcd(a,b) __gcd(a,b)
#define for0(l,n) for(int l=0;l<n;l++)
#define for1(l,n) for(int l=1;l<=n;l++)
#define bug(n) cout<<">> "<<n<<" <<";
#define pb push_back
#define P1(a) cout<<a<<endl;
#define P2(a,b) cout<<a<<" "<<b<<endl;
#define P3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define S1(a) cin>>a
#define S2(a,b)cin>>a>>b
#define S3(a,b,c) S2(a,b),S2(c)
#define squerit(n) (ll)n*n
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)

bool vowel(char a)
{
    a= toupper(a);
    if((a=='A')||(a=='E')||(a=='I')||(a=='O')||(a=='U'))return 1;
    return 0;
}

ll n,m,q,a,b,c,sum=0,cnt=0;
ll arr[1000055];
map<ll,bool>mp;
string str;
int main()
{
    FastRead;

    cin>>n>>a>>b;

    if((a==1 && b==2 )||(a==n && b==n-1)||(abs(b-a) % 2))
    {
        cout<<"Borys"<<endl;
    }
    else cout<<"Alice"<<endl;


}















Measured memory_bytes: 256
#include<iostream>
using namespace std;
main(){for(;;){int i,n,m,h=0,t,e[1000],b[1000];cin>>n>>m;if(!n){break;}for(i=0;i<n;i++){cin>>b[i];}for(i=0;i<m;i++){cin>>e[i];}for(i=0;i<m;i++){h+=e[i];if(h>=n){i++;break;}t=h;h+=b[t];if(h>=n){i++;break;}}cout<<i<<endl;}}

Measured memory_bytes: 0
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int n,m,a[5];
int top,sta[5];
bool pd(int x)
{
	top=0;
	if(x==0)sta[++top]=0;
	else {while(x)sta[++top]=x%10,x/=10;}
	if(top!=n)return false;
	for(int i=1;i<=top;i++)
	{
		if(a[i]!=-1 && sta[top-i+1]!=a[i])return false;
	}
	return true;
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    memset(a,-1,sizeof(a));
    n=read(),m=read();
    for(int i=1;i<=m;i++)
    {
    	int u=read(),v=read();
    	if(a[u]==-1)a[u]=v;
    	else if(a[u]!=v)a[u]=10;
    }
    int ans=-1;
    for(int i=0;i<=999;i++)
    {
    	if(pd(i)==true){ans=i;break;}
    }pr2(ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		String a = sc.next();
		String b = sc.next();
		sc.close();
		int ab = parseInt(a+b);
		int ab2 = (int)sqrt((double)ab);
		out.println(ab==ab2*ab2?"Yes":"No");
	}
}


Measured memory_bytes: 21716
import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


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


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int(input())

        d = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}

        for i in range(n):
            s = input()
            d[s] += 1

        # print(d)

        for x in ['AC', 'WA', 'TLE', 'RE']:
            print(f'{x} x {d[x]}')



Measured memory_bytes: 9496
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   int n;
   cin>>n;
   int a[n],b[n];
   for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
   }
   for(int i=0;i<n-2;i++){
     if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2]){
      cout<<"Yes"<<"\n";
      return 0;
     }
   }
  cout<<"No"<<"\n";
  return 0;


}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<string>
using namespace std;
template < typename T > std::string to_string( const T& n )
    {
        std::ostringstream stm ;
        stm << n ;
        return stm.str() ;
    }
int main(void)
{
	
	int n,count = 0;
	cin >> n;
	for(int i=1;i<=n;i++){
		if(to_string(i).length()%2 == 1){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int answer = A + B;
        if (24 <= answer) {
            answer -= 24;
        }
        System.out.println(answer);
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007

typedef long long ll;

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

    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
//Variables End


void solve(){
	 int n,m,x;cin>>n>>m>>x;
	 vector<int> cost(n);
	 vector<vector<int>> val(n,vector<int> (m,0));
	 for(int i=0;i<n;i++){
		cin>>cost[i];
		for(int j=0;j<m;j++)cin>>val[i][j];
	 }
	 
	 int ans = INT_MAX;
	 
	 for(int mask = 1; mask < (1<<n) ; mask++){
		int cur = 0;
		bool is_ok=true;
		vector<int> know(m);
		for(int bit=0;bit<n;bit++){
			if((1<<bit)&mask){
				cur+=cost[bit];
				
				for(int i=0;i<m;i++){
					know[i] += val[bit][i];
				}
			}
		}
		
		for(int i=0;i<m;i++)if(know[i]<x)is_ok=false;
		
		if(is_ok)ans = min(ans,cur);
		
	 }
	 if(ans==INT_MAX)ans=-1;
	 cout<<ans<<endl;
	 
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    for(int i=1;i<=ti;i++)
    {
		solve();        
    }
    return 0;
        
}


Measured memory_bytes: 3664
#include <iostream>
#include <vector>

using namespace std;

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> p(N);

	for(int i = 0; i < N; i++) {
		cin >> p[i];
		p[i]--;
	}

	UF uf(N);
	for(int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		uf.unite(x, y);
	}

	int cnt = 0;
	for(int i = 0; i < N; i++) {
		if(uf.find(i) == uf.find(p[i])) {
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;

}


Measured memory_bytes: 1792
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) = IO().exec {
    val s = string()
    var l = -1
    for (i in 0 until s.length-1) if (s[i] == s[i+1]) l = i
    if (l >= 0) {
        if (l == 0) {
            var r = 0
            for (i in 0 until s.length-1) if (s[0] == s[i]) r++
            if (r == s.length) println("-1 -1")
            else println("1 ${r+1}")
        } else {
            println("$l ${l+2}")
        }
    } else {
        for (i in 0 until s.length-2) if (s[i] == s[i+2]) l = i
        if (l >= 0) println("${l+1} ${l+3}")
        else println("-1 -1")
    }
}

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = PrintWriter(System.out)
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = System.`in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun string(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun long(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun double(): Double {
        return string().toDouble()
    }
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}

Measured memory_bytes: 31392
from itertools import product

points = list(map(int,input().split()))
k = int(input())

tmp = product(range(3), repeat = k)

for ls in tmp:
    copy = points.copy()
    for chose in ls:
        copy[chose] *= 2
    if copy[1] > copy[0] and copy[2] > copy[1]:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 64436
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;



int main()
{
	fast;
	fs(ar,3);
	fo(i,1,3)
		sum+=ar[i];
	if(sum<22)
		cout<<"win";
	else
		cout<<"bust";

}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll h,w,k,i,j,ans[1000][1000],p,fl,av;
	string a[1000];
	cin>>h>>w>>k;
	for(i=1;i<=h;i++)
		cin>>a[i];
	
	for(j=0;j<w;j++)
		ans[0][j]=1;
	p=0; 
	for(i=1;i<=h;i++) {
		av=0; fl=0;
		for(j=0;j<w;j++)
			if(a[i][j]=='#') {
				av=1;
				break;
			}
		for(j=0;j<w;j++) {
			if(a[i][j]=='#') {
				fl=1;
				p++;
				ans[i][j]=p;
			} else {
				if(av==0) ans[i][j]=ans[i-1][j];
				else {
					if(fl==1) ans[i][j]=p;
					else ans[i][j]=p+1;
				}
			}
		}
	}
	fl=0;
	for(j=0;j<w;j++){
		if(a[1][j]=='#') {
			fl=1;
			break;
		}
	}
	if(fl==0) {
		av=-1;
		for(i=1;i<=h;i++) {
			for(j=0;j<w;j++) {
				if(a[i][j]=='#') {
					av=i;
					break;
				}
			}
			if(av!=-1) break;
		}
		for(i=1;i<av;i++) {
			for(j=0;j<w;j++) {
				ans[i][j]=ans[av][j];
			}
		}
	}
	for(i=1;i<=h;i++) {
		for(j=0;j<w;j++)
			cout<<ans[i][j]<<" ";
		cout<<"\n";
	}	
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

set<int>s[2*maxn];
int visited[2*maxn];
int ans = 0;
int cnt = 0;

void dfs(int st){
	cnt++;
	visited[st] = 1;
	for(auto i:s[st]){
		if(!visited[i]) dfs(i);
	}
}

int32_t main(){
	fastio();
	int n,m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int a,b;
		cin >> a >> b;
		s[a].insert(b);
		s[b].insert(a);
	}
	for(int i = 1; i  <= n; i++){
		if(!visited[i]){
			cnt = 0;
			dfs(i);
			ans = max(ans,cnt);
		}
	}
	cout << ans;
}


Measured memory_bytes: 39588
#include<stdio.h>
int main(void){
  int m,i,sum=0;
  scanf("%d",&m);
  while(m>=500){
    sum+=1000;
    m-=500;
  }
  while(m>=5){
    sum+=5;
    m-=5;
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int a[n+1]={};
    for(int i=0;i<n;i++){
        if(s[i]=='<'){
            a[i+1]=max(a[i+1],a[i]+1);
        }
    }
    for(int i=n-1;i>=0;i--){
        if(s[i]=='>'){
            a[i]=max(a[i],a[i+1]+1);
        }
    }
    ll ans=0;
    for(int i=0;i<n+1;i++){
        ans+=a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2820
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll a,b,c,d;cin>>a>>b>>c>>d;
  ans1((c+b-1)/b<=(a+d-1)/d);
  return 0;
}

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

struct UnionFind{
	vector<int> data;

	UnionFind(int sz){
		data.assign(sz, -1);
	}

	bool unite(int x,int y){
		x = find(x), y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) swap(x,y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}

	bool same(int x,int y){
		if(find(x)==find(y)) return true;
		else return false;
	}

	int find(int k){
		if(data[k]<0) return k;
		return (data[k] = find(data[k]));
	}

	int size(int k){
		return data[find(k)];
	}
};

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

	UnionFind UF(n);

	for(int Q=0;Q<q;Q++){
		int a,b,c;
		cin >> a >> b >> c;
		if(a==0) UF.unite(b, c);
		else cout << UF.same(b, c) << endl;
	}

	return 0;
}


Measured memory_bytes: 3156
import sys

X, Y = map(int, input().split())
MOD = 10 ** 9 + 7

if (X + Y) % 3 != 0:
    print(0)
    sys.exit()

n1 = (2 * X - Y) // 3
n2 = (2 * Y - X) // 3

if n1 < 0 or n2 < 0:
    print(0)
    sys.exit()

P = 10 ** 9 + 7
N = 10 ** 6 + 5
inv_t = [0]+[1]
for i in range(2, N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

m = 10 ** 9 + 7
res = 1
for i in range(2, n1 + n2 + 1):
    res = res * i % m
for i in range(1, n2 + 1):
    res = res * inv_t[i] % m
for i in range(1, n1 + 1):
    res = res * inv_t[i] % m
print(res)

Measured memory_bytes: 42716
#include <cstring>
#include <iostream>

using i64 = long long;

const i64 MOD = 1000000007;
const int N = 300000 + 7;

int n;
char s[N];
i64 f[N][3][3], ans;

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%s", s + 1), n = strlen(s + 1);
	f[0][0][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 3; ++k) {
				if (s[i] != '1')
					( (k == 2 ? f[i][j][1] : f[i][j][k + 1]) += f[i - 1][j][k] ) %= MOD;
				if (s[i] != '0')
					( (k ? f[i][j][k - 1] : f[i][std::min(j + 1, 2)][0]) += f[i - 1][j][k] ) %= MOD;
			}
	for (int j = 0; j < 3; ++j)
		for (int k = 0; k <= j; ++k)
			( ans += f[n][j][k] ) %= MOD;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 21632
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7,M=1e6+7; bool fl[M];
int n,cnt,tot,opv,x[N],y[N],op[M],st[N],f[M<<1],posa[M],posb[M],ch[N][2];
struct node{int pot,num,va,vb;}q[N<<1];
struct edge{int u,v,t;}edg[M<<2];
inline int read(){
	int num=0; char g=getchar(); while(g<48||57<g) g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); return num;
}
inline void addedge(int u,int v){
	tot++,edg[tot].u=u,edg[tot].v=v,edg[tot].t=f[u],f[u]=tot;
}
inline void build(int l,int r,int t){
	if(l==r) {posa[t]=q[l].va,posb[t]=q[l].vb; return;} int d=(l+r)>>1;
	posa[t]=++cnt,posb[t]=++cnt; build(l,d,t<<1),build(d+1,r,t<<1|1);
	addedge(posa[t<<1],posa[t]),addedge(posa[t<<1|1],posa[t]);
	addedge(posb[t],posb[t<<1]),addedge(posb[t],posb[t<<1|1]);
}
inline void linka(int l,int r,int t,int lf,int rf,int pt){
	if(lf>rf) return; if(l==lf&&r==rf) {addedge(pt,posb[t]); return;} int d=(l+r)>>1;;
	if(lf<=d) linka(l,d,t<<1,lf,min(d,rf),pt); if(rf>d)  linka(d+1,r,t<<1|1,max(lf,d+1),rf,pt);
}
inline void linkb(int l,int r,int t,int lf,int rf,int pt){
	if(lf>rf) return;
	if(l==lf&&r==rf) {addedge(posa[t],pt); return;} int d=(l+r)>>1;
	if(lf<=d) linkb(l,d,t<<1,lf,min(d,rf),pt); if(rf>d)  linkb(d+1,r,t<<1|1,max(lf,d+1),rf,pt);
}
inline bool cmp(node a,node b){
	return a.pot<b.pot;
}
inline void tarjan(int u){
	op[u]=++opv,st[++st[0]]=u,fl[u]=1; int ht=opv,hc=st[0];
	for(int i=f[u];i>0;i=edg[i].t){
		int x=edg[i].v; if(!op[x]) tarjan(x); if(fl[x]) op[u]=min(op[u],op[x]);
	}
	if(ht==op[u]){
		while(st[0]!=hc-1) op[st[st[0]]]=ht,fl[st[st[0]]]=0,st[0]--;
	}
}
inline bool check(int u){
	cnt=0,tot=0,opv=0,memset(f,0,sizeof(f)),memset(op,0,sizeof(op)),memset(fl,0,sizeof(fl)); int l,r,t;
	for(int i=1;i<=n;i++){
		ch[i][0]=++cnt,q[cnt].pot=x[i],q[cnt].num=i,q[cnt].va=cnt,q[cnt].vb=cnt+1;
		ch[i][1]=++cnt,q[cnt].pot=y[i],q[cnt].num=i,q[cnt].va=cnt,q[cnt].vb=cnt-1;
	}
	sort(q+1,q+cnt+1,cmp),build(1,n<<1,1);
	for(int i=1;i<=(n<<1);i++){
		l=1,r=i-1,t=i;
		while(l<=r){int d=(l+r)>>1; if(q[d].pot>q[i].pot-u) t=d,r=d-1; else l=d+1;}
		linka(1,n<<1,1,t,i-1,q[i].va),linkb(1,n<<1,1,t,i-1,q[i].vb);
		l=i+1,r=(n<<1),t=i;
		while(l<=r){int d=(l+r)>>1; if(q[d].pot<q[i].pot+u) t=d,l=d+1; else r=d-1;}
		linka(1,n<<1,1,i+1,t,q[i].va),linkb(1,n<<1,1,i+1,t,q[i].vb);
	}
	for(int i=1;i<=cnt;i++) if(!op[i]) tarjan(i);
	for(int i=1;i<=n;i++) if(op[ch[i][0]]==op[ch[i][1]]) return false;
	return true;
}
int main(){
	n=read(); for(int i=1;i<=n;i++) x[i]=read(),y[i]=read();
    int l=0,r=1e9,ans=0;
    while(l<=r) {int d=(l+r)>>1; if(check(d)) ans=d,l=d+1; else r=d-1;}
    cout<<ans<<endl;
	return 0;
}

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

#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f // 100'000'000'000'000
#define all(x) x.begin(),x.end()
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

using namespace std;
const int N= 1e5+10, mod=1e9+7;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);  

	int n,m;
	ll s=0;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x;
		cin>>x;
		s+=x;
	}
	cout<<max(-1LL,n-s);
    
    return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,k;
	cin>>n;
	int h[n];
	for (i=0;i<n;i++)
	cin>>h[i];
	int dp[n+1];
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(h[1]-h[0]);
	for (i=3;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(h[i-1]-h[i-2]),dp[i-2]+abs(h[i-1]-h[i-3]));
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
N, K, C = map(int, input().split())
S = str(input())
A = [0] * K
B = [0] * K
a = 0
b = N - 1
for i in range(K):
    j = K - 1 - i
    while S[a] == 'x':
        a += 1
    while S[b] == 'x':
        b -= 1
    A[i] = a
    a += 1 + C
    B[j] = b
    b -= 1 + C
for i in range(K):
    if A[i] == B[i]:
        print(A[i] + 1)

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

namespace AtCoder.Abc
{
    // 問題:
    class A_157_Duplex_Printing
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            int result = n / 2;

            if(n % 2 == 1)
            {
                result = result + 1;
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

using int64 = long long;
using uint64 = unsigned long long;

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

    int N;
    cin >> N;

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

    vector<bool> isChanged(N, false);
    int ans = 0;
    for (int i = 1; i < N; i++)
    {
        if (!isChanged[i - 1] and a[i - 1] == a[i])
        {
            ans++;
            isChanged[i] = true;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
sm = 0
r = [0]*n
r[0]=a[0]
for i in range(1,n):
    if r[i-1]*2 >= a[i]:
        sm += 1
    else:
        sm = 0
    r[i] = r[i-1] + a[i]

print(sm+1)

Measured memory_bytes: 20436
N, A, B, C, D = map(int, input().split())

#右端がでかくしても一般性を失わない
# if A > B:
#     A, B = B, A

k = (B - A + (N - 1) * D) // (C + D)
# print (k)
if k >= (B - A + (N - 1) * C) / (C + D) and N - 1 >= k >= 0:
    print ('YES')
else:
    print ('NO')


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;scanf("%d",&n),n;){
		vi hist(7);
		rep(i,n){
			int age; scanf("%d",&age);
			hist[min(age,60)/10]++;
		}
		rep(i,7)
			printf("%d\n",hist[i]);
	}
	
	return 0;
}

Measured memory_bytes: 916
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> B(N - 1);
  for (int i = 0; i < N - 1; ++i) {
    cin >> B[i];
  }

  ll sum = 0;
  if (N == 2) {
    sum += 2* B[0];
  }else {
  sum += B[0];
  for (int i = 1; i < N - 1; ++i) {
    sum += min(B[i-1], B[i]);
  }
   sum += B[N-2];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = true;


int main(){

    
    ll n;
    cin >> n;

    vector<ll> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    sort(all(v));

    ll sum = 0;
    for(int i = 0; i < n; i++){
        if(v[i] < 0) sum -= v[i];
        else sum += v[i];
    }

    if(v[0] >= 0){
        cout << sum - 2 * v[0] << endl;
        for(int i = 1; i < n - 1; i++){
            cout << v[0] << " " << v[i] << endl;
            v[0] -= v[i];
        }   
        cout << v[n-1] << " " << v[0] << endl;
    }
    else if(v[n-1] <= 0){
        cout << sum + 2 * v[n-1] << endl;
        for(int i = 0; i < n - 1; i++){
            cout << v[n-1] << " " << v[i] << endl;
            v[n-1] -= v[i];
        }   
    }
    else {
        cout << sum << endl;
        for(int i = 1; i < n-1; i++){
            if(v[i] < 0){
                cout << v[n-1] << " " << v[i] << endl;
                v[n-1] -= v[i];
            }
            else{
                cout << v[0] << " " << v[i] << endl;
                v[0] -= v[i];
            }
        }
        cout << v[n-1] << " " << v[0] << endl;
    }



}

Measured memory_bytes: 2688
#include<iostream>
using namespace std;
int a,b,c,ans;
int main()
{
    int n;
    cin>>a>>b>>c;
    for(int i=1;i<=a;i++)
    {
        cin>>n;
        if(n<b||n>=c)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

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

using namespace std;

typedef long long ll;

struct Data {
  ll h,a,d,s,t;
  bool operator < ( const Data &data ) const { return d * data.t > data.d * t; }
};

int n;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  Data fri;
  cin >> fri.h >> fri.a >> fri.d >> fri.s;
  vector<Data> buf;
  bool out = false;
  rep(i,n) {
    ll h,a,d,s,t;
    cin >> h >> a >> d >> s;
    buf.push_back((Data){h,a,d,s});
    ll fattack = max(0LL,fri.a-buf[i].d);
    ll eattack = max(0LL,buf[i].a-fri.d);
    //cout << fattack << " " << eattack << endl;
    if( fattack == 0LL ) {
      if( eattack == 0LL ) continue;
      out = true;
      continue;
    }
    buf.back().t = (ll)( buf.back().h / fattack ) + (ll)( (buf.back().h%fattack) != 0 );
    buf.back().d = eattack;
  }

  if( out ) {
    puts("-1");
    return 0;
  }

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

  ll ans = 0LL, total_turn = 0;
  ll HP = fri.h;
  rep(i,buf.size()) {
    int coef = 0;
    if( buf[i].s < fri.s ) coef = 1;
    total_turn += buf[i].t;
    //cout << "total_turn = " << total_turn << endl;
    //cout << "pow = " << buf[i].d << endl;
    ans += buf[i].d * max(0LL, total_turn - (ll)coef );
    HP -= buf[i].d * max(0LL, total_turn - (ll)coef );
    //cout << HP << " " <<ans<< endl;
    if( HP <= 0LL ) {
      puts("-1");
      return 0;
    }
  }

  cout << ((ans<fri.h)?ans:-1) << endl;

  return 0;
}

Measured memory_bytes: 3792
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, x[N], y[N], ans, edge, cnt1, cnt2;
bool used[N];
vector <int> g[N];

void dfs (int v, bool ok = 0) {
   cnt1 += ok;
   cnt2 += (ok ^ 1);
   used[v] = 1;
   for (auto to : g[v]) {
      edge ++;
      if (!used[to])
         dfs (to, (ok ^ 1));
   }
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () { 
   cin >> n;
   for (int i = 1; i <= n; i ++) {
      cin >> x[i] >> y[i];
      y[i] += 100000;
      g[x[i]].pb (y[i]);
      g[y[i]].pb (x[i]);
   }
   for (int i = 1; i <= 100000; i ++)
      if (!used[i]) {
         dfs (i);
         ans += 1ll * cnt1 * cnt2 - edge / 2;
         edge = cnt1 = cnt2 = 0;  
      }
   cout << ans;

}                                     

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


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


int main(void){
    string s;
    cin>>s;
    bool flag=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='d'){
            if(s[i+7]=='a' || s.size()<i+7 || s[i+5]=='d'){
                if(s.substr(i, 5) != "dream")flag=1;
                i+=4;
            }
            else{
                if(s.substr(i, 7) != "dreamer")flag=1;
                i+=6;
            }            
        }
        else if(s[i]=='e'){
            if(s[i+5]=='r'){
                if(s.substr(i, 6) != "eraser")flag=1;
                i+=5;
            }
            else{
                if(s.substr(i, 5) != "erase")flag=1;
                i+=4;
            }
        }
    }
    if(flag) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int q;
	cin >> q;
	REP(i, q) {
		ll a, b;
		cin >> a >> b;
		ll c = sqrt(a * b);
		if (c * c == a * b) {
			if (a == b) {
				put(2 * (c - 1));
			} else {
				put(2 * (c - 1) - 1);
			}
			continue;
		}
		c = sqrt(a * b - 1);
		ll res;
		if (a * b <= c * (c + 1)) {
			res = 2 * c - 2;
		} else {
			res = 2 * c - 1;
		}
		put(res);
	}
	return 0;
}


Measured memory_bytes: 256
while True:
    n,x = map(int,input().split())
    if n == x and n == 0:
        break
    count = 0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    count = count+1
                    break

    print(count)



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

/*                          
---------------------------------------------------------------
Aditya Kumar mishra
---------------------------------------------------------------
*/

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define len(s) s.length()
#define forp(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define ren(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (int i = a; i >= b; i--)
#define on cout << endl
#define o2(a, b) cout << a << " " << b
#define os cout << " "
#define all(v) v.begin(), v.end()
#define mem(n, m) memset(n, m, sizeof(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sii set<int>
#define us unordered_set<int>
#define um unordered_map<int, int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return 0
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define ford(container, it) for (__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fors(container, it, a, b) for (__typeof(container.begin()) it = a; it != b; it++)

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001

typedef long long ll;
typedef long double ldo;
typedef double db;
using namespace std;
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    c_p_c();
    ll n;
    cin >> n;
    vll v(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    ll sum = 0;
    vll v1;
    v1.pb(v[0]);
    // for (auto x : v)
    // {
    //     cout << x << " ";
    // }
    // on;
    // for (auto x : v1)
    // {
    //     cout << x << " ";
    // }

    for (ll i = 1; i < n; i++)
    {
        v1.pb(max(v1[i - 1], v[i]));
    }
    for (ll i = 0; i < n; i++)
    {
        sum += abs(v1[i] - v[i]);
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 6888
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())

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

const int n1=60, n2=40, n3=30, n4=200, ntot=60;
const ll INF = 1e19;

ll N, A, B, C, D;
//__int128 dp[n1+1][n2+1][n3+1][n4+10];
ll dp[n1+1][n2+1][n3+1][n4+10][5];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while(T--) {
    cin >> N;
    cin >> A >> B >> C >> D;
    for(int i=0; i<n1; i++)
      for(int j=0; j<n2; j++)
        for(int k=0; k<n3; k++)
          for(int l=0; l<n4; l++)
            for(int m=0; m<5; m++)
              dp[i][j][k][l][m] = INF;
    dp[0][0][0][0][0] = N;
    __int128 best = INF;
    for(int i=0; i<min(n1,ntot); i++){
      for(int j=0; j<min(n2,ntot-i); j++){
        for(int k=0; k<min(n3,ntot-i-j); k++){
          for(int l=0; l<n4; l++){
            for(int m=0; m<5; m++){
              ll cur = dp[i][j][k][l][m];
              best = min(best, i*A+j*B+k*C+(l+cur)*((__int128)D));
              if(cur == INF || cur == 0)
                continue;
              int x = cur/2%5;
              dp[i+1][j][k][l+cur%2][x] = min(dp[i+1][j][k][l+cur%2][x], cur/2);
              x = (cur/2+1)%5;
              dp[i+1][j][k][l+2-cur%2][x] = min(dp[i+1][j][k][l+2-cur%2][x], cur/2+1);
              x = cur/3%5;
              dp[i][j+1][k][l+cur%3][x] = min(dp[i][j+1][k][l+cur%3][x], cur/3);
              x = (cur/3+1)%5;
              dp[i][j+1][k][l+3-cur%3][x] = min(dp[i][j+1][k][l+3-cur%3][x], cur/3+1);
              x = cur/5%5;
              dp[i][j][k+1][l+cur%5][x] = min(dp[i][j][k+1][l+cur%5][x], cur/5);
              x = (cur/5+1)%5;
              dp[i][j][k+1][l+5-cur%5][x] = min(dp[i][j][k+1][l+5-cur%5][x], cur/5+1);
            }
          }
        }
      }
    }
    cout << (ll)best << endl;
  }

  return 0;
}


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

int main(){
	string s;cin>>s;
	ll cnt=0;
	ll ans=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='B'){
			cnt++;
		}else{
			ans+=cnt;
		}
	}
	cout<<ans;
}

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

using namespace std;
using ll = long long;

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

  const ll mod = 1e9 + 7;

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

  // bits[i][j][0or1] := i番目以降の数にj桁目が0or1になる数がいくつあるか
  vector<vector<vector<ll>>> bits(n, vector<vector<ll>>(60, vector<ll>(2)));

  for (ll i = n - 1; i >= 0; i--) {
    for (ll j = 0; j < 60; j++) {
      if (i < n - 1) {
        bits[i][j][0] = bits[i + 1][j][0];
        bits[i][j][1] = bits[i + 1][j][1];
      }
      if (a[i] & (1ll << j)) {
        bits[i][j][1]++;
      } else {
        bits[i][j][0]++;
      }
    }
  }

  ll ans = 0;
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = 0; j < 60; j++) {
      if (a[i] & (1ll << j)) {
        ans += ((1ll << j) % mod) * bits[i + 1][j][0];
        ans %= mod;
      } else {
        ans += ((1ll << j) % mod) * bits[i + 1][j][1];
        ans %= mod;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1001608
N,M=list(map(int, input().split()))
P=[0]*M
S=[0]*M
for i in range(M):
    P[i],S[i]=list(input().split())
    P[i]=int(P[i])

flagac=[False]*N
pnlt=[0]*N
for i in range(M):
    p=P[i]-1
    s=S[i]
    if s=='AC':
        flagac[p]=True
    else:
        pnlt[p]+=(flagac[p]+1)%2
# print(flagac)
# print(pnlt)

ctac=0
ctwa=0
for i in range(N):
    if flagac[i]:
        ctac+=1
        ctwa+=pnlt[i]
print(ctac, ctwa)

Measured memory_bytes: 88928
#include <iostream>
#include <vector>

using namespace std;

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

	int ans = 0;
	for (int i = 0; i < n; i += 2) {
		ans += a[i] % 2 == 1 ? 1 : 0;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3616