akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define pr        pair<int,int>
#define vpll       vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(container) int((container).size())
#define mape map<int,int>
const ll mod=1e9+7;
const int N=2e5+5;
//cout << fixed << setprecision(6) <<
using namespace std;
int main()
{
    int x,y,flag=0;
    cin>>x>>y;
    FOR(i,0,100)
    FOR(j,0,100)
    if(i+j==x and i*2+j*4==y)
    flag=1;
    if(flag)
    cout<<"Yes";
    else
    cout<<"No";
}

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

using namespace std;

vector<int> G[100010];
vector<pair<int,int> > e;
map<pair<int,int>, int> mp;
int ans[100010];
int in[100010];
int mx;

void dfs(int u, int p, int color) {
    ans[u] = color;
    mp[make_pair(min(u,p), max(u,p))] = color;
    set<int> s;
    if(color != 0)s.insert(color);
    int cur = 1;
    for (int v: G[u]) {
        if(v == p) continue;
        while(s.count(cur) and cur <= mx) cur++;
        s.insert(cur);
        dfs(v, u, cur);
    }
}

int main() {
    
    int n;
    cin >> n;
    
    for (int i = 0; i < n - 1; ++i) {
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
        e.emplace_back(min(x,y), max(x,y));
        in[x]++,in[y]++;
    }

    mx = 0;
    for (int i = 1; i <= n; ++i)
        mx = max(mx, in[i]);

    dfs(1,1,0);
    
    cout << mx << "\n";

    for (auto p: e) 
        cout << mp[make_pair(p.first, p.second)] << "\n";
    return 0;
}


Measured memory_bytes: 23672
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  string N;
  cin >> N;
  uint64_t s = 0;
  for (int i = 0; i < N.length(); i++)
  {
    s += stoi(N.substr(i, 1));
  }
  cout << (s % 9 == 0 ? "Yes" : "No") << endl;
}


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

