akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC111C - /\/\/\/
  // 偶奇で別々のvectorを用意。vector<pair<int, int> >でカウント数、値の順に保持
  // それぞれ降順sortして最初のカウント数と値を取得
  // 基本はそれぞれの最大値以外のカウントが書き換えする数　n/2 - 最大カウント数
  // ただし、偶奇のカウント最大値が同じ値のとき、全ての値を同じにしてしまうため例外処理が必要
  // 二番目に大きいカウントのpairを取得。
  int n; cin >> n;
  vector<pair<int, int> > ev(1e5+1, pair<int, int>());
  vector<pair<int, int> > od(1e5+1, pair<int, int>());
  REP(i, n){
    int tmp; cin >> tmp;
    if(i%2 == 0){
      ev[tmp].first++;
      ev[tmp].second = tmp;
    }else{
      od[tmp].first++;
      od[tmp].second = tmp;
    }
  }
  sort(ev.begin(), ev.end(), greater<pair<int, int> >());
  sort(od.begin(), od.end(), greater<pair<int, int> >());
  int ans;
  if(ev[0].second != od[0].second){
    ans = n - ev[0].first - od[0].first;
  }else{
    ans = n - max(ev[0].first+od[1].first, ev[1].first+od[0].first);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
  int i,sum;
  char num[1001];

  for(;;){
    scanf("%s", &num);
    if(num[0] == '0') break;
    
    sum = 0;
    for(i=0;num[i]!='\0';i++)
      sum += num[i] - '0';
    printf("%d\n", sum);
  }
  
  return 0;
}


Measured memory_bytes: 2076
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   string s; cin>>s;
   string ans="Yes";
   for(int i=0;i<s.length();i++){
       if(i%2==1){
           if(s[i]=='R'){
               ans="No";
               break;
           }
       }
       else{
           if(s[i]=='L'){
               ans="No";
               break;
           }
       }
   }
   cout<<ans<<endl;
   return 0;
}

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

using namespace std;

void solve()
{
	int N;
	cin >> N;
	string s = "";
	for(int i=0;i<N;i++)
	{
		int x,y;
		cin >> x >> y;
		if(x==y)
			s += "1";
		else
			s += "0";
	}
	for(int i=1; i<N-1;i++)
	{
		if(s[i]-'0' && s[i-1]-'0' && s[i+1]-'0')
		{
			cout << "Yes";
			return;
		}
	}
	cout<<"No";
}


int main() {
    int t;
    // cin>>t;
	// while(t--)
		solve();
	return 0;

}

Measured memory_bytes: 3584
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left,int mid, int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      j++;
    }
  }
}

