akhauriyash/Code-Regression huggingface dataset:
//AT3882带边权的并查集 
//最早接触带边权的并查集是银河英雄传说，这里就直接抄
#include <cstdio> 
using namespace std;
const int maxn=100010;
int father[maxn],dep[maxn];
int n,m;
bool f=1;
void csh(){
	for(int i=1;i<=n;i++){
		father[i]=i;
		dep[i]=0;
	}
}
int getfather(int x){
	if(x==father[x])return x;
	int fx=father[x];
	father[x]=getfather(father[x]);
	dep[x]+=dep[fx];
	return father[x];
}
void merge(int x,int y,int l){
	int xx,yy,ll;
	xx=getfather(x);
	yy=getfather(y);
	if(xx==yy){
		ll=dep[y]-dep[x];
		if(ll!=l)f=0;
		return; 
	}
	father[yy]=xx;
	dep[yy]=dep[x]+l-dep[y];
}
int main(){
	scanf("%d %d",&n,&m);
	csh();
	for(int i=1;i<=m;i++){
		int l1,r1,d1;
		scanf("%d%d%d",&l1,&r1,&d1);
		merge(l1,r1,d1);
		if(!f)break;
	}
	if(f)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    long long x[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        x[0] += a[i] * (1 - 2 * (i % 2));
    }
    printf("%lld", x[0]);
    for (int i = 1; i < n; i++) {
        x[i] = 2 * a[i-1] - x[i-1];
        printf(" %lld", x[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int main(){
	long n;
	cin >> n;
	for(int i = (int)sqrt(n); i>=1; i-- ){
		if(n % i == 0) {
			int k = n/i;
			int dig = 0;
			while(k > 0) {
				dig++;
				k /= 10;
			}
			cout << dig << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int main(){
  int N,A,B,ans=0;
  scanf("%d %d %d",&N,&A,&B);
  FOR(i,1,N+1){
    int j=i;
    int cnt=0;
    while(j>0){
      cnt+=j%10;
      j/=10;
    }
    if(A<=cnt&&cnt<=B){
      ans+=i;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 256
<?php
	while(fscanf(STDIN, "%d %d", $a, $b)) {
		$gcd = _gcd($a, $b);
		$lcm = $a / $gcd * $b;
		print $gcd . " " . $lcm . "\n";
	}

	function _gcd($a, $b) {
		if($b == 0) return $a;
		return _gcd($b, $a % $b);
	}
?>

Measured memory_bytes: 6600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  
  int saidai = 0;
  
  int N;
  cin >> N;
  
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    
    cin >> s.at(i);
    
  }
  int M;
  cin >> M;
  
  vector<string> t(M);
  for (int i = 0; i < M; i++) {
    
    cin >> t.at(i);
    
  }
  
  for (int i = 0; i < N; i++) {
    
    
    string a = s.at(i);
    int c = 0;
      
      
    for(int i = 0; i < N; i++) {
      
      if (a == s.at(i)) {
        
        c++;
        
      }
      
      
      
    }
    for(int i = 0; i < M; i++) {
      
      if (a == t.at(i)) {
        
        c--;
        
      }
      
      
      
    }
    if (saidai < c) {
      
      saidai = c;
      
    }
    
      
      
   
  }
  
  cout << saidai << endl;
  
}
 
  
  


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	ll n,i,j,k,x;
	cin>>n>>k;
	vector<ll> v;
	for(i=0;i<n;i++)
	{
		cin>>x;
		v.pb(x);
	}
	sort(v.begin(),v.end());
	ll ans = 2e9;
	for(i=0;i<=n-k;i++)
	{
		// cout<<(v[i+k-1]-v[i])<<endl;
		ans = min(ans,(v[i+k-1]-v[i]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
const int MAX_N = 200005;
const int INF = 1001001001;
 
vector<int> a, ans;
vector<int> to[MAX_N];
int dp[MAX_N];
 
void dfs(int v, int p=-1) {
  int i = lower_bound(dp, dp+MAX_N, a[v]) - dp;
  int old = dp[i];
  dp[i] = a[v];
  ans[v] = (int)(lower_bound(dp, dp+MAX_N, INF) - dp -1);
  for (int u : to[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
  dp[i] = old;
}
 
int main() {
  int n;
  cin >> n;
  a = ans = vector<int>(n);
  rep(i,n) cin >> a[i];
  rep(i,n-1) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    to[v].push_back(u);
    to[u].push_back(v);
  }
  rep(i,MAX_N) dp[i] = INF;
  dp[0] = -INF;
  dfs(0);
  rep(i,n) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 30780
A = int(input())

retval = 0
if (A == 100000):
  A = A-1
  
if (A >= 10000):
  retval += A-9999
  A = 9999
 
if (A >= 1000):
  A = 999

if (A>=100):
  retval += A-99
  A = 99
  
if (A>=10):
  A = 9
 
retval += A
print(retval)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <stdio.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)


//    Edges := 重み付き辺の集合
//    WeightedGraph := 重み付きグラフ
//    UnWeightedGraph := 重み無しグラフ
//    Matrix := 距離行列
template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

//計算量 O(ElogV)
// Dijkstra(g, s): 重み付き有向グラフ g 上で,
// 頂点 s からすべての頂点への最短距離を求め, その列を返す。
//
int INF = numeric_limits<int>::max();
template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s)
{
  const auto inf = numeric_limits< T >::max();
  vector< T > dist(g.size(), inf);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v,e,r;
    cin>>v>>e>>r;
    WeightedGraph<int> g(v);
    FOR(i,0,e){
      int in1,in2,c;
      cin>>in1>>in2>>c;
      g[in1].push_back(edge<int>(in1,in2,c));
    }
    vector<int> res = dijkstra(g,r);
    FOR(i,0,res.size()){
      if(res[i]==INF) cout<<"INF"<<endl;
      else cout<<res[i]<<endl;
    }
}



Measured memory_bytes: 15316
n = int(input())
dat = list(map(int, input().split()))
cur = dat[0]
can = True
for i in range(1, n):
    if dat[i] > cur:
        cur = dat[i] - 1
        continue
    if dat[i] == cur:
        continue
    can = False
print("Yes" if can else "No")

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100005;

template <int mod>
struct ModInt{
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p){
        if ((x += p.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p){
        if ((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e){
        long long a = 1, p = x;
        while (e > 0){
            if (e % 2 == 0){
                p = (p * p) % mod;
                e /= 2;
            }
            else{
                a = (a * p) % mod;
                e--;
            }
        }
        return ModInt(a);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p){
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a){
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

using modint = ModInt<mod>;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    unordered_map<int,int> D[n];
    for(int i=0;i<n;i++){
        for(int j=2;j*j<=a[i];j++){
            while(a[i]%j==0){
                D[i][j]++;;
                a[i]/=j;
            }
        }
        if(a[i] != 1)D[i][a[i]]++;
    }
    modint res=0;
    unordered_map<int,int> mp;
    for(int i=0;i<n;i++){
        for(auto it:D[i])mp[it.first]=max(mp[it.first],it.second);
    }
    modint pi=1;
    for(auto it:mp)pi*=modint(it.first).pow(it.second);
    for(int i=0;i<n;i++){
        modint z=pi;
        for(auto it:D[i])z/=modint(it.first).pow(it.second);
        res+=z;
    }
    cout<<res<<endl;

}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
int A[100100];

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> A[i];
    }
    multiset<int> se;
    se.insert(A[N - 1]);
    for (int i = N - 2; i >= 0; --i) {
        int v = A[i];
        auto ite = se.upper_bound(v);
        if (ite == se.end()) {
            se.insert(v);
        } else {
            se.erase(ite);
            se.insert(v);
        }
    }
    cout << se.size() << endl;
    return 0;
}


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

int main(){
   string s; cin>>s;
   int cnt=0;
   int l=0,r=0;
   rep(i,s.size()){
      if(s[i]=='0') l++;
      else r++;
   }
   int ans=min(l,r);
   cout<<ans*2<<endl;
   return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
// Begin Header {{{
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<lli>>;
using P = pair<int, int>;
// }}} End Header

int main(){
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int ans = (60*h2+m2) - (60*h1+m1) - k;
	if(ans < 0) ans = 0;
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n, j, cnt=0;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<bool> dp(1000007, true);
    vector<bool> np(1000007, false);
    rep(i,n){
        j=2;
        if(dp[a[i]]){
            while(1){
                if(a[i]*j>1000007) break;
                dp[a[i]*j]=false;
                ++j;
            }
            if(np[a[i]]) dp[a[i]]=false;
            np[a[i]]=true;
        }
    }
    rep(i,n){
        if(dp[a[i]]) ++cnt;
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 4272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll H, W, K; cin >> H >> W >> K;
  ll a[H][W];
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      char c; cin >> c; a[i][j] = c-'0';
    }
  }
  ll wsum[H+1][W];
  for (ll j = 0; j < W; j++) {wsum[0][j] = 0;}
  for (ll j = 0; j < W; j++) {
    for (ll i = 1; i <= H; i++) {
      wsum[i][j] = wsum[i-1][j]+a[i-1][j];
    }
  }
  ll res = 10000;
  
  for (ll bits = 0; bits < (1 << (H-1)); bits++) {
    ll h = __builtin_popcountll(bits)+1;
    vector<ll> v;
    v.push_back(0);
    for (ll i = 0; i < H-1; i++) {
      if ((bits >> i) & 1) {v.push_back(i+1);}
    }
    v.push_back(H);
    ll w[h]; fill(w, w+h, 0);
    ll p = 0;
    ll cut = h-1;
    while (p < W) {
      for (ll i = 0; i < h; i++) {
        w[i] += (wsum[v[i+1]][p]-wsum[v[i]][p]);
        if (wsum[v[i+1]][p]-wsum[v[i]][p] > K) {cut = 10000; break;}
      }
      if (cut == 10000) {break;}
      ll mx = 0;
      for (ll i = 0; i < h; i++) {
        mx = max(w[i],mx);
      }
      if (mx > K) {
        fill(w, w+h, 0); cut++;
      } else {
        p++;
      }
    }
    res = min(res,cut);
  }
  cout << res << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
int64_t pow10(int64_t t){
    if(t==0){
        return 1;
    }
    else{
        return 10*pow10(t-1);
    }
} 
int64_t pow5(int64_t t){
    if(t==0){
        return 1;
    }
    else{
        return 5*pow5(t-1);
    }
} 
int main(){
    int64_t n;
    cin >> n;
    //奇数の時f(n) = n*(n-2)*(n-4)*....5*3; ⇒ 絶対0じゃん
    //偶数の時f(n) = n*(n-2)*(n-4)*....4*2; ⇒10,100,1000...の倍数の数    
    int64_t sum = 0;
    int64_t t;
    int64_t pret=1;
    int64_t fivetwo;
    if(n%2==1){
        cout << 0 << endl;
    }
    //250とかの存在
    //末尾の0は5の因数
    else{
        while(pow5(pret) <=n){
           t = n/pow5(pret)/2;
           sum += t;
           pret++;
        }
        cout << sum <<endl; 
    }
}
    


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
   string w;
   cin >> w;
   int s = 0;
   if(w.size()  % 2 ==1){
       cout << "No"  << endl;
    }
    else{
        sort(w.begin(), w.end());
        for(int i = 1; i < w.size(); i++){
            if(w[i-1]==w[i]){
                s++;
            }
            else{
                if(s % 2 == 0){
                    cout << "No" <<  endl;
                    break;
                }
                else{
                    s = 0;
                }   
            }
            if(i == w.size()-1){
                if(s % 2 == 0){
                    cout << "No" << endl;
                }
                else{cout << "Yes" << endl;}
            }
        }
    }
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()

print(math.ceil(N/2))

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;

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

  double invsum = 0.0;
  for(int i = 0; i < N; i++){
    invsum += 1.0/A[i];
  }

  cout << setprecision(15) << (1.0 / invsum) << endl;

  return 0;
}



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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  string ans;
  std::cin >> ans;
  sort(rng(ans));
  rep(i, n-1) {
    string s; std::cin >> s;
    sort(rng(s));
    string ns;
    rep(j, ans.size()) rep(k, s.size()) {
      if (ans[j] == s[k]) {
        ns += s[k];
        s[k] = '?';
        break;
      }
    }
    ans = ns;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll a = 2 , b = 1 , x;
    if( n != 1 ){
    	for(int i = 2 ; i <= n ; i++){
    		x = b;
    		b += a;
    	  	a = x;
    	}
    	cout << b;
    } else cout << 1;
}


Measured memory_bytes: 3652
//# define FLAG
///delet....................................
# include   <bits/stdc++.h>
using namespace std;
# define    pb                      push_back
# define    mp                      make_pair
# define    IOS                     ios::sync_with_stdio(false)
# define    mem(a,b)                memset(a,b,sizeof(a))
# define    FO(i,n,a)               for(int i=n; i>=a; --i)
# define    FOR(i,a,n)              for(int i=a; i<=n; ++i)
# define    MAX(a,b)                (a)>(b)?(a):(b)
# define    MIN(a,b)                (a)<(b)?(a):(b)
# define    lowbit(x)               ((x)&(-x))
# define    LINF                    0xfcfcfcfcfcfcfcf
# define    INF                     0x3f3f3f3f
# define    MOD                     1000000007
# define    eps                     0.00000001
# define    pi                      3.141592653
# define    ee                      2.718281828459
# define    hr                      ptc('\n')
# define    kb                      ptc(' ')
# define    bug                     puts("H");
# pragma    comment(linker,"/STACK:1024000000,1024000000")
typedef     pair<int,int>           PII;
typedef     vector<int>             VI;
typedef     long long               LL;
typedef     unsigned long long      ULL;
inline char gtc() {
    static char buf[100000],*p1=buf-1,*p2=buf-1;
    return p1==p2&&(p2=(p1=buf-1)+fread(buf,1,100000,stdin),p1==p2)?EOF:*++p1;
}
static char bufout[2000000],*chout=bufout-1;
inline void ptc(char ch) {
    *++chout=ch;
}
# define    Template                LL
inline Template read() {
    char ch=gtc();
    while(!(ch>='0'&&ch<='9'||ch=='-'))ch=gtc();
    Template sum=0,flag=(ch=='-'?(ch=gtc()):0);
    while(ch>='0'&&ch<='9')sum=sum*10+ch-'0',ch=gtc();
    return flag?-sum:sum;
}
inline void out(Template x) {
    if(x<0)ptc('-'),x=-x;
    if(x>9)out(x/10);
    ptc(x%10+'0');
}
inline void write() {
    fwrite(bufout,1,chout-bufout+1,stdout);
}
///coding...................................

char a[10];

int main() {
    IOS;
#ifdef FLAG
    //freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    int cnt=0;
    cin>>a+1;
    FOR(i,1,6)if(a[i]=='1')cnt++;
    cout<<cnt<<endl;
    return 0;
}










///delete FLAG..............................




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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define EPS 0.0000000001
#define pb push_back
#define space " "
#define ar array
#define pi pair<int,int>
#define ff first
#define ss second

const int maxN = 2 * 100000;
vector<int> g[maxN + 3];
vector<bool> vis(maxN + 2);

int dfs(int cur) {
    vis[cur] = true;
    int ans = 1;
    for (auto to : g[cur]) {
        if (!vis[to]) {
            vis[to] = true;
            ans += dfs(to);
        }
    }
   // cerr << " cur = " << cur << " ans = " << ans << endl;
    return ans;
}

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;v-- ;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ans = 0 ;
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            ans = max(ans, dfs(i));
        }
    }
    cout << ans << endl;
}

int main() {
//    freopen("input.txt" , "r" , stdin) ;
//    freopen("output.txt" , "w" , stdout) ;
    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 23912
from sys import stdin
from itertools import accumulate


def fin(f):
    """
    INput with Function
    f(input())と同じ。書きやすさのために作成した。
    :param f: 入力に対して呼び出す関数
    :return: 関数の処理結果
    """
    return f(stdin.readline().rstrip())


def gin(f, nl=1):
    """
    INput with function and Generator
    空白区切りの入力の各値に対して関数fを用いて初期化を行う。
    複数行にも対応。
    使い方:
      一行の入力例 -> next(gin(int))
      複数行の入力をリストに格納する例 -> list(gin(int, n))
      forループで使う例 -> for l, r in gin(int, n):
    :param f: 各値に適応する関数
    :param nl: 行数(デフォルトは1)
    :returns: 空白区切りのリストたち
    """
    for _ in range(nl):
        yield list(map(f, stdin.readline().split()))


n, q = next(gin(int))

s = input()


def count(total, i):
    return total + 1 if s[i-1:i+1] == 'AC' else total


cumsum = list(accumulate([0] + list(range(n)), count))[1:]

for l, r in gin(int, q):
    print(cumsum[r-1] - cumsum[l-1])



Measured memory_bytes: 9476
#pragma region
// Author: Wenxing Mei
//   Date: 2018-08-25 19:58
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define repv(ele, vec) for (auto &ele : vec)
#define zero(mem) memset(mem, 0, sizeof(mem))
#define sd(_) scanf("%d", &_)
#define sdd(_, __) scanf("%d%d", &_, &__)
#define sddd(_, __, ___) scanf("%d%d%d", &_, &__, &___)
#define sdddd(_, __, ___, ____) scanf("%d%d%d%d", &_, &__, &___, &____)
#define sf(_) scanf("%lf", &_)
#define sff(_, __) scanf("%lf%lf", &_, &__)
#define sfff(_, __, ___) scanf("%lf%lf%lf", &_, &__, &___)
#define sffff(_, __, ___, ____) scanf("%lf%lf%lf%lf", &_, &__, &___, &____)
#define sl(_) scanf("%lld", &_)
#define sll(_, __) scanf("%lld%lld", &_, &__)
#define slll(_, __, ___) scanf("%lld%lld%lld", &_, &__, &___)
#define sllll(_, __, ___, ____) scanf("%lld%lld%lld%lld", &_, &__, &___, &____)
#define sc(_) scanf("%c", &_)
#define ss(_) scanf("%s", _)
#define sz(x) (int)(x).size()
#define mid(a, b) (((a) + (b)) >> 1)
#define lfg(x) x << 1
#define rht(x) x << 1 | 1
#define inf 0x3f3f3f3f
#define all(container) container.begin(), container.end()
//#define MOD 19260817
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#pragma endregion

// Read the question correctly
// What are the exact constraints?
// Look out for SPECIAL CASES (n=1? n=1000000000?) and overflow (ull vs int?)

int main() {
  int n, i;
  sdd(n, i);
  cout << n + 1 - i << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; 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 ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;

int main(void){
  int n;
  cin >> n;
  n *= 2;
  vi l(n);
  REP(i, n) cin >> l[i];
  sort(ALL(l));
  int ans = 0;
  RREP(i, n){
    ans += l[i-1];
    i--;
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  ll A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> S(N+1);
  S[N] = "AB";
  vector<char> ans;
  rep(i, N) cin >> S[i];
  rep(i, N) {
    if(S[i] == "AB") {
      if(A == 0 && B == 0) {
        break;
      } else if(A == 0) {
        A++; B--;
        ans.push_back('A');
      } else if(B == 0) {
        B++; A--;
        ans.push_back('B');
      } else if(A == 1 && B == 1) {
        if(S[i+1] == "AB") {
          A--; B++;
          ans.push_back('B');
        } else if(S[i+1] == "BC") {
          B++; A--;
          ans.push_back('B');
        } else {
          A++; B--;
          ans.push_back('A');
        }
      } else if(A > B) {
        A--; B++;
        ans.push_back('B');
      } else {
        A++; B--;
        ans.push_back('A');
      }
    } else if(S[i] == "BC") {
      if(B == 0 && C == 0) {
        break;
      } else if(B == 0) {
        B++; C--;
        ans.push_back('B');
      } else if(C == 0) {
        C++; B--;
        ans.push_back('C');
      } else if(B == 1 && C == 1) {
        if(S[i+1] == "BC") {
          B--; C++;
          ans.push_back('C');
        } else if(S[i+1] == "AC") {
          C++; B--;
          ans.push_back('C');
        } else {
          B++; C--;
          ans.push_back('B');
        }
      } else if(B > C) {
        B--; C++;
        ans.push_back('C');
      } else {
        B++; C--;
        ans.push_back('B');
      }
    } else {
      if(C == 0 && A == 0) {
        break;
      } else if(C == 0) {
        C++; A--;
        ans.push_back('C');
      } else if(A == 0) {
        A++; C--;
        ans.push_back('A');
      } else if(C == 1 && A == 1) {
        if(S[i+1] == "AC") {
          C--; A++;
          ans.push_back('A');
        } else if(S[i+1] == "AB") {
          A++; C--;
          ans.push_back('A');
        } else {
          C++; A--;
          ans.push_back('C');
        }
      } else if(C > A) {
        C--; A++;
        ans.push_back('A');
      } else {
        C++; A--;
        ans.push_back('C');
      }
    }
  }
  if(ans.size() == N) {
    cout << "Yes" << endl;
    rep(i, N) cout << ans[i] << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 6716
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000009;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);


struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}


void solve() {
	ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;
	ll d = abs(a - b);
	ll c = t * (v - w);
	if (c >= d) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    //cout << fixed << setprecision(6);
	//init_f();
	//init();
	//int t; cin >> t;rep(i,t)
	solve();
	stop
		return 0;
}


Measured memory_bytes: 7748
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

std::string s;

int main(){
    std::cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(i%2 == 0 && s[i] == 'L'){
            printf("No\n");
            return 0;
        }
        if(i%2 == 1 && s[i] == 'R'){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#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
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

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



int main() {

	ll N,K;
	cin >> N>>K;
	vector<ll> dp(N+K+2);
	vector<ll> h(N+K+2);
	rep(i, N) {
		cin >> h.at(i);
		dp.at(i) = 999999999;
	}
	rep(i, K + 2) {
		dp.at(i + N) = 999999999;
	}
	dp.at(0) = 0;
	for (ll i = 0; i < N; i++) {
		for (ll j = 1; j <= K; j++) {
			chmin(dp.at(i + j), dp.at(i) + abs(h.at(i) - h.at(i + j)));
		}
	}
	cout << dp.at(N-1) << endl;
}


Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int N, K;

bool cmp(const pii &a, const pii &b){
    if(a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

vi dist;
int d[110][110];

bool bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
    dist = vector<int>(n, INF);
    dist[s] = 0; // 開始点の距離は0
    for (int i = 0; i < n; i++) {
        for (int v = 0; v < n; v++) {
            for (int u = 0; u < n; u++) {
                if (dist[v] != INF && dist[u] > dist[v] + d[v][u]) {
                    dist[u] = dist[v] + d[v][u];
                    if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
                }
            }
        }
    }
    return false;
}


int main() {
    //cout << fixed << setprecision(15);

    int maxV = 0;
    int N = readInt(), M = readInt();

    REP(i, N){
        int cnt=0;
        REP(j, M) {
            int t;  cin >> t;
            if(t) cnt++;
        }
        maxV = max(maxV, cnt);
    }
    cout << maxV << endl;

    return 0;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a + b == c + d){
    cout << "Balanced" << endl;
  } else if (a + b < c + d){
    cout << "Right" << endl;
  } else if (a + b > c + d){
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <numeric>

char field[50][51];
int ids[50][50];
int H, W;
int step[50 * 50];
std::vector<int> counts;
const int dir[] = {0, 1, 0, -1, 0};

struct XY
{
  int x;
  int y;
};

int fill_path(int id, int x, int y)
{
  int count = 1;
  ids[y][x] = id;
  field[y][x] = '#';
  
  for (int i = 0; i < 4; ++i)
  {
    int X = x + dir[i + 1];
    int Y = y + dir[i];
    if (0 <= X && X < W && 0 <= Y && Y < H && field[Y][X] == '.' && ids[Y][X] == 0)
    {
      count += fill_path(id, X, Y);
    }
  }
  return count;
}

int main()
{
  scanf("%d %d", &H, &W);
  for (int i = 0; i < H; ++i)
  {
    scanf("%s", field[i]);
  }
  
  int route_id = 1;
  for (int y = 0; y < H; ++y)
  {
    for (int x = 0; x < W; ++x)
    {
      if (field[y][x] == '.')
      {
        counts.push_back(fill_path(route_id, x, y));
        ++route_id;
      }
    }
  }
  if (ids[0][0] != ids[H - 1][W - 1])
  {
    puts("-1");
    return 0;
  }
  
  route_id = ids[0][0];
  std::queue<XY> q;
  q.push(XY{0, 0});
  step[0] = 1;
  
  while (q.size() > 0)
  {
    XY xy = q.front();
    q.pop();
    if (xy.x == W - 1 && xy.y == H - 1) break;
    for (int i = 0; i < 4; ++i)
    {
      int X = xy.x + dir[i + 1];
      int Y = xy.y + dir[i];
      
      if (0 <= X && X < W && 0 <= Y && Y < H && ids[Y][X] == route_id && step[Y * 50 + X] == 0)
      {
        step[Y * 50 + X] = step[xy.y * 50 + xy.x] + 1;
        q.push(XY{X, Y});
      }
    }
  }
  printf("%d\n", std::accumulate(counts.begin(), counts.end(), 0) - step[(H - 1) * 50 + (W - 1)]);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#include "atcoder/all"

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

string solve() {
    int n;
    cin >> n;
    vector<P> v(n);
    for (P &p:v) cin >> p.first >> p.second;

    auto check = [&](int i) -> bool {
        return (v[i].first == v[i].second)
               && (v[i + 1].first == v[i + 1].second)
               && (v[i + 2].first == v[i + 2].second);
    };

    rep(i, n - 2) {
        if (check(i)) return "Yes";
    }
    return "No";


}

int main() {
    cout << solve() << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int cnt=0;
int N,S;
void func(int m,int n,int s){
    if(m==10){
        if(n==N&&s==S)cnt++;

        return;
    }

    func(m+1,n+1,s+m);
    func(m+1,n,s);

    return;
}
int main(){
    while(cin>>N>>S,N||S){
        cnt=0;
        func(0,0,0);
        cout<<cnt<<endl;
    }
}

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

int main(){
  string s, t;
  cin >> s >> t;
  string maxS = "";
  for ( int i = 0; i < 50; i++){
    maxS += "z";
  }
  string ans = maxS;
   if ( s.length() < t.length()){
      cout << "UNRESTORABLE" << endl;
      return 0;
    }
  for ( int i = 0; i <= s.length() - t.length(); i++){
    string ss = s;
    string substr = ss.substr(i, t.length());
    bool isCorrect = true;
    for ( int j = 0; j < t.length(); j++){
//      cout << substr << endl;
       if ( substr[j] != '?' && substr[j] != t[j]){
        isCorrect = false;
        break;
      }
    }

    if ( isCorrect ){
      ss.replace(i, t.length(), t);
      for ( int j = 0; j < ss.length(); j++){
        if ( ss[j] == '?')ss[j] = 'a';
      }
      ans = min(ans, ss);
    }
  }

  if ( ans == maxS ){
    ans = "UNRESTORABLE";
  }

  cout << ans << endl;


  return 0;
}

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

int main(){
    int n, m; cin >> n >> m;
    priority_queue<int> item;
    rep(i, n) {
        int a; cin >> a;
        item.push(a);
    }
    rep(i, m) {
        int x = item.top() / 2;
        item.pop(); 
        item.push(x);
    }
    ll ans=0;
    while(!item.empty()) {
        ans += item.top();
        item.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;

char g[1005][1005] = {0};
string c[10][10];
LL n;

void init(){
	c[3][0] = "aa.";
	c[3][1] = "..b";
	c[3][2] = "..b";
	
	c[4][0] = "aabc";
	c[4][1] = "ddbc";
	c[4][2] = "efgg";
	c[4][3] = "efhh";
	
	c[5][0] = "aabbc";
	c[5][1] = "dee.c";
	c[5][2] = "d..fg";
	c[5][3] = "h..fg";
	c[5][4] = "hiijj";
	
	c[7][0] = "aabbcc.";
	c[7][1] = "gg.gg.d";
	c[7][2] = "..g..gd";
	c[7][3] = "..g..ge";
	c[7][4] = "gg.gg.e";
	c[7][5] = "..g..gf";
	c[7][6] = "..g..gf";
}

LL cov(LL x,LL y,LL id){
	for(LL i = 0;i < id;i ++){
		for(LL j = 0;j < id;j ++){
			g[x + i][y + j] = c[id][i][j];
		}
	}
}

void solve(LL x,LL y){
	if(x == -1){
		if(y == 2){ cout << -1 << endl; return; }
		if(y == 3) cov(1,1,3);
		if(y == 6){ cov(1,1,3); cov(4,4,3); }
		if(y == 5) cov(1,1,5);
		if(y == 7) cov(1,1,7);
		if(y == 11){ cov(1,1,4); cov(5,5,7); }
	}
	else{
		LL tx = 1;
		for(LL i = 1;i <= x;i ++){
			cov(tx,tx,4);
			tx += 4;
		}
		for(LL i = 1;i <= y;i ++){
			cov(tx,tx,5);
			tx += 5;
		}
	}
	for(LL i = 1;i <= n;i ++){
		for(LL j = 1;j <= n;j ++){
			if(!g[i][j]) g[i][j] = '.';
			cout << g[i][j];
		}
		cout << endl;
	}
}

int main(){
	cin >> n;
	init();
	if(n <= 2) solve(-1,2);
	if(n == 3) solve(-1,3);
	if(n == 4) solve(1,0);
	if(n == 5) solve(0,1);
	if(n == 6) solve(-1,6);
	if(n == 7) solve(-1,7);
	if(n == 11) solve(-1,11);
	if(n < 8 || n == 11) return 0;
	for(LL i = 0;i <= 1000;i ++){
		if((n - i * 4) % 5 == 0){
			solve(i,(n - i * 4) / 5);
			break;
		}
	}
	return 0;
}
//

Measured memory_bytes: 2176
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
using namespace std;
int main() {
	int N, M;
	bool ans = false;
	cin >> N >> M;
	int a, b;
	vector<int>c(N);
	for (int i = 0; i < M; i++)
	{
		cin >> a >> b;
		if (b == 1 || a == N)swap(a, b);
		if (a == 1)c[b]++;
		if (b == N)c[a]++;
	}
	for (int i = 0; i < N; i++)if (c[i] == 2)ans = true;
	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE");
}


Measured memory_bytes: 1024
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7
const ll MOD=1e9+7;
const int N=500000;

main(){
    vector<char> s;
    string t;cin>>t;
    for(auto c:t)s.pb(c);
    s.erase(unique(all(s)),s.end());
    cout<<s.size()-1;
}

Measured memory_bytes: 640
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	vector<ll>arr(n);
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr.begin(),arr.end());
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			ll val=arr[i]+arr[j];
			ll pos=lower_bound(arr.begin(),arr.end(),val)-arr.begin();
			ans+=max(0LL,pos-j-1);
		}
	}
	cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 256