int main(){
  int t;
  cin >> t;
  vector<long long int> v(3 * t);
  for(int i = 0; i < 3 * t; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  long long int sum = 0;
  for(int i = 0; i < t; i++) {
    sum += v[i * 2 + 1];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 2560
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    from collections import deque
    d=deque(input())
    q=int(input())
    rev=False
    for i in range(q):
        l=input().split()
        if len(l)==1:
            if rev:
                rev=False
            else:
                rev=True
        else:
            if rev:
                if l[1]=='1':
                    d.append(l[2])
                else:
                    d.appendleft(l[2])
            else:
                if l[1]=='1':
                    d.appendleft(l[2])
                else:
                    d.append(l[2])
    if rev:
        d=reversed(d)
    print(''.join(d))
resolve()

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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second

const int N = 7;

string g[N];

void solve() {
    int h, w, k; 
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++)
        cin >> g[i];

    int ans = k ? 0 : 1;
    for (int i = 0; i < ((1 << h) - 1); i++) {
        for (int j = 0; j < ((1 << w) - 1); j++) {
            int cnt = 0;
            for (int x = 0; x < h; x++)
                for (int y = 0; y < w; y++)
                    if (!(i & (1 << x)) && !(j & (1 << y)))
                        if (g[x][y] == '#')
                            cnt++;
            if (cnt == k)
                ans++;
        }
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 3604
h,w=map(int, input().split())
s=[list(input()) for i in range(h)] 
x=0
v=0
count=0
for i in range(h):
    if s[x].count('.')==w:
        del s[x] 
    else:
        x+=1
for j in range(w):
    for i in range(len(s)):
        if s[i][v]=='.':
            count+=1
    if count==len(s):
        count=0
        for i in range(len(s)):
            del s[i][v]
    else:
        v+=1
        count=0
        
for i in range(len(s)):
    print(''.join(s[i]))

Measured memory_bytes: 3188
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use std::collections::HashSet;

#[fastout]
fn main() {
    input! {
    mut s: usize
    }
    let mut is_used = HashSet::new();
    is_used.insert(s);
    for i in 1.. {
        let ns = f(s);
        if is_used.contains(&ns) {
            print!("{}", i + 1);
            return
        }
        is_used.insert(s);
        s = ns;
    }
}

fn f(n: usize) -> usize {
    if n % 2 == 0 {
        n / 2
    } else {
        3 * n + 1
    }
}



Measured memory_bytes: 2184
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(void) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int white = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        white++;
      }
    }
  }
  vector<vector<int> > dis(h, vector<int>(w, -1));
  dis[0][0] = 0;
  queue<pair<int, int> > qu;
  qu.push(make_pair(0, 0));
  while (!qu.empty()) {
    int i = qu.front().first;
    int j = qu.front().second;
    int k = dis[i][j];
    if (i + 1 < h && s[i + 1][j] == '.' && dis[i + 1][j] == -1) {
      qu.push(make_pair(i + 1, j));
      dis[i + 1][j] = k + 1;
    }
    if (i - 1 >= 0 && s[i - 1][j] == '.' && dis[i - 1][j] == -1) {
      qu.push(make_pair(i - 1, j));
      dis[i - 1][j] = k + 1;
    }
    if (j + 1 < w && s[i][j + 1] == '.' && dis[i][j + 1] == -1) {
      qu.push(make_pair(i, j + 1));
      dis[i][j + 1] = k + 1;
    }
    if (j - 1 >= 0 && s[i][j - 1] == '.' && dis[i][j - 1] == -1) {
      qu.push(make_pair(i, j - 1));
      dis[i][j - 1] = k + 1;
    }
    if (i == h - 1 && j == w - 1) {
      cout << white - k - 1 << endl;
      return 0;
    }
    qu.pop();
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void Print(int a[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
}

void insertionSort(int a[],int n){
  int i,j,v;
  Print(a,n);
  for(i=1;i<n;i++){

    v=a[i];
    j=i-1;
    while(j>=0 && a[j]>v){
      a[j+1]=a[j];
      j--;
      a[j+1]= v;
      }
      Print(a,n);
  }
}

int main(void){
  int n,i;
  int a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  insertionSort(a,n);

  return 0;
}



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

int main(){
  string S;
  cin >> S;
  int N=S.size();
  for(int i=(N-1)/2;i>0;i--){
    bool ok = true;
    for(int j=0;j<i;j++){
      if(S[i+j]!=S[j]){
        ok = false;
        break;
      }
    }
    if(ok){
      cout << 2*i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int n, ans, total; cin >> n;
    int w[n];
    total = 0;
    ans = N_MAX;
    for (int i = 0; i < n; i++)
    {
        cin >> w[i];
        total += w[i];
    }
    int s1 = 0;
    int s2 = total;
    for (int j = 0; j <= n; j++ )
    {
        s1 += w[j];
        s2 -= w[j];
        if (ans > abs(s1 -s2))
        {
            ans = abs(s1 - s2);
        } 
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

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

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

int main() {
  vector<int> a(5);
  vector<int> b(5);
  int sum = 0;
  for(int i=0;i<5;i++){
    cin >> a.at(i);
    b.at(i) = a.at(i) % 10;
    if(b.at(i) == 0) b.at(i) = 10;
    a.at(i) += 10 - b.at(i);
    sum += a.at(i);
  }
  sort(b.begin(),b.end());
  cout << sum - 10 + b.at(0) << endl;
  return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 char c[101];
 int main(void) {
 cin>>c;
 int res = 0;
 int n = strlen(c);
 for (int i = 0; i < n; i++) {
 	if (c[i] != c[n - 1 - i]) 
      res++;
 }
cout<<res/2;
   return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define EPS 1e-9
#define PI acos(-1)
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    ll ans = 0;
    for(ll i = 1; i*i <= n; i++)
    {
        if(n%i==0)
        {
            if(n/i < i - 1)
            {
                ans += i-1;
                //cout<<i-1<<endl;
            }
            if(i*i==n) continue;
            if(i < n/i - 1)
            {
                ans += n/i-1;
                //cout<<n/i-1<<endl;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
x=int(input())
if x in range(400,600): print("8")
if x in range(600,800): print("7")
if x in range(800,1000): print("6")
if x in range(1000,1200): print("5")
if x in range(1200,1400): print("4")
if x in range(1400,1600): print("3")
if x in range(1600,1800): print("2")
if x in range(1800,1999+1): print("1")

Measured memory_bytes: 62004
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
time = [a, b, c, d, e]

for i in range(5):
    if time[i] % 10 == 0:
        time[i] = 0
    else:
        time[i] = abs((time[i] % 10) - 10)

time_m = max(time)
print(a + b + c + d + e + sum(time) - time_m)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	static edge[][] V=new edge[30][30];
	static class edge{
		int v,c;
		edge(int v,int c){//v=行き先, c=距離
			this.v=v;
			this.c=c;
		}
	}
	static class node implements Comparable<node>{
		double cc;
		int v,st;
		node(double cc,int v,int st){//cc=所要時間, v=現在地, st＝使ったチケット
			this.cc=cc;
			this.v=v;
			this.st=st;
		}
		public int compareTo(node s){
			if(this.cc>s.cc)return 1;
			else if(this.cc<s.cc)return -1;
			else return 0;
		}
	}

	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();//チケット枚数
			int m = sc.nextInt();//都市数
			int p = sc.nextInt();//道路数
			int a = sc.nextInt()-1;//出発地
			int b = sc.nextInt()-1;//目的地
			if(n==0)break;
			int[] ti=new int[n];
			int[] Vs=new int[m];
			for(int i=0;i<n;i++) {
				ti[i]=sc.nextInt();
			}//チケットごとの馬数

			Arrays.fill(Vs,0);

			for(int i=0;i<p;i++){
				int x=sc.nextInt()-1;
				int y=sc.nextInt()-1;
				int z=sc.nextInt();//xy間距離
				V[x][Vs[x]++]=new edge(y,z);
				V[y][Vs[y]++]=new edge(x,z);
			}
			Queue<node> q=new PriorityQueue<node>();
			q.add(new node(0,a,0)); //cc=所要時間, v=現在地, st＝使ったチケット

			double[][] vis=new double[m][1<<n];
			boolean[][] fix=new boolean[m][1<<n];
			for(int i=0;i<m;i++){
				Arrays.fill(vis[i],1<<28);
				Arrays.fill(fix[i],false);
			}

			double ans=-1;

			while(! q.isEmpty()){
				node cn=q.poll();

				if(fix[cn.v][cn.st])continue;
				fix[cn.v][cn.st]=true;
				if(cn.v==b){//目的地のとき
					ans=cn.cc;//所要時間
					break;
				}

				for(int i=0;i<n;i++){//n:チケット枚数
					if(((cn.st>>i)&1)==1)continue;
					for(int j=0;j<Vs[cn.v];j++){
						int nv=V[cn.v][j].v;//現在地
						int tc=V[cn.v][j].c;//距離
						int nst=cn.st|(1<<i);//使ったチケット
						double nc=cn.cc+1.0*tc/ti[i];//今までの時間＋今回かかった時間
						if(vis[nv][nst]<=nc)continue;
						vis[nv][nst]=nc;//小さいとき
						q.add(new node(nc,nv,nst));
					}
				}
			}
			if(ans<0)System.out.println("Impossible");
			else System.out.println(ans);
		}
	}
}



Measured memory_bytes: 50092
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
#define pii pair < int , int >
#define vi vector < int >
#define pb push_back
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define vll vector < long long int >
#define sll set < long long int >
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main()
{
	fastIO;
	ll a,b;
	cin>>a>>b;
	if(a+b==15)
	{
		cout<<"+";return(0);
	}
	if(a*b==15)
	{
		cout<<"*";return(0);
	}
	cout<<"x";
	return(0);
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    int cnt=0,x,y;
    rep(i,n){
        cin>>x>>y;
        if(x==y) cnt ++;
        else cnt=0;
        if(cnt==3){
            Yes;
            return 0;
        }
    }
    No;
}/*
./problem.exe
*/

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, w; cin >> n >> w;
    long long dp[w + 1]; for (int i = 0; i <= w; i++) dp[i] = 0;
    for (int i = 0; i < n; i++) {
        int wi, v; cin >> wi >> v;
        for (int j = w; j >= wi; j--) dp[j] = max(dp[j], dp[j - wi] + v);
    }
    long long ans = 0;
    for (int i = 0; i <= w; i++) ans = max(ans, dp[i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    int n;
    cin >> n;
    vec<pair<int, int>> times(n);
    for (auto& e : times)
        cin >> e.first >> e.second;

    auto comp = [](auto p1, auto p2)
    {
        if (p1.second == p2.second)
            return p1.first > p2.first;
        else
            return p1.second > p2.second;
    };

    priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(comp)> q(comp);
    for (const auto& e : times)
        q.emplace(e);

    int t{}, ans{};
    while (!q.empty())
    {
        auto top = q.top();
        q.pop();

        //cout << top.first << " " << top.second << endl;

        if (t < top.first)
        {
            t = top.second;
            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4616
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;

bool f[d5],s[d5];
int df[d5],ds[d5];
vector<int> edge[d5];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    fill(df,df+n,inf);
    fill(ds,ds+n,inf);
    df[0]=0;
    f[0]=true;
    ds[n-1]=0;
    s[n-1]=true;
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()){
        int now=Q.front();Q.pop();
        for(int i=0;i<edge[now].size();i++){
            if(!f[edge[now][i]]){
                f[edge[now][i]]=true;
                df[edge[now][i]]=df[now]+1;
                Q.push(edge[now][i]);
            }
        }
    }
    ds[n-1]=0;
    s[n-1]=true;
    Q.push(n-1);
    while(!Q.empty()){
        int now=Q.front();Q.pop();
        for(int i=0;i<edge[now].size();i++){
            if(!s[edge[now][i]]){
                s[edge[now][i]]=true;
                ds[edge[now][i]]=ds[now]+1;
                Q.push(edge[now][i]);
            }
        }
    }
    int fcnt=0,scnt=0;
    for(int i=0;i<n;i++){
        if(df[i]<=ds[i])fcnt++;
        else scnt++;
    }
    if(fcnt>scnt)cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
}

Measured memory_bytes: 8320
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0;
    rep(i, n) {
        ll cnta = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll cntc = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
        ans += cnta * (n - cntc);
    }
    cout << ans << endl;
}

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

int count(int arr[], int n){
	
	if(n==1)
		return 0;
	
	if(n==2){
		if(arr[1]<=arr[0])
			return 1;
		else
			return 0;
	}
	
	int i=0;
	int j=i+1;
	int ans = 0;
	
	while(j<n){
		if(arr[j]<=arr[j-1]){
			ans = max(ans,j-i+1);
			//cout<<"YES"<<j-i+1<<endl;
			j++;
		}else{
			i = j;
			j = i+1;
		}
	}
	return (ans-1>0?ans-1:0);
}

int main(){
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	cout<<count(arr,n);
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin>>str;
  if(str.size()<4){
    cout<<"No"<<endl;
  }else if(str.substr(0,4)=="YAKI"){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int xs[100100], ys[100100];
int num[100100];

bool flg[100100];

int N, M;

void input(){
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; ++i){
		scanf("%d%d", xs + i, ys + i);
	}
}

void init(){
	for(int i = 1; i <= N; ++i){
		flg[i] = false;
		num[i] = 1;
	}
	flg[1] = true;
}

void proc(int x, int y){
	num[x]--;
	num[y]++;
	if(flg[x]) flg[y] = true;
	if(num[x] == 0) flg[x] = false;
}

int main(){
	input();
	init();
	for(int i = 0; i < M; ++i) proc(xs[i], ys[i]);
	int ans = 0;
	for(int i = 1; i <= N; ++i) if(flg[i]) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

void solve(long long N, std::vector<long long> A) {
  // solver code

  LL res = 0;

  LL right = 0;
  LL sum = 0;

  for (int left = 0; left < N; left++) {
    while (right < N && (sum ^ A[right]) == (sum + A[right])) {
      sum += A[right];
      right++;
    }

    res += right - left;

    if (left == right) {
      right++;
    } else {
      sum -= A[left];
    }
  }

  cout << res << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <map>

using namespace std;

int main() 
{
	int a, b;
	cin >> a >> b;
	if (a + b == 15)
	{
		cout << "+";
	}
	else if (a*b == 15)
	{
		cout << "*";
	}
	else
	{
		cout << "x";
	}



}

Measured memory_bytes: 256
/*input
6
1 1
2 2
3 3
4 4
5 5
6 6
*/


 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m,c;

void solve()
{
  
int count=0;
c=0;
cin>>n;
for(i=0;i<n;i++)
{
    cin>>j>>k;

    if(j==k)
    {
        count++;
    }
    else {
        if(count>=3)
            c=1;

        count=0;
    }
}
if(count>=3)
            c=1;

            if(c)
                cout<<"Yes";
            else cout<<"No";


  }

 
 
 
signed main()
{// inputFile;


    fast;
    int T = 1;
    // cin >> T;
    ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

template <typename T> T gcd(T x, T y) { return( y ? gcd(y, x % y) : x); }
template <typename T> T lcm(T x, T y) { return( x / gcd(x, y) * y); }
template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
    int a, b;
  cin >> a >> b;

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define put(arr,v) fil(all(arr) , v)
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define sort(v) sort(all(v));
#define fill_vec(v,val)  fill(all(v) , val)
#define fill_arr(ar,n,val) fill(ar , ar+n ,val)
#define nl cout<<"\n";
#define input_i(v) generate(all(v),nxt_i);
#define input_s(v) generate(all(v),nxt_s);
#define vst vector<string>
#define vi vector<int>
#define pi pair<int,int>

// namespace ohuefmi{
    
//     int nxt_i(){
//         int x;
//         cin>>x;
//         return x;
//     }
//     string nxt_s(){
//         string x;
//         cin>>x;
//         return x;
//     }
//     void print(vector<int>v){
//         for(auto i : v){
//             cout<<i<<" ";
//         }nl;
//     }
//      void print(vector<string>v){
//         for(auto i : v){
//             cout<<i<<" ";
//         }nl;
//     }
    
//     string binary(int n)
//     {
//         bitset<32>b(n) ;
//         string p =b.to_string();
//         return p;

//     }
//     int decimal(string s)
//     {
//         int res = 0;
//         for(int i = 0; i < s.size() ; i++ ){
//             if(s[i] == '1')
//             res = res + pow(2,s.size() - i -1);
//         }
//         return res;
//     }
//     bool isPrime(int n){
//         if (n <= 1) return false; if (n <= 3) return true;
//     if (n % 2 == 0 || n % 3 == 0) 
//         return false;
//     for (int i = 5; i * i <= n; i = i + 6) 
//         if (n % i == 0 || n % (i + 2) == 0) 
//             return false; 
  
//     return true; 
//     }
    
//      int pow (int x, int n,int mod) {//calculate x^n
//     if (n == 0) return 1;

//       int res = pow (x, n / 2,mod);

//     res = (res * res) % mod;
//     if (n % 2) res = (res * x ) % mod;

//     return res;
//     }
    
// }

// using namespace ohuefmi;
int32_t main(){
    
    
        ios_base::sync_with_stdio(cin.tie(NULL));
        cout.tie(NULL);
    
        int tc = 1; 
        // tc = nxt_i();

        while(tc -- ){
            
            
            
            double n;
            cin>>n;
            
            double res = 0.0;
            
            double sum =  n/3.0;
            
            double cas  = n - sum*2.0;
            
            res =  sum*sum*cas;
            
            
            
            precise(10);
            cout<<res<<endl;
        }       
       
      
      
}


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

int main()
{
    int n;
    cin >> n;
    int a[200002], b[200002];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a, a + n, greater<int>());
    if(a[0] == a[1]){
        for(int i = 0; i < n; i++) cout << a[0] << endl;
    }
    else{
        for(int i = 0; i < n; i++){
            if(b[i] == a[0]) cout << a[1] << endl;
            else cout << a[0] << endl;
        }
    }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	int n,h;
	cin>>n;
	vector<int> lista,aux,ali;
	queue<vector<int> > q;
	int posi=0,i;
	for(i=0;i<n;i++){
		cin>>h;
		lista.push_back(h);
		if(h==0){
			if(aux.size()>0) q.push(aux);
			aux.clear();
		}
		else aux.push_back(h);
	}
	if(aux.size()>0) q.push(aux);
	int ans=0;
	while(!q.empty()){
		aux=q.front();
		q.pop();
		int mini=200;
		ali.clear();
		for(int j=0;j<aux.size();j++){
			mini=min(aux[j],mini);
		}
		for(int j=0;j<aux.size();j++){
			aux[j]-=mini;
			if(aux[j]==0){
				if(ali.size()>0) q.push(ali);
				ali.clear();
			}	
			else ali.push_back(aux[j]);
		}
		if(ali.size()>0) q.push(ali);
		ans+=mini;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	ll n;
	cin >> n;
	ll sum = 0, ans = 0;
	set<ll> s;
	bool flag = false;
	while(true){
        ans++;
        sum = (sum*10 + 7)%n;
        if (sum == 0){
            cout << ans << endl;
            break;
        }
        if (s.find(sum) != s.end()){
            cout << "-1" << endl;
            break;
        }
        s.insert(sum);
    }
	return 0;
}


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

int main(){
  int X, A, B;
  cin >> X >> A >> B;
  if (B <= A) {
    cout << "delicious" << endl;
  } else if (B <= A + X) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){
  int n = 0;
  int a[100000] = {};
  int b[100000] = {};
  int i = 0;
  long max = 0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    b[a[i]]++;
  }
  for(i=0;i<100000;i++){
    if(i != 0 && i != 99999){
      if(b[i-1]+b[i]+b[i+1] > max){
        max = b[i-1]+b[i]+b[i+1];
        //printf("%d/",b[i-1]+b[i]+b[i+1]);
      }
      
    }else if(i == 0){
      if(b[0] + b[1] > max){
        max = b[0] + b[1];
      }
    }else if(i == 99999){
      if(b[99998]+b[99999] > max){
        max = b[99999]+b[99998] ;
      }
    }
  }
  printf("%ld",max);
    
  /*for(i=0;i<n-1;i++){
    printf("%d ",b[i]);
  }*/
  return 0;
}

Measured memory_bytes: 896
if __name__ == '__main__':
    S = input()

    S1 = S.replace("A", "")
    if S1 != "KIHBR":
        print("NO")
        exit()

    if not "KIH" in S:
        print("NO")
        exit()

    if S.find("AA") > -1:
        print("NO")
        exit()

    print("YES")


Measured memory_bytes: 3060
from itertools import combinations_with_replacement
N,M,Q= map(int,input().split())
abcd = [list(map(int,input().split())) for i in range(Q)]

ans = 0
for A in combinations_with_replacement(range(1,M+1),N):
    p = 0
    for a,b,c,d in abcd:
        if A[b-1] - A[a-1] == c:
            p += d
    ans = max(p,ans)

print(ans)




Measured memory_bytes: 73580
n=int(input())
a=list(map(int,input().split()))
cnt=0
ch=True
#print(cnt,a)
while True:
    my_bool=True
    for i in range(n):
        if my_bool:
            if a[i]!=0:
                my_bool=False
                ch2=True
                a[i]-=1
        else:
            if a[i]!=0:
                a[i]-=1
                ch=True
                ch2=True
            else:
                if ch2:
                    cnt+=1
                ch=False
                ch2=False
    if ch:
        if my_bool:
            pass
        else:
            #print("ch",cnt,a)
            cnt+=1
    #print(cnt,a)
    if my_bool:
        break
print(cnt)

Measured memory_bytes: 39896
package main
 
import (
  "fmt"
)
 
func main() {
  var h, w, n int
  fmt.Scanf("%d", &h)
  fmt.Scanf("%d", &w)
  fmt.Scanf("%d", &n)
  
  ans := 0
  if h < w{
    ans = (n / w)
    if n % w != 0 {
      ans++
    }
  }
  if w <= h{
    ans = (n / h)
    if n % h != 0 {
      ans++
    }
  }
  
  fmt.Printf("%d\n", ans)
}

Measured memory_bytes: 1832
n,c,k = map(int,input().split())
t = []
for i in range(n):
  t.append(int(input()))

ans = 0
t.sort()
x = 0
p = 0
for ti in t:
  if x < ti:
    ans += 1
    p = 1
    x = ti+k
  else:
    if p < c:
      p += 1
    else:
      ans += 1
      p = 1
      x = ti+k
print(ans)

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

int main() {
  vector<int> vec(5);
  rep(i,5) {
    cin >> vec.at(i);
  }
  int ans;
  rep(i,5) {
    if (vec.at(i) == 0) ans =  i + 1;
  }
  cout << ans;
}

Measured memory_bytes: 3608
#include <stdio.h>

#define N 100
#define inf 2100000000
#define WHITE 0
#define BLACK 1
#define NIL -1

void dijkstra();
void initializeSingleSource();

int G[N][N];
int d[N];
int pi[N];
int color[N];
int num;

int main(){
  int v, vnum, connectv, i, j;
  
  scanf("%d", &num);

  for(i = 0; i < num; i++){
    for(j = 0; j < num; j++){
      G[i][j] = NIL;
    }
  }

  for(i = 0; i < num; i++){
    scanf("%d %d", &v, &vnum);
    getchar();
    //printf("v = %d, vnum = %d\n", v, vnum);
    for(j = 0; j < vnum; j++){
      scanf("%d", &connectv);
      scanf("%d", &G[v][connectv]);
      getchar();
      //printf("G[%d][%d] = %d\n", v, connectv, G[v][connectv]);
    }
  }
  dijkstra();

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

void  initializeSingleSource(){
  int i;
  
  for(i = 0; i < num; i++){
    d[i] = inf;
    pi[i] = NIL;
  }
  d[0] = 0;
}

void dijkstra(){
  int i, j, u, v, w, mincost;

  initializeSingleSource();
  
  while(1){
    mincost = inf;
    
    for(i = 0; i < num; i++){
      for(j = 0; j < num; j++){
	if(color[i] != BLACK && d[i] < mincost){
	  mincost = d[i];
	  u = i;
	}
      }
    }
    
    if(mincost == inf){
      break;
    }
    
    color[u] = BLACK;
    
    for(i = 0; i < num; i++){
      if(G[u][i] != NIL){
	if(color[i] != BLACK && d[u] + G[u][i] < d[i]){
	  pi[i] = u;
	  d[i] = d[u] + G[u][i];
	}
      }
    }
  }
  
}



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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Cake {
	Cake(): t(0), w(0), h(0) {}
	Cake(int t, int w, int h): t(t), w(w), h(h) {}
	int t, w, h;
	const bool operator<(const Cake& c) {
		if (t != c.t) return t < c.t;
		if (w * h != c.w * c.h) return w * h < c.w * c.h;
		return w < c.w;
	}
};

int main() {
	for (;;) {
		int n, w, h; cin >> n >> w >> h;
		if (!w) break;
		vector<Cake> v;
		v.push_back(Cake(0, w, h));
		for (int i = 1; i <= n; i++) {
			int p, s; cin >> p >> s; --p;
			Cake c = v[p]; v.erase(v.begin() + p);
			s %= c.w + c.h;
			if (s < c.w) {
				v.push_back(Cake(i, s, c.h));
				v.push_back(Cake(i, c.w - s, c.h));
			} else {
				s -= c.w;
				v.push_back(Cake(i, c.w, s));
				v.push_back(Cake(i, c.w, c.h - s));
			}

			sort(all(v));
		}
		sort(all(v), [](const Cake &a, const Cake &b) { return a.w * a.h < b.w * b.h; });
		for (int i = 0; i < v.size(); i++) {
			cout << v[i].w * v[i].h << " \n"[i + 1 == v.size()];
		}
	}
}



Measured memory_bytes: 3072
'use strict'

const n = 753

function main(input) {
  let nums = input.split('').map(v => ~~v)
  nums = nums.slice(0, -1)
  let ans = Number.MAX_SAFE_INTEGER

  for (let i = 0; i < nums.length - 2; i++) {
    let tmp = Math.abs(n - (nums[i] * 100 + nums[i + 1] * 10 + nums[i + 2]))
    ans = Math.min(tmp, ans)
  }

  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N); rep(i,N) cin >> H[i];
  int ans = 0;
  double deg = 1e9;
  rep(i,N){
    double d = T - 0.006 * H[i];
     if(abs(A-d) < abs(A - deg)){
       deg = d;
       ans = i;
     }
  }
  cout << ans + 1 << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int MAX = 1e5 + 9;
ll n,w,N[MAX],W[MAX],dp[100][MAX];
ll maxi(ll i,ll k){
    if(i==n){
        return 0;
    }
    if(dp[i][k])return dp[i][k];
    if(k<W[i])return dp[i][k]=maxi(i+1,k);
    else return dp[i][k]=max(maxi(i+1,k),N[i]+maxi(i+1,k-W[i]));
}




int main() {
    fast();
    cin >> n>>w;
    for (int i = 0; i < n; ++i) {
        cin>>W[i]>>N[i];
    }
    clr(dp,0);
    cout<<maxi(0,w);
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

void solve() {
	int N; cin >> N;
	ll sum = 0;
	vvll LG(N+1), RG(N+1);

	int lidx = 0, ridx = N;
	for (int i = 0; i < N; i++) {
		ll K, L, R; cin >> K >> L >> R; --K;
		if (L > R) {
			sum += R;
			LG[K].push_back(L-R);
			lidx++;
		} else if (L == R) {
			sum += L;
		} else {
			RG[K+1].push_back(R-L);
			ridx--;
			sum += L;
		}
	}
	
	//cout << sum << endl;

	priority_queue<ll> pq;
	for (int u = N-1; u >= lidx; u--) {
		for (auto &p : LG[u]) pq.push(p);
	}
	for (lidx--; lidx >= 0; lidx--) {
		for (auto &p : LG[lidx]) pq.push(p);
		if (!pq.empty()) {
			sum += pq.top(); pq.pop();
		}
	}
	
	//cout << sum << endl;
	while (!pq.empty()) pq.pop();
	
	for (int u = 0; u < ridx; u++) {
		for (auto &p : RG[u]) pq.push(p);
	}

	for (; ridx < N; ridx++) {
		for (auto &p : RG[ridx]) pq.push(p);
		if (!pq.empty()) {
			sum += pq.top(); pq.pop();
		}
	}

	cout << sum << endl;
}

void Main() {
	int T; cin >> T;
	while (T--) solve();
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 18308
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque

def main():
    N, M = input_nums()
    drinks = []
    for i in range(N):
        A, B = input_nums()
        drinks.append((A, B))
    drinks.sort()
    drinks = deque(drinks)
    cnt = 0
    money = 0
    while cnt < M:
        a, b = drinks.popleft()
        cnt += b
        money += a*b
    money -= (cnt-M)*a
    print(money)
    


if __name__ == '__main__':
    main()


Measured memory_bytes: 17612
n = gets.chomp.to_i
s = gets.chomp
hash = {
  "R"=> 0,
  "G"=> 0,
  "B"=> 0
}
s.split("").each do |c|
  hash[c] += 1
end
ans = hash["R"] * hash["G"] * hash["B"]
(0..n-3).each do |i|
  (i+1..n-2).each do |j|
    k = 2 * j - i
    next if k >= n
    ans -= 1 if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
  end
end

puts ans


Measured memory_bytes: 14564
#include <stdio.h>
int main(void){
	int sx,sy,tx,ty,i;
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	int dx=tx-sx,dy=ty-sy;
	for(i=0;i<dy;i++)printf("U");
	for(i=0;i<dx;i++)printf("R");
	for(i=0;i<dy;i++)printf("D");
	for(i=0;i<dx;i++)printf("L");
	printf("L");
	for(i=0;i<=dy;i++)printf("U");
	for(i=0;i<=dx;i++)printf("R");
	printf("DR");
	for(i=0;i<=dy;i++)printf("D");
	for(i=0;i<=dx;i++)printf("L");
	printf("U\n");
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;



void solve() {
    int n;
    cin >> n;
    n = ((n + 110) / 111) * 111;
    cout << n << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
        solve();



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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <class T>
struct Dijkstra {
  struct edge {
    int from, to; T cost;
    edge() {}
    edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  };
 
  int N;
  vector<vector<edge>> G;
  vector<T> dis;
  vector<int> prev;
  Dijkstra() {}
  Dijkstra(int N) : N(N), G(N), dis(N), prev(N, -1) {}
  void add_edge(int f, int t, T c) {
    G[f].emplace_back(f, t, c);
  }
  void shortest_path(int s, T INF) {
    fill(dis.begin(), dis.end(), INF);
    dis[s] = 0;
    using P = pair<T, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, s);
    while (!que.empty()) {
      P p = que.top(); que.pop();
      int v = p.second;
      if (dis[v] < p.first) continue;
      for (auto &e : G[v]) {
        if (dis[e.to] > dis[v] + e.cost) {
          dis[e.to] = dis[v] + e.cost;
          prev[e.to] = v;
          que.emplace(dis[e.to], e.to);
        }
      }
    }
  }
  vector<int> get_path(int t) {
    vector<int> path;
    for(; t != -1; t = prev[t]) path.push_back(t);
    reverse(path.begin(), path.end());
    return path;
  }
};

const ll INF = 1LL << 50;
ll n, m, s, t;
ll u[100010], v[100010], a[100010], b[100010];
vector<ll> ga[100010], gb[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> n >> m >> s >> t;
  s--, t--;
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--, v[i]--;
  }

  Dijkstra<ll> da(n), db(n);
  for (int i = 0; i < m; i++) {
    da.add_edge(u[i], v[i], a[i]);
    da.add_edge(v[i], u[i], a[i]);
    db.add_edge(u[i], v[i], b[i]);
    db.add_edge(v[i], u[i], b[i]);
  }
  da.shortest_path(s, INF);
  db.shortest_path(t, INF);
  vector<ll> ans;
  ll s = INF;
  for (int i = 0; i < n; i++) {
    s = min(s, da.dis[n - i - 1] + db.dis[n - i - 1]);
    ans.emplace_back(s);
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < n; i++) {
    cout << (ll)1e15 - ans[i] << endl;
  }

  return 0;
}

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

int main() {
	
	//vector<int> a(n);
	//cout << "test" << endl;

	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string ans="YES";


	int n;
	cin >> n;
	
	
	
	vector<int> a(n);
	
	int k=0;

	
	rep(i,n){
		cin >> a[i];
		if(a[i]!=i+1) k++;
	}
	if(k>2) ans="NO";
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
a=tuple(map(int,input().split()))
b=[]
for i in range(a[0]+1):
    b.append(list(map(int,input().split())))
ans=0
s=0
for j in range(a[0]+1)[1:a[0]+1]:
    for k in range(a[1]):
        s+=b[j][k]*b[0][k]
    s+=a[2]
    if s>0:
        ans+=1
    s=0
print(ans)

Measured memory_bytes: 3064