void mergeSort(int A[],int n,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int main(){
  int A[MAX],n,i;
  cnt=0;
  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A,n,0,n);

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

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

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

    long long A,B; cin >> A >> B;
    map<int,int> factor;
    long long g=__gcd(A,B);
    for(int i=2;(long long)i*i<=g;i++){
        while(g%i==0){
            factor[i]++;
            g/=i;
        }
    }
    if(g>1) factor[g]++;
    cout << factor.size()+1 << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    int n;
    int a;
    int b;
    String s;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        s = sc.next();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        char[] sList = s.toCharArray();
        int ab = a + b;
        int b_rank = 1;
        int cur = 0;

        for (int i = 0; i < sList.length; i++) {
            if (sList[i]=='a' && cur < ab) {
                cur++;
                System.out.println("Yes");
            } else if (sList[i]=='b' && b >= b_rank && cur < ab) {
                cur++;
                b_rank++;
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 34788
n = int(input())
ans = [0] * n
cnt = 0
k = []
x = 1
while x ** 2 < n:
    y = 1
    s_x = x ** 2
    while y ** 2 < n:
        z = 1
        s_y = y ** 2
        while z ** 2 < n:
            ans_tmp = s_x + s_y + z ** 2 + x * y + y * z + z * x
            if ans_tmp <= n:
                ans[ans_tmp - 1] += 1
            cnt += 1
            z += 1
        y += 1
    x += 1

for i in range(n):
    print(ans[i])


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

int main()
{
  int coins_1yen, price,result;
  cin >>  price >> coins_1yen;
  result=price%500;
  
  if(result <= coins_1yen)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

#define MP make_pair 
#define N 200005
typedef long long LL;
const int mod = 1e9 +7;

int n, X;
LL sum[N];
struct data
{	
	LL l, r, b;
	LL val() {return r*(X-b)-l*(0-b);}
	bool operator < (const data &t)const
	{
		return r*(X-b)-l*(0-b) > t.r*(X-t.b)-t.l*(0-t.b);
	}
}d[N];

LL o;

bool check(LL s)
{
	int num = s / X;
	if (s % X == 0)
	{
		LL v = o;
		for (int i = 1; i <= num; ++i)
			v += d[i].val();
		return v >= 0;	
	}
	else
	{
		LL r = s % X, v = o;
		for (int i = 1; i <= n; ++i)
		{
			if (i <= num) v = o + sum[num+1] - d[i].val();
		    else v = o + sum[num]; 
		    v -= d[i].l * (0 - d[i].b);
			if (r >= d[i].b) v += d[i].r * (r - d[i].b);
			else v += d[i].l * (r - d[i].b);
			if (v >= 0) return true;
		}
	}
	return false;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	scanf("%d%d", &n, &X);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%lld%lld%lld", &d[i].b, &d[i].l, &d[i].r);
		o += d[i].l * (0 - d[i].b);
	}

	sort(d+1, d+n+1);
	for (int i = 1; i <= n; ++i) 
	{
	 	sum[i] = sum[i-1] + d[i].val();
	 //	cout << d[i].b << " "<< d[i].l << " " <<d[i].r << " " << d[i].val() << endl;
    }
    //cout << o <<endl;
    //check(115);
    //return 0;
	LL lo = 0, hi = 1LL*n*X, mid;
	while (lo < hi)
	{
		mid = (lo + hi) >> 1;
		if (check(mid)) hi = mid;
		else lo = mid + 1;
	}
	printf("%lld\n", lo);
	return 0;
}

Measured memory_bytes: 6400
#include "bits/stdc++.h"
using namespace std;

const int N=1e6+20,MOD=1e9+7;

int n,f[N],ie[N];

int mul(int a,int b) {return (1ll*a*b)%MOD;}

int power(int a,int b)
{
	int num=a,ans=1;
	while(b)
	{
		if(b&1) ans=mul(ans,num);
		b>>=1;
		num=mul(num,num);
	}
	return ans;
}

int inverse_euler(int n)
{
	return power(n,MOD-2);
}

int ncr(int n,int r)
{
	return mul(f[n],mul(ie[r],ie[n-r]));
}

void precompute()
{
	f[0]=1;
	for(int i=1;i<N;i++) f[i]=mul(f[i-1],i);
	for(int i=0;i<N;i++) ie[i]=inverse_euler(f[i]);
}

int main()
{
	//https://codeforces.com/contest/560/problem/E
	precompute();

	cin>>n;
	long long temp=0;
	for(int i=1;i<=n;i++)
	{
		temp+=mul(power(8,n-i),ncr(n,i));
		temp%=MOD;
	}
	temp=(temp*2)%MOD;
	temp=(temp+power(8,n))%MOD;
	cout<<(power(10,n)-temp+MOD)%MOD;
}

Measured memory_bytes: 11320
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>


using namespace std;
using ll = long long;

string str;

bool a, b;

int main()
{
	cin >> str;
	sort(str.begin(), str.end());
	if (str[0] == str[1] && str[2] == str[3] && str[0] != str[3])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e3 + 5;
pair<ll, ll> a[N];
ll dp[N][N];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        //freopen("VLJUM.INP", "r", stdin);
        //freopen("VLJUM.OUT", "w", stdout);
        ll n;
        cin >> n;
        for (int i = 1; i <= n; i++){
                cin >> a[i].first;
                a[i].second = i;
        }
        sort(a + 1, a + n + 1, greater<pair<ll, ll>>());
        for (int i = 1; i <= n; i++){
                for (int j = 0; j <= i; j++){
                        if (j > 0) dp[i][j] = dp[i - 1][j - 1] + a[i].first * abs(a[i].second - j);
                        if (j < i) {
                                dp[i][j] = max(dp[i - 1][j] + a[i].first * abs(a[i].second - (n - (i - j - 1))), dp[i][j]);
                        }
                }
        }
        ll ans = 0;
        for (int i = 1; i <= n; i++){
                ans = max(ans, dp[n][i]);
        }
        cout << ans;
}


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

int main(void) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x = i;
        if (x%3 == 0) {
            cout << " " << i;
        }
        else {
            while (x > 0) {
                if (x%10 == 3) {
                    cout << " " << i;
                    break;
                }
                else {
                    x /= 10;
                }
            }
        }
    }
    cout << endl;
    return 0;
}


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

#define ankit_2305 cerr<<"\nTime taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<" sec\n";
#define START clock_t
#define TIMER time_p=clock();
#define ll long long

#define MOD 1000000007

using namespace std;


int main(){
    START TIMER
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	string s;
	cin>>s;
	if(s[2] == s[3] && s[4] == s[5])
		cout<<"Yes\n";
	else
		cout<<"No\n";
    ankit_2305
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll A,B,C;
int main(){
    cin>>A>>B>>C;
    if( (A==B && B!=C) || (A==C && B!=C) || (B==C&&A!=B) ){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/30 08:39:09 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	int	n;
	cin >> n;

	vector<int>	V(n);
	vector<int>	dp(n);
	rep(i, n)
		cin >> V.at(i);
	dp.at(1) = abs(V.at(1) - V.at(0));
	for (int i = 2; i < n; i++)
		dp.at(i) = min(dp.at(i - 2) + abs(V.at(i) - V.at(i - 2)), dp.at(i - 1) + abs(V.at(i) - V.at(i - 1)));
	cout << dp.at(n - 1) << endl;
}
// END

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


Measured memory_bytes: 1024
import java.util.Scanner;

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

    int n = sc.nextInt();
    int[] a = new int[n];

    for (int i = 0; i < n - 1; i++) {
      a[sc.nextInt() - 1]++;
    }

    for (int result : a) {
      System.out.println(result);
    }
  }
}


Measured memory_bytes: 56176
from collections import deque
r,c =map(int,input().split())
G = [input() for _ in range(r)]
black = 0
for i in range(r):
    for j in range(c):
        if G[i][j] == "#":
            black += 1
# print(black)

M = [[10**7 for _ in range(c)] for i in range(r)]
queue = deque([(0,0)])
M[0][0] = 0
while len(queue) != 0:
    now = queue.popleft()
    dxy = [(0,1),(0,-1),(1,0),(-1,0)]
    for p in dxy:
        nexte = (now[0]+p[0],now[1]+p[1])
        if nexte[0]<0 or nexte[0]>=r or nexte[1]<0 or nexte[1]>=c:
            continue
        else:
            if G[nexte[0]][nexte[1]] == ".":
                if M[nexte[0]][nexte[1]] > M[now[0]][now[1]] + 1:
                    M[nexte[0]][nexte[1]] = M[now[0]][now[1]] + 1
                    queue.append(nexte)
if M[r-1][c-1] == 10**7:
    print("-1")
else:
    print(r*c-1 - M[r-1][c-1] - black) 

Measured memory_bytes: 40688
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,X; cin >> N >> X;
    vector<ll> m(N); for(auto& in:m) cin >> in;
    res = N; X -= accumulate(m.begin(),m.end(),0);
    res += X / (*min_element(m.begin(), m.end()));
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# Traveling
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, t: "List[int]", x: "List[int]", y: "List[int]"):
    t.insert(0, 0)
    x.insert(0, 0)
    y.insert(0, 0)
    print(trabelable(N, t, x, y))

def trabelable(N, t, x, y):
    for i in range(N):
        delta_t = t[i+1] - t[i]
        dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i])
        if delta_t < dist:
            return NO
        if delta_t % 2 != dist % 2:
            return NO
    return YES

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]" 
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        t[i] = int(next(tokens))
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, t, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 11636
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<ll> xs(n), ys(n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        xs[i] = a+b;
        ys[i] = a-b;
    }
    ll l = *min_element(xs.begin(),xs.end());
    ll r = *max_element(xs.begin(),xs.end());
    ll u = *min_element(ys.begin(),ys.end());
    ll d = *max_element(ys.begin(),ys.end());
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = max({ans, abs(l-xs[i]), abs(r-xs[i]), abs(u-ys[i]), abs(d-ys[i])});
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

/*
テストケース全てに目を通す
テストケースが2個以下だったらなんかある
N最小のコーナーケースがないか調べる
制約をしっかりと確認する（1からNまでの順列、全て異なる値などの制約も含め）
制約のn*mとn,mを読み違えない
操作の逆順を考える
オーバーフローしないか確かめる
Codeforcesではscanfを使う
modの引き算には+modをする
エラー出力は消す
エラー出力を消せ！！！！！
cout << fixed;
cout << setprecision(n) << ans;
 */

int main() {
    int n;
    cin >> n;
    ll a[n];
    ll s[n];
    rep(i,n){
        ll x;
        cin >> x;
        a[i]=x;
        if(i==0)s[i]=a[i];
        else s[i]=s[i-1]+a[i];
    }
    vector<ll> ans;
    rep(i,n-1){
        ans.pb(abs(s[n-1]-2*s[i]));
    }
    sort(all(ans));
    cout << ans[0];



    
}

/*
*/


Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=2e5+10;
char s[maxn];
int vis[2][maxn],p[maxn];
int l[maxn],r[maxn],Begin[maxn],Next[maxn<<1],to[maxn<<1],w[maxn<<1],e;
inline void add_edge(int x,int y,int z){
	to[++e]=y;
	Next[e]=Begin[x];
	Begin[x]=e;
	w[e]=z;
}
queue<int> q;
int main(){
	int n=read(),m=read();
	scanf("%s",s+1);
	REP(i,1,m) l[i]=read(),r[i]=read();
	REP(i,1,m){
		vis[s[l[i]]-'A'][r[i]]++,vis[s[r[i]]-'A'][l[i]]++;
		add_edge(l[i],r[i],s[l[i]]-'A'),add_edge(r[i],l[i],s[r[i]]-'A');
	}
	int cnt=n;
	REP(i,1,n){
		if(vis[0][i]>0 && vis[1][i]>0) continue;
		q.push(i),p[i]=1;
	}
	while(!q.empty()){
		int u=q.front();q.pop(),--cnt;
		for(int i=Begin[u];i;i=Next[i]) if(!p[to[i]]){
			--vis[w[i]][to[i]];
			if(!vis[w[i]][to[i]]) q.push(to[i]),p[to[i]]=1;
		}
	}
	printf("%s\n",cnt?"Yes":"No");
    return 0;
}


Measured memory_bytes: 10112
import itertools
import math
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    town = [LI() for _ in range(n)]
    way = list(itertools.permutations(range(n), n))
    ans = 0
    for w in way:
        for i in range(n-1):
            x1 = town[w[i]][0]
            y1 = town[w[i]][1]
            x2 = town[w[i+1]][0]
            y2 = town[w[i+1]][1]
            ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)
    ans /= len(way)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13988
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

int main() {
	vector<vector<int>> b(3, vector<int>(3));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> b[i][j];
		}
	}
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (b[j][k] == a) b[j][k] = -1;
			}
		}
	}
	auto f = [&]() {
		cout << "Yes" << endl;
		exit(0);
	};
	for (int i = 0; i < 3; i++) {
		bool flag = true;
		for (int j = 0; j < 3; j++) {
			flag &= b[i][j] == -1;
		}
		if (flag) f();
	}
	for (int i = 0; i < 3; i++) {
		bool flag = true;
		for (int j = 0; j < 3; j++) {
			flag &= b[j][i] == -1;
		}
		if (flag) f();
	}
	bool flag = true;
	for (int i = 0; i < 3; i++) {
		flag &= b[i][i] == -1;
	}
	if (flag) f();
	flag = true;
	for (int i = 0; i < 3; i++) {
		flag &= b[i][2 - i] == -1;
	}
	if (flag) f();
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.strip().to_i
trump = {"S" => Array.new(13){0},
		 "H" => Array.new(13){0},
		 "C" => Array.new(13){0},
		 "D" => Array.new(13){0}}
n.times do
	inputs = gets.strip().split(" ")
	symbol = inputs[0]
	num = inputs[1].to_i
	trump[symbol][num-1] = 1
end

trump.each do |symbol, array|
	for i in 0..12
		puts "#{symbol} #{i+1}" if array[i] == 0
	end
end


Measured memory_bytes: 6876
#!/usr/bin/ruby
h,w=gets.split.map(&:to_i)
m=$<.map{|e|e.chomp[1..-2]}
2.times{|i|h.times{|y|
	if i==0
		if y%2==0
			puts '#'*(w-1)+'.'
		else
			puts '#'+m[y]+'.'
		end
	else
		if y%2==0
			puts '.'+m[y]+'#'
		else
			puts '.'+'#'*(w-1)
		end
	end
};puts}

Measured memory_bytes: 3452
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string s;
int l;
int main()
{
    cin>>s;
    l=s.size();
    for(register int i=0;i<l;i++)
    {
        if(s[i]=='C')
        {
            for(register int j=i+1;j<l;j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 764
class Dice(object):

    def __init__(self, num):
        self.num = num

    def rotate_S(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rotate_N(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rotate_W(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]

    def rotate_E(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def get_right_num(self, a, b):
        top_index = self.num.index(a) + 1
        front_index = self.num.index(b) + 1
        if [top_index, front_index] in [[2, 3], [3, 5], [5, 4], [4, 2]]:
            return self.num[0]
        elif [top_index, front_index] in [[1, 4], [4, 6], [6, 3], [3, 1]]:
            return self.num[1]
        elif [top_index, front_index] in [[1, 2], [2, 6], [6, 5], [5, 1]]:
            return self.num[2]
        elif [top_index, front_index] in [[1, 5], [5, 6], [6, 2], [2, 1]]:
            return self.num[3]
        elif [top_index, front_index] in [[1, 3], [3, 6], [6, 4], [4, 1]]:
            return self.num[4]
        elif [top_index, front_index] in [[2, 4], [4, 5], [5, 3], [3, 2]]:
            return self.num[5]

dice = Dice(map(int, raw_input().split()))
Q = input()
for q in range(Q):
    num_set = map(int, raw_input().split())
    print dice.get_right_num(num_set[0], num_set[1])

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

using namespace std;
#define int long long
typedef pair <int, int> ii;

const int oo = 1e16;
vector <int> digit(17, 0);
int p10[30], dem, S;

int num(vector <int> d) {
	int ret = 0;
	for (int i = dem; i >= 1; --i) ret = ret * 10 + d[i];
	return ret;
}
int sum(int a) {
	int ret = 0;
	while (a) {
		ret += a % 10;
		a /= 10;
	}
	return ret;
}

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

	p10[0] = 1;
	for (int i = 1; i <= 15; ++i) p10[i] = p10[i - 1] * 10;
	int k;
	cin >> k;
	cout << 1 << endl;
	int cur = 1;
	for (int turn = 2; turn <= k; ++turn) {
		int nxt = -1;
		digit = vector <int>(17, 0);
		int tmp = cur + 1; dem = S = 0;
		while (tmp) {
			S += tmp % 10;
			digit[++dem] = tmp % 10;
			tmp /= 10;
		}
		for (int i = 1; i <= dem; ++i) {
			for (int j = digit[i]; j < 10; ++j) {
				digit[i] = j;
				if (nxt == -1 || nxt * sum(num(digit)) > num(digit) * sum(nxt)) {
					nxt = num(digit);
				}
			}
		}
		
		cur = nxt;
		cout << cur << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100];
int main(){

  int n,count=0;
  cin>>n;
  for(int i=1;i<(n+1);i++){
    cin>>a[i];
	if(a[i]%2 && i%2)
      count++;
  }
  cout<<count;
}


Measured memory_bytes: 3620
# from pprint import pprint
# import math
# import collections

# n = int(input())
a, b, c = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))

s = 0
mods = []
while True:
    s += a

    mod = s % b

    if mod == c:
        res = 'YES'
        break
    elif mod in mods:
        res = 'NO'
        break

    mods.append(mod)

print(res)


Measured memory_bytes: 9168
#include<stdio.h>
int main()
{
    int h,a,b,c;
    scanf("%d %d",&h,&a);
    if(h<=a){
        printf("1");
    }
    else if(h>a)
    {
        b=h/a;
        c=h%a;

        if(c!=0)
            b++;
 printf("%d\n",b);
    }

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> 
#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;

int main(){
    int N,M;cin>>N>>M;
    vector<int> P(M),Y(M);
    vector<p> city(M);
    map <int,int> mprefecture;
    for(int i = 0; i < M; i++)
    {
        cin>>P[i]>>Y[i];
        city[i] = make_pair(Y[i],i);//year, order
        mprefecture[i] = P[i];
    }
    sort(city.begin(),city.end());
    map<int ,int> p_count;
    vector<p> answer(M);
    for(int i = 0; i < city.size(); i++)
    {
        int prefecture = mprefecture[city[i].second];
        p_count[prefecture]++;
        answer[city[i].second] = make_pair(prefecture,p_count[prefecture]);
    }

    for(int i = 0; i < answer.size(); i++)
    {
        cout<<setfill('0')<<right<<setw(6)<<answer[i].first<<right<<setw(6)<<answer[i].second<<endl;
    }
    
}

Measured memory_bytes: 14720
# https://atcoder.jp/contests/abc094/tasks/arc095_a

n = gets.to_i
nums = gets.split.map(&:to_i)
sorted_nums = nums.sort
orig_medians = sorted_nums[sorted_nums.size / 2 - 1, 2]
has_two_larger_median = nums.count(orig_medians[1]) > 1

nums.each do |i|
  puts i > orig_medians[0] ? orig_medians[0] : orig_medians[1]
end 


Measured memory_bytes: 23396
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int flag=1;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i]){
			flag=0;
			break;
		}
	}
	if(s.size()!=t.size()-1)
		flag=0;
	if(flag)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	vector<ll>a;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	vector<ll>b;
	ll m=n;
	for(int i=n-1;i>=0;i--){
		if(a[i]==i+1){
			b.push_back(a[i]);
			a.erase(a.begin()+i);
			m--;
			i=m;
			continue;
		}
		if(i==0){
		cout << -1;
		return 0;
		}
	}
	for(int i=n-1;i>=0;i--){
		cout << b[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

int main() {
	int H,W;
	char masu[50][50],ans=0,c=0;
	bool flag=true;
	cin>>H>>W;
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			cin>>masu[i][j];
		}
	}
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			if(masu[i][j]=='#'){
				if(i>0)
				{
					if(masu[i-1][j]=='#')flag=true;
				}
				if(i<H-1)
				{
					if(masu[i+1][j]=='#')flag=true;
				}
				if(j>0)
				{
					if(masu[i][j-1]=='#')flag=true;
				}
				if(j<W-1)
				{
					if(masu[i][j+1]=='#')flag=true;
				}
				if(flag)c++;
				flag=false;
				ans++;
				}
		}
	}
	if(ans==c)cout<<"Yes";
	else cout<<"No";
	}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
k, n = map(int,input().split())
a = [int(i) for i in input().split()]

a.sort()
ans1 = a[-1] - a[0]
ans2 = 10 ** 10
for i in range(n - 1):
    #print(i, i + 1)
    tmp = a[i] + (k - a[i + 1])
    if tmp < ans2:
        ans2 = tmp
print(min(ans1, ans2))


Measured memory_bytes: 24564
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int N;
	int T[100];
	scanf("%d", &N);
	for(int i=0;i<N;i++){
		scanf("%d",&T[i]);
	}
	int M;
	int P[100];
	int X[100];
	scanf("%d", &M);
	for(int i=0;i<M;i++){
		scanf("%d %d", &P[i], &X[i]);
	}
	long long sum = 0;
	for(int i=0;i<N;i++){
		sum += T[i];
	}
	for(int i=0;i<M;i++){
		printf("%lld\n",sum-T[P[i]-1]+X[i]);
	}


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int h,w,k,ans=INF;
string s[11];
signed main(){
	cin>>h>>w>>k;
	rep(i,h)cin>>s[i];
	rep(i,1<<h){
		vector<int> v;
		int bit[11]={0},bou=0;
		rep(j,h){
			if(i&(1<<j)){
				bit[j]=1;
			}
		}
		/*cout<<i<<":";
		rep(j,h)cout<<bit[j];
		cout<<endl;*/
		bit[h]=INF;
		rep(j,h){
			if(bit[j]!=bit[j+1])v.push_back(0);
		}
		//cout<<"test:"<<v.size()<<endl;
		
		int contflag=0;
		rep(j,w){
			int cnt=0,index=0;
			vector<int> v2;
			rep(l,h){
				//cout<<index<<endl;
				if(bit[l]!=bit[l+1]){
					if(s[l][j]=='1')cnt++;
					if(cnt>k){
						contflag=1;
						break;
					}
					v[index]+=cnt;
					v2.push_back(cnt);
					cnt=0;
					index++;
				}
				else{
					if(s[l][j]=='1')cnt++;
				}
			}
			if(contflag)break;
			
			int flag=0;
			rep(l,v.size()){
				if(v[l]>k)flag=1;
			}
			if(flag){
				bou++;
				rep(l,v.size()){
					v[l]=v2[l];
				}
			}
		}
		//cout<<v.size()<<endl;
		if(!contflag)ans=std::min(ans,bou+(int)v.size()-1);
		//if(bou+(int)v.size()-1==3)cout<<bou<<" "<<v.size()-1<<endl;
	}
	cout<<ans<<endl;
	
}

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

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val d = readint()
    val c = readints()
    val s = Array(d){IntArray(26)}
    for(i in 0 until d){
        s[i] = readints().toIntArray()
    }
    val ans = IntArray(d)

    fun score() : Long{
        val t = IntArray(26)
        var sum = 0L
        for(i in 0 until d){
            sum += s[i][ans[i]]
            t[ans[i]] = i
            for(j in 0 until 26){
                sum -= c[j] * (i - t[j])
            }
        }
        return sum
    }

    for(i in 0 until d){
        var ma = 0
        var mai = 0
        for(j in 0 until 26){
            if(ma < s[i][j]){
                ma = s[i][j]
                mai = j
            }
        }
        ans[i] = mai
    }

    var ma = score()
    val rand = Random()

    repeat(300){
        for(i in 0 until d){
            val t = ans[i]
            ans[i] = rand.nextInt(26)
            val m = score()
            if(m > ma){
                ma = m
            }
            else{
                ans[i] = t
            }
        }
    }

    for(i in 0 until d){
        println(ans[i] + 1)
    }
}



fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}


Measured memory_bytes: 53300
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	rep(i,0,19){
		char c=getchar();
		if(i==5||i==13)putchar(' ');
		else putchar(c);
	}
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int m = scan.nextInt();
		int f = scan.nextInt();
		int b = scan.nextInt();
		if(m+f < b){
			System.out.println("NA");
		}else if(m-b >= 0) {
			System.out.println(0);
		}else {
			System.out.println(b-m);
		}
	}
}



Measured memory_bytes: 26320
k=int(input())
t = []
x=1
lim=1000005
mod = 0
ans=0
for i in range(lim):
	ans+=1
	t+=[x%k]
	x = (x%k * 10%k)%k
	mod = (mod + (7%k * t[i])%k)%k
	if mod == 0:
		break
if mod==0: print(ans)
else: print(-1)


Measured memory_bytes: 48628
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1e9+7;
const int maxn=510;

int main(){
    string str;
    cin>>str;
    for(int i=0;i<str.length();i++){
        if(str[i]==',') cout<<' ';
        else cout<<str[i];
    }
    cout<<endl;
    return 0;
}

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

const int N = 1e5 + 10;
int n, a[3 * N];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < 3 * n; i++) {
    scanf("%d", a + i);
  }
  sort(a, a + 3 * n);
  int pt = 3 * n - 2;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[pt];
    pt -= 2;
  }
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 1408
#include<iostream>

using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==7&&b==5&&c==5)
    cout<<"YES"<<endl;
  else if(a==5&&b==7&&c==5)
    cout<<"YES"<<endl;
  else if(a==5&&b==5&&c==7)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	while(cin>>n,n){
		int in[50][30]={0};
		rep(i,n){
			int a;
			cin>>a;
			rep(j,a){
				int b;
				cin>>b;
				in[i][b-1]=true;
			}
		}
		vvi dp(n,vi(31,0));
		rep(i,n)dp[i][0]=(ll)1<<i;
		int out=-1;
		ll w=((ll)1<<n)-1;
		rep(i,30){
			ll t=-1;
			rep(j,n)if(in[j][i]){
				if(t+1)dp[j][i+1]=t;
				else{
					t=0;
					rep(k,n)if(in[k][i])t|=dp[k][i];
					if(t==w){out=i+1;break;}
					dp[j][i+1]=t;
				}
			}else dp[j][i+1]=dp[j][i];
			if(out+1)break;
		}
		cout<<out<<endl;
		//rep(i,n){rep(j,5)cout<<" "<<dp[i][j];cout<<endl;}
	}
}

Measured memory_bytes: 1232
import java.util.*;class Main{public static void main(String[]z){int l,e,t,a,b;for(Scanner s=new Scanner(System.in);s.hasNext();System.out.println(l))for(a=s.nextInt(),b=s.nextInt(),l=a>b?a:b,e=a<b?a:b;e>0;l=e,e=t)t=l%e;}}

Measured memory_bytes: 12000
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <limits>
using namespace std;
#define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 2e5+10;
int n, x, a[N], s[N];

int rangesum(int l, int r) {
	return s[r] - (l > 0 ? s[l-1] : 0);
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n >> x;
    REP(i, n) cin >> a[i];
    s[0] = a[0];
    FOR(i, 1, n-1) s[i] = s[i-1]+a[i];
    int ans = numeric_limits<int>::max();
    FOR(trips, 1, (n+1)/2) {
    	int m = 5;
    	int cur = m*rangesum(n-2*trips, n-1);
    	int idx = n-2*trips;
    	while(idx > 0) {
    		m += 2;
    		cur += m*rangesum(idx-trips, idx-1);
    		idx = idx-trips;
    	}
    	cur += (n+trips)*x;
    	if(cur > 0) ans = min(ans, cur);
    }
    cout << ans << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)


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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long 
#define sqr(x) ((x)*(x))
#define pi acosl(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;

void solve(){
    int n;
    scanf("%d",&n);
    int cnt=0;
    for(int i = 0;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if(x==y)cnt++;
        else cnt=0;
        if(cnt==3){
            printf("Yes\n");
            return ;
        }
    }
    printf("No\n");
}
int main(){
    int t=1;
    int T=1;
    while(t--){
        solve();
    }
}
/*
100
5
5 4
4 2
4 2 3
5 4 2 3 1
*/


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

const int MAXN = 300010;
typedef long long LL;
const LL NINF = 0xcfcfcfcfcfcfcfcfLL;
int n, Q;
LL A[MAXN], L[MAXN], R[MAXN];
LL g[MAXN], pre[MAXN];
bool cmpat(int j, int k, LL x) {
	return g[j] - g[k] <= x * (j - k);
}
bool cmpsl(int i, int j, int k) {
	return (g[i] - g[j]) * (j - k) >= (g[j] - g[k]) * (i - j);
}
int st[MAXN], top;
void moveto(int x) {
	while (top > 1 && cmpat(st[top], st[top - 1], x)) --top;
}
void push(int i) {
	while (top > 1 && cmpsl(i, st[top], st[top - 1])) --top;
	st[++top] = i;
}
void solve(LL * A, LL * f) {
	st[top = 1] = 0;
	for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + A[i];
	for (int i = 1; i <= n; ++i) {
		moveto(i);
		int j = st[top];
		f[i] = f[j] + (i - j) * (i - j + 1ll) / 2 - pre[i] + pre[j];
		f[i] = std::max(f[i], f[i - 1]);
		g[i] = f[i] + pre[i] + i * (i - 1ll) / 2;
		push(i);
	}
}
LL ansl[MAXN], flg[MAXN];
inline int rx(int x, int l, int r) { return r - x + l; }
void solve(int l, int r) {
	if (l > r) return ;
	if (l == r) return (void) (ansl[l] = L[l - 1] + R[r + 1] - A[l] + 1);
	int mid = l + r >> 1;
	solve(l, mid); solve(mid + 1, r);
	pre[l - 1] = pre[r + 1] = 0; flg[l - 1] = flg[r + 1] = NINF;
	for (int i = l; i <= r; ++i) pre[i] = pre[i - 1] + A[i];
	top = 0;
	for (int i = l - 1; i <= mid; ++i) {
		g[i] = L[i] + pre[i] + i * (i - 1ll) / 2;
		push(i);
	}
	for (int i = mid + 1; i <= r; ++i) {
		moveto(i);
		int j = st[top];
		LL t = R[i + 1] + L[j];
		t += (i - j) * (i - j + 1ll) / 2 - pre[i] + pre[j];
		flg[i] = t;
	}
	for (int i = r; i > mid; --i)
		ansl[i] = std::max(ansl[i], flg[i] = std::max(flg[i], flg[i + 1]));
	top = 0;
	for (int i = l; i <= r; ++i) pre[i] = pre[i - 1] + A[rx(i, l, r)];
	for (int i = r + 1; i > mid; --i) {
		int j = rx(i, l, r);
		g[j] = R[i] + pre[j] + j * (j - 1ll) / 2;
		push(j);
	}
	for (int i = mid; i >= l; --i) {
		int j = rx(i, l, r);
		moveto(j);
		int k = st[top], nk = rx(k, l, r);
		LL t = L[i - 1] + R[nk];
		t += (j - k) * (j - k + 1) / 2 - pre[j] + pre[k];
		flg[i] = t;
	}
	for (int i = l; i <= mid; ++i)
		ansl[i] = std::max(ansl[i], flg[i] = std::max(flg[i], flg[i - 1]));
}
#define rev(X) std::reverse(X + 1, X + 1 + n)
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	solve(A, L); rev(A);
	solve(A, R); rev(A); rev(R);
	memset(ansl, 0xcf, sizeof ansl);
	solve(1, n);
	std::cin >> Q;
	while (Q --> 0) {
		int x, v; std::cin >> x >> v;
		LL ans = std::max(L[x - 1] + R[x + 1], ansl[x] + A[x] - v);
		std::cout << ans << std::endl;
	}
	return 0;
}


Measured memory_bytes: 20224
from math import log2
l = int(input())
t = int(log2(l))
g = [[] for _ in range(t + 1)]
for i in range(t):
    g[i].append((i + 1, 0))
    g[i].append((i + 1, 2 ** i))
l -= 2 ** t
c = 2 ** t
for i in range(t):
    if (l >> i) & 1:
        g[i].append((t, c))
        c += 2 ** i
n, m = t + 1, 0
for i in range(t):
    m += len(g[i])
print(n, m)
for i in range(t):
    for node, cost in g[i]:
        print(i + 1, node + 1, cost)

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

int main(){
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  cout << A + B + C + D - min(min(A, B), min(C, D)) + E + F - min(E , F) << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
string A,B;
int k;
map<string,int> mem;

string add(string a,int l,int r,int v){
  for(int i=l;i<=r;i++) a[i]=(a[i]-v+10)%10;
  return a;
}

int dfs(int idx,string dial){
  if(idx==k)return 0;
  if(mem.count(dial)) return mem[dial];
  int res=1e9;
  for(int i=idx;i<=k;i++)
    res=min(res,dfs(idx+1,add(dial,idx,i,dial[idx]))+(dial[idx]!=0));
  return mem[dial]=res;
}

int main(){

  while(cin>>k,k){
    cin>>A>>B;
    for(int i=0;i<k;i++) A[i]=(A[i]-B[i]+10)%10;
    mem.clear();
    cout <<dfs(0,A)<<endl;
    
  }  
  return 0;
}

Measured memory_bytes: 4284
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define M 998244353
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i, o = 0;
    cin>>n;
    ll a[n], b[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n;i++)
        cin>>b[i];
    multiset <pair<ll,ll>> mt, mt2;

    for(i=0;i<n;i++)
    {
        mt2.insert(mp(a[i],b[i]));
        mt.insert(mp(b[i], a[i]));
    }
    while(mt.size())
    {
        //cout<<"a"<<endl;
        auto ele = *mt.begin();
        mt.erase(mt.begin());
        mt2.erase(mt2.find(mp(ele.ss,ele.ff)));
        //cout<<ele.ff<<" "<<ele.ss<<endl;
        if(ele.ff >= ele.ss)
        {
            continue;
        }
        o++;
        if(mt2.size() == 0)
        {
            o = n;
            break;
        }
        auto itr = mt2.upper_bound(mp(ele.ff, 1000000001));
        if(itr == mt2.begin())
        {
            o = n;
            break;
        }
        itr--;
        auto ele2 = *itr;
        mt.erase(mt.find(mp(itr->ss, itr->ff)));
        mt2.erase(itr);
        mt.insert(mp(ele2.ss,ele.ss));
        mt2.insert(mp(ele.ss, ele2.ss));

    }
    if(o <= n-2)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll L[100];
bool seen[100];

ll Lucas(int N){
    if(seen[N]==true||L[N]!=-1)return L[N];
    L[0]=2;
    L[1]=1;
    if(N!=1&&N!=0)L[N]=Lucas(N-1)+Lucas(N-2);    
    return L[N];
}

int main(){
    int N;
    cin>>N;
    rep(i,100){
        seen[i]=false;
        L[i]=-1;
    }
    cout<<Lucas(N)<<endl;
    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int INF=-5;
int main(){
	int n,ten[107]={0},tenc[107]={0},ans[107]={0};
	cin>>n;
	for(int i=0;i<n*(n-1)/2;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		if(c>d)ten[a]+=3;
		else if(c<d)ten[b]+=3;
		else ten[a]++,ten[b]++;
	}
	//for(int i=1;i<=n;i++)cout<<ten[i];int ans[107]={0};
		for(int i=1;i<=n;i++)tenc[i]=ten[i];
		
		for(int i=1;i<=n;i++){
			int tmp=-1,jun=-1;
			for(int j=1;j<=n;j++){
				if(tmp<tenc[j])tmp=tenc[j],jun=j;
			}
			tenc[jun]=-1;
			ans[jun]=i;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(ten[i]==ten[j])(ans[i]>ans[j])?ans[i]=ans[j]:ans[j]=ans[i];
			}
		}
	for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 1160
N = int(input())
S = list(map(int,input().split()))
S.sort(reverse=True)
slime = [S[0]]
S[0] = -1
for i in range(N):
    slime.sort(reverse = True)
    S.sort(reverse=True)
    ai = 0
    for j in range(2**i):
        while S[ai] != -1:
            if slime[j] > S[ai]:
                slime.append(S[ai])
                S[ai] = -1
                ai += 1
                break
            ai += 1
    if len(slime) < 2**(i+1):
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 118604