akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
const ll MOD=100000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return (v[(size / 2) - 1] + v[size / 2]) / 2;
}


int main(){
    ll r,d,x;
    cin>>r>>d>>x;
    rep(i,0,10){
        x=r*x-d;
        cout<<x<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int A[110];

void insert_sort(int a[], int n) {
    for(int i=1; i < n; ++i) {
        int v = a[i];
        int j = i-1;
        while(j >= 0 && a[j] > v) {
            a[j+1] = a[j];
            --j;
        }
        a[j+1] = v;
        for(int k=0; k < n; ++k) {
            if(k > 0) cout << " ";
            cout << a[k];
        }
        cout << endl;
    } 
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    int n; cin >> n;
    rep(i,n) cin >> A[i];

    rep(i,n) {
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    insert_sort(A, n);


    return 0;
}



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

typedef double du ;
typedef string st ;
typedef long long ll ;

int main ()
{
    int num ;
    st nu1 , nu2 ;

    cin >> num ;
    cin >> nu1 >> nu2 ;

    st res [num*2] ;

    for (int i = 0 , j = 0 ; i < num ; j += 2 , i ++)
    {
        res[j] = nu1[i] ;
        res[j + 1] = nu2 [i] ;
    }
    for (int i = 0 ; i < num * 2; i ++)
    {
        cout << res[i] ;
    }
    return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dl double
using namespace std;

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
	ll x;
    cin >>x;
    ll ans=0;
    ans+=1000*(x/500);
    x=x%500;
    ans+=5*(x/5);
    cout <<ans << endl;
	
	
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	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>
#include<sstream>
#include<iomanip>
#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()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int main(){
	int q;
	cin>>q;
	while(q--){
		int n,m;
		cin>>n>>m;
		int in[20][20][2]={0};
		int w;cin>>w;
		while(w--){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			int x=min(a,c),y=min(b,d),e=(a!=c?true:false);
			in[x][y][e]=true;
		}
		vvi dp(n+1,vi(m+1));
		dp[0][0]=1;
		rep(i,n+1)rep(j,m+1){
			if(j+1<=m&&in[i][j][0]==0)dp[i][j+1]+=dp[i][j];
			if(i+1<=n&&in[i][j][1]==0)dp[i+1][j]+=dp[i][j];
		}
		if(dp[n][m])cout<<dp[n][m]<<endl;
		else cout<<"Miserable Hokusai!"<<endl;
	}
}

Measured memory_bytes: 1220
def woo(x, y):
    res = [0]*x
    z = list(map(int, input().split()))
    for i in range(1, x):
        res[i] = min(abs(z[i] - z[j]) + res[j] for j in range(max(0, i - y), i))
    return res

if __name__ == '__main__':
    x, y = map(int, input().split())
    r = woo(x, y)
    f = len(r)-1
    print(r[f])



Measured memory_bytes: 14820
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
	int S[N];
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	long long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += S[i];
	}
	if (sum % 10 != 0) {
		cout << sum << endl;
		return 0;
	}
	sort(S, S + N);
	for (int i = 0; i < N; i++) {
		if (S[i] % 10 != 0) {
			cout << sum - S[i] << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K;
    cin >> N >> K;

    int l[50];
    for(int i=0;i<N;i++)
        cin >> l[i];

    // 降順ソート
    sort(l, l + N, greater<int>());
    int ans = 0;
    for(int i=0;i<K;i++)
        ans += l[i];
    
    cout << ans << endl;

}

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

int main(){
  int n;
  ll sum = 0;
  priority_queue<int> que;
  priority_queue< int, vector<int>, greater<int> > quea;
  cin >> n;
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    que.push(a); quea.push(a);
    sum += a;
  }
  cout << quea.top() << " " << que.top() << " " << sum << "\n";
  return 0;
}



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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> p(m);
    vector<string> s(m);
    rep(i, m)
    {
        cin >> p.at(i) >> s.at(i);
    }
    //ここまで入力
    vector<int> wa(n);
    vector<bool> ac(n);
    rep(i, n)
    {
        wa.at(i) = 0;
        ac.at(i) = false;
    }

    int actimes = 0;

    rep(i, m)
    {
        if (s.at(i) == "AC" && ac.at(p.at(i) - 1) == false)
        {
            actimes++;
            ac.at(p.at(i) - 1) = true;
        }
        else if (ac.at(p.at(i) - 1) == false)
        {
            wa.at(p.at(i) - 1)++;
        }
    }
    int wrongsum = 0;
    rep(i, n)
    {
        if (ac.at(i) == true)
        {
            wrongsum += wa.at(i);
        }
    }

    cout << actimes << " " << wrongsum << endl;
}


Measured memory_bytes: 6528
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
//change null_type here for map/set
typedef tree<int,null_type,less<int>,rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;
typedef long long int  ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define F first
#define S second

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    x*=sgn; return ~c;
}
///START HERE
///indexed_set pbd;
//pbd.insert()
//auto x = pbd.find_by_order(2);
//int od=pbd.order_of_key(7)
///rope<int> rp;
//rp.push_back()
//RandomAccess like vector
//mutable_begin, mutable_end()

int main(){
    ///read()+printf
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //fast;
    string st;
    cin>>st;
    ll x=0;
    for(auto i:st){
        x+=i-'0';
    }
    if(x%9==0){

        cout<<"Yes";
    }
    else{
        cout<<"No";
    }



    return 0;
}


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

int main(){
	int q,a,b;
	scanf("%d",&q);
	while(q--){
		scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		if(a==b || a+1==b) printf("%d\n",a+a-2);
		else{
			int l=1,r=1000000001;
			while(r-l>1){
				int mid=(l+r)>>1;
				if((ll)mid*mid<(ll)a*b) l=mid;
				else r=mid;
			}
			if((ll)l*(l+1)>=(ll)a*b) printf("%d\n",l+l-2);
			else printf("%d\n",l+l-1);
		}
	}
	return 0;
}

Measured memory_bytes: 256
n, m, c = list(map(int, input().split(' ')))
bb = list(map(int, input().split(' ')))
ans = 0
for i in range(n):
    aa = list(map(int, input().split(' ')))
    hoge = sum([b*a for b, a in zip(bb, aa)])
    if hoge + c > 0:
    	ans += 1
print(ans)

Measured memory_bytes: 3060
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])
const h = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const ans = () => {
  let max = h[0]

  for (let i = 1; i < n; i++) {
    if (max - h[i] > 1) {
      return 'No'
    }

    max = Math.max(max, h[i])
  }

  return 'Yes'
}

console.log(ans())


Measured memory_bytes: 17816
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
constexpr long long int MOD = 998244353LL;
long long int power(const long long int base, const int exp) {
	switch (exp) {
	case 0: return 1LL;
	case 1: return base % MOD;
	default: return power(base * base % MOD, exp / 2) * power(base, exp % 2) % MOD;
	}
}
int main() {
	int n; std::cin >> n;
	std::vector<int> distances(n); for (auto& d : distances) std::cin >> d;
	if (distances[0] != 0 || std::count(distances.begin(), distances.end(), 0) >= 2) {
		std::cout << 0 << '\n';
		return 0;
	}
	std::vector<int> node_count(n, 0);
	for (auto i = 0; i < n; ++i) {
		node_count[distances[i]]++;
	}
	const auto max_distance = *std::max_element(distances.begin(), distances.end());
	long long int result = 1;
	for (auto i = 1; i <= max_distance; ++i) {
		result *= power(node_count[i - 1], node_count[i]);
		result %= MOD;
	}
	std::cout << result << std::endl;
}

Measured memory_bytes: 1656
inp = int(input())
lis = list(map(int, input().split()))

dic = {}

#count
for l in lis:
  if l in dic: dic[l] += 1
  else: dic[l] = 1

#dic_sum = dic.copy()
s = 0
#calcurate
for d in dic:
  s += int(dic[d]*(dic[d]-1)//2)
  
for i in range(inp):
  #dic_sum_n = dic_sum.copy()
  t = dic[lis[i]]
  print(s-int(t*(t-1)//2)+int((t-1)*(t-2)//2))

Measured memory_bytes: 26140
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>
#include <cstring>
#include <cstdlib>

#define MEMZERO(x, sz) memset(x, '0', sz);

using namespace std;

int keta;

void mycopy( char a[7], int x )	// 数字を文字列に
{
	MEMZERO(a, 7);
	a[keta] = 0;
	int pnt = 0;
	while(x) {
		a[pnt++] = (x % 10) + '0';
		x /= 10;
	}
}
int main( void )
{
	int num;
	int save[21];
	while(cin >> num >> keta, num | keta) {
		char in[7];
		mycopy(in, num);
		save[0] = num;

		//cout << save[0] << endl;

		int count = 1, ans1, ans2, ans3;
		while(true) {
			char tt[7];
			strcpy(tt, in);
			tt[keta] = 0;
			sort(in, in+keta, greater<char>());	// 最大値
			sort(tt, tt+keta);					// 最小値
			int x = atoi(in) - atoi(tt);			// 大 - 小
			//cout << in << ' ' << tt << endl;
			//cout << x << endl;
			bool hit = false;
			for(int i=0; i < count; ++i) {
				if(x == save[i]) {
					//cout << x << ' ' << save[i] << endl;
					ans1 = i;
					ans2 = x;
					ans3 = count - i;
					hit = true;
					break;
				}
			}
			if(hit) break;
			save[count++] = x;
			mycopy(in, x);
		}
		cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
		MEMZERO(in, 7);
		in[keta] = 0;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
using namespace std;

ll n,ar[N],dp[N];

ll f(int ind)
{
	if(dp[ind]!=-1)
		return dp[ind];
	if(ind==n)
		return 0;
	ll t1=f(ind+1)+fabs(ar[ind+1]-ar[ind]);
	ll t2=0;
	if(ind<n-1)
		t2=f(ind+2)+fabs(ar[ind+2]-ar[ind]);
	else
		t2=99999999999;
	// if(ind==2)
	// 	cout<<t1<<sp<<t2<<endl;
	// return min(t1,t2);
	return dp[ind]=min(t1,t2);

	}


int main()
{
	fast;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
		cin>>ar[i];
	ll a=f(1);
	cout<<a<<endl;
	// for(int i=1;i<=n;i++)
	// 	cout<<dp[i]<<sp;
}


Measured memory_bytes: 15232
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn readu() -> usize {
    read::<usize>()
}

#[allow(dead_code)]
fn readi() -> i32 {
    read::<i32>()
}

fn main() {
    input! {
        pos: [i32; 5],
        k: usize,
    }

    for i in 0..5 {
        for j in (i + 1)..5 {
            if (pos[i] - pos[j]).abs() > k as i32 {
                println!(":(");
                return;
            }
        }
    }
    println!("Yay!");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max({a*c,a*d,b*c,b*d}) << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const ll Mod = 1000000007;
/* --- */
using MT = decay<decltype(Mod)>::type;

MT inverse (MT a, MT n) {
	MT u = 0, v = 1;
	while (a != 0) {
		MT q = n / a;
		swap(u, v); v -= q * u;
		swap(n, a); a -= q * n;
	}
	assert(n == 1);
	return u;
}

class mint {
private: MT x;
public:
	void normalize() {
		if (x >= Mod || x < 0) x = (x % Mod) + Mod;
		if (x > Mod) x -= Mod;
	}
	mint(): x(0) {}
	mint(MT z): x(z) { normalize(); }
	const MT& operator() () const { return x; }

	mint operator+ (const mint& z) { MT r = x + z(); if (r > Mod) r -= Mod; return mint(r); }
	mint operator- (const mint& z) { MT r = x - z(); if (r < 0) r += Mod; return mint(r); }
	mint operator* (const mint& z) { MT r = x * z(); if (r > Mod) r %= Mod; return mint(r); }
	mint operator/ (const mint& z) { return (*this) * mint(inverse(z(), Mod)); }

	mint operator+= (const mint& z) { (*this) = (*this) + z; return (*this); }
	mint operator-= (const mint& z) { (*this) = (*this) - z; return (*this); }
	mint operator*= (const mint& z) { (*this) = (*this) * z; return (*this); }
	mint operator/= (const mint& z) { (*this) = (*this) / z; return (*this); }

	friend std::istream& operator>> (std::istream&, mint&);
};

std::istream& operator>> (std::istream& stream, mint& p) {
	MT v; stream >> v; p.x = v; p.normalize(); return stream;
}
std::ostream& operator<< (std::ostream& stream, const mint& p) { return stream << p(); }
mint operator+ (const MT& p, const mint& q) { return mint(p) + q; }
mint operator- (const MT& p, const mint& q) { return mint(p) - q; }
mint operator* (const MT& p, const mint& q) { return mint(p) * q; }
mint operator/ (const MT& p, const mint& q) { return mint(p) / q; }
string to_string (const mint& p) { return to_string(p()); }

mint powMod (mint a, MT b) {
	mint res = 1, x = a;
	while (b > 0) {
		if (b & 1) res *= x;
		x *= x;
		b >>= 1;
	}
	return res;
}
/* --- */

const int N = 100010;
mint f[N], g[N], h[N];
int n;
char s[N];

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'A') f[i] = f[i - 1] + powMod(3, k);
    else if (s[i] == '?') f[i] = f[i - 1] * 3 + powMod(3, k);
    else f[i] = f[i - 1];
    
    if (s[i] == '?') k++;
  }

  for (int i = 1; i <= n; i++) {
    if (s[i] == 'B') g[i] = g[i - 1] + f[i - 1];
    else if (s[i] == '?') g[i] = g[i - 1] * 3 + f[i - 1];
    else g[i] = g[i - 1];
  }

  for (int i = 1; i <= n; i++) {
    if (s[i] == 'C') h[i] = h[i - 1] + g[i - 1];
    else if (s[i] == '?') h[i] = h[i - 1] * 3 + g[i - 1];
    else h[i] = h[i - 1];
  }
  printf("%lld\n", h[n]());
}



Measured memory_bytes: 2688
# include <iostream>
# include <algorithm>

using namespace std;

struct Item
{
    int v, w;
};

int main(){
    int N, W;
    scanf("%d%d", &N, &W);
    Item items[N+1];
    for(int i=1; i<=N; i++) scanf("%d%d", &items[i].v, &items[i].w);
    int table[N+1][W+1];
    for(int i=0; i<=W; i++) table[0][i] = 0;
    for(int i=1; i<=N; i++)
    {
        table[i][0] = 0;
        for(int j=1; j<=W; j++)
        {
            if(j < items[i].w) table[i][j] = table[i-1][j];
            else table[i][j] = max(table[i-1][j], items[i].v + table[i-1][j - items[i].w]);
        }
    }
    printf("%d\n", table[N][W]);
} 


Measured memory_bytes: 7104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
const int mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n;
vector<vector<int>> g;
map<P, int> mp;

bool get_path(int start, int goal, int parent, ll &path){
        if(start == goal) {
            path = 0;
            return true;
        }
        else{
            for(int next : g[start]){
                if(next == parent) continue;
                if(get_path(next, goal, start, path)){
                    path |= (1LL << mp[P(start, next)]);
                    return true;
                }
            }
        }

        return false;
    }

int main(){
    cin >> n; g.assign(n, vector<int> ());
    rep(i,n-1){
        int a,b; cin >> a >> b; a--; b--;
        g[a].pb(b); g[b].pb(a);
        mp[P(a,b)] = i;
        mp[P(b,a)] = i;
    }

    int m; cin >> m;
    vector<int> u(m), v(m);
    rep(i,m){
        cin >> u[i] >> v[i];
        u[i]--; v[i]--;
    }

    vector<ll> path(m);

    rep(i,m) get_path(u[i], v[i], -1, path[i]);
    ll ans = 0;

    rep(bit, (1 << m)){
        ll cnt = 0;

        rep(i,m) if(bit & (1LL << i)) cnt |= path[i];

        ll free = (ll)n - 1LL - __builtin_popcountl(cnt);

        if(__builtin_popcountl(bit) % 2) ans -= (1LL << free);
        else ans += (1LL << free);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve(){
	
	int n,k;
	cin>>n>>k;
	vector<int>arr;
	for(int i=0;i<n;i++){
		int x; cin>>x;
		arr.push_back(x);
	}
	
	int sum=0;
	sort(arr.begin(),arr.end());
	for(int i=0;i<k;i++){
		sum+=arr[i];
	}
	cout<<sum;
		

}

int main(){
	solve();
}


Measured memory_bytes: 3608
#include <iostream>

#define MAX 100005
#define NIL -1

struct Node{int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u){
  int i, c;
  std::cout << "node " << u << ": ";
  std::cout << "parent = " << T[u].p << ", ";
  std::cout << "depth = " << D[u] << ", ";

  if (T[u].p == NIL) std::cout << "root, ";
  else if (T[u].l == NIL) std::cout << "leaf, ";
  else std::cout << "internal node, ";

  std::cout << "[";

  for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if (i) std::cout << ", ";
    std::cout << c;
  }
  std::cout << "]" << std::endl;
}


void rec(int u, int p){
  D[u] = p;
  if (T[u].r != NIL) rec(T[u].r, p);
  if (T[u].l != NIL) rec(T[u].l, p + 1);
}
int main() {
  int i, j, d, v, c, l, r;
  std::cin >> n;
  for ( i = 0; i < n; i++) T[i].p = T[i].l = T[i].r  = NIL;

  for ( i = 0; i < n; i++) {
    std::cin >> v >> d;
    for ( j = 0; j < d; j++) {
      std::cin >> c;
      if (j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for ( i = 0; i < n; i++) {
    if (T[i].p == NIL) r = i;
  }

  rec(r, 0);

  for ( i = 0; i < n; i++) print(i);

  return 0;
}



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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        ll h,w;
        cin>>h>>w;
        char g[h][w];
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                cin>>g[i][j];
        ll dp[h][w];
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                dp[i][j]=0;
        dp[0][0]=1;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(i==0&&j==0||g[i][j]=='#')
                    continue;
                else if(i==0)
                    dp[i][j]+=dp[i][j-1];
                else if(j==0)
                    dp[i][j]+=dp[i-1][j];
                else
                    dp[i][j]+=dp[i-1][j]+dp[i][j-1];
                dp[i][j]%=MOD;
            }
        }
        cout<<dp[h-1][w-1];
    }
}

Measured memory_bytes: 12440
col=list(map(str,input().split()))
num=list(map(int,input().split()))
U=str(input())
if U == col[0]:
  num[0] = num[0]-1
elif U == col[1]:
  num[1] = num[1]-1
[print(num[i],end=" ") for i in range(2)]

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
  public static void main(String[] args) throws IOException {
    String[] strs;
    String[] nums;
    try(BufferedReader br
        = new BufferedReader(new InputStreamReader(System.in))
    ){
      strs = br.readLine().split(" ");
      nums = br.readLine().split(" ");
    }
    int N = Integer.parseInt(strs[0]);
    int K = Integer.parseInt(strs[1]);
    int sum = 0;
    Set<Integer> s = new HashSet<Integer>();
    for (int i = 0; i < K; i++) {
      s.add(Integer.parseInt(nums[i]));
    }
    
    for (int n = N; n <= 100000; n++) {
      boolean f = true;
      String nSize = String.valueOf(n);
      int tmp = n;
      for (int j = 0; j < nSize.length(); j++) {
        if (s.contains(tmp % 10)) {
          f = false;
          break;
        }
        tmp /= 10;
      }
      if (f) {
        sum = n;
        break;
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 23764
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int ans = Math.max(a + b, Math.max(a - b, a * b));

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21716
N, X, Y = map(int, input().split())
res = [0] * N
for i in range(1, N):
    for j in range(i+1, N+1):
        d = min(j-i, abs(X-i) + abs(Y-j) + 1)
        res[d] += 1

for i in range(N-1):
    print(res[i+1])


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
#define debug(x) cout<<x;
    
int a[105];
    
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m;
    cin>>n>>m;

    int ans=0;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        ans+=a[i];
    }

    sort(a+1,a+n+1);

    int pd=0;
    double res=1.0*ans/(4*m);
    for (int i=n;i;i--)
    {
        if (double(a[i])>=res)
            m--;
        else pd=1;

        if (!m) break;
    }

    if (pd) cout<<"No\n";
    else cout<<"Yes\n";

    return 0;
}

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

static const int PMAX = (int)2e5;

int main()
{
    std::vector<bool> pmap(PMAX, true);
    std::vector<int> ps {};
    for (int i = 2; i < PMAX; i++)
    {
        if (!pmap[i])
        {
            continue;
        }
        ps.push_back(i);
        for (int j = i; j < PMAX; j += i)
        {
            pmap[j] = false;
        }
    }
    
    int n;
    std::cin >> n;
    auto i = std::lower_bound(ps.begin(), ps.end(), n);
    std::cout << *i << std::endl;
    
    return 0;
}



Measured memory_bytes: 512
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, q;
    scan(n, q);
    auto s = readln.chomp;
    auto c = new int[](n + 1);
    foreach (i ; 2 .. n + 1) {
        debug {writeln(s[i - 2 .. i]);}
        c[i] = s[i - 2 .. i] == "AC";
    }
    foreach (i ; 1 .. n + 1) {
        c[i] += c[i - 1];
    }
    debug {
        writeln(c);
    }

    foreach (i ; 0 .. q) {
        int li, ri;
        scan(li, ri);
        int ans = c[ri] - c[li];
        writeln(ans);
    }
}


























int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 4476
#include <iostream>
#include <queue>
using namespace std;
int main(){
	priority_queue<int> s;
	int N,K;
	cin>>N>>K;
	for(int i=1;i<=N;i++){
		int temp;
		cin>>temp;
		s.push(temp);
	}
	while(K--&&!s.empty())
		s.pop();
	long long ans=0;
	while(!s.empty()){
		ans+=s.top();
		s.pop();
	}
	cout<<ans<<endl;
	return 0 ;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int ans[100005];

int main()
{
	char S[100005];
	cin >> S;
	int N = strlen(S);
	int H[100005];
	bool v = true;
	int fin = 0;
	for (int i = 1; i < N; i++)
	{
		
		if (v&&S[i] == 'R') continue;
		else if (v&&S[i] == 'L')
		{
			for (int j = fin; j < i; j++)
			{
				H[j] = i - 1;
			}
			fin = i;
			v = false;
		}
		else if (!v&&S[i] == 'L') continue;
		else if (!v&&S[i] == 'R')
		{
			for (int j = fin; j < i; j++)
			{
				H[j] = fin;
			}
			fin = i;
			v = true;
		}
	}
	for (int i = fin; i < N; i++)
	{
		H[i] = fin;
	}



	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'R')
		{
			if ((H[i] - i) % 2 == 0) ans[H[i]]++;
			else ans[H[i] + 1]++;
		}
		if (S[i] == 'L')
		{
			if ((i - H[i]) % 2 == 0) ans[H[i]]++;
			else ans[H[i] - 1]++;
		}
	}

	for (int i = 0; i < N; i++)
	{
		cout << ans[i] << " ";
	}

	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    ll N, min,max;
    ll A[200005],B[200005];
    ll sum = 1000000,tmp,tmp2=0,tmp1=0;
    ll min_cnt,max_cnt;

    cin>>N;
    for(int i=0; i<N;i++){
        cin >> A[i];
        B[i] = A[i] - (i+1);
        if(B[i]<0){
            min_cnt++;
        }else if(B[i]>0){
            max_cnt++;
        }
    }
    sort(B,B+N);

    ll b = B[N/2];
    ll b1 = B[N/2 + 1];
    ll b2 = B[N/2 - 1];

    //for(ll b = min; b <= max; b++){
    tmp = 0;
    for(int i=0; i<N;i++){
        B[i] = abs(A[i] - (i + 1 + b));
        tmp += B[i];
    }
    for(int i=0; i<N;i++){
        B[i] = abs(A[i] - (i + 1 + b1));
        tmp1 += B[i];
    }
    for(int i=0; i<N;i++){
        B[i] = abs(A[i] - (i + 1 + b2));
        tmp2 += B[i];
    }
    sum=tmp;
    //cout<<tmp<<endl;
    if(sum > tmp2){
        sum = tmp2;
        // cout<<"b:"<<b<<endl;
    } 
    if(sum > tmp1){
        sum = tmp1;
        // cout<<"b:"<<b<<endl;
    } 
    //}
    cout << sum << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;
    
    vector<ll> A(26, 0), B(26, 0);
    REP(i,0,N) ++A[S[i]-'a'];
    
    ll m = 0;
    REP(i,0,N) {
        ll cnt = 0;
        --A[S[i]-'a'];
        ++B[S[i]-'a'];
        REP(j,0,26) cnt = ((A[j] != 0) && (B[j] != 0)) ? cnt+1 : cnt;
        m = MAX(m,cnt); 
    }
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 3644
let dist a b c d = abs(a-c)+abs(b-d) in
Scanf.scanf "%d %d " @@ fun n m ->
  let a = Array.make n 0 in
  let b = Array.make n 0 in
  for i=0 to n-1 do
    Scanf.scanf "%d %d " @@ fun ai bi ->
      a.(i) <- ai;
      b.(i) <- bi
  done;
  let c = Array.make m 0 in
  let d = Array.make m 0 in
  for j=0 to m-1 do
    Scanf.scanf "%d %d " @@ fun cj dj ->
      c.(j) <- cj;
      d.(j) <- dj
  done;
  for i=0 to n-1 do
    let min = ref max_int in 
    let index = ref 0 in
    for j=0 to m-1 do
      let distance = dist a.(i) b.(i) c.(j) d.(j) in 
      if !min > distance then (
        min := distance; index := j
      )
    done;
    Printf.printf "%d\n" (!index+1)
  done


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
 
 
#define int long long
using namespace std;
 
 
signed main(){
	int n;
	cin >> n;
	vector <int> a(n);
 
	int ans = 1e18 + 7;
	int sum = 0;
	for (int i = 0; i < n; ++i){
		cin >> a[i];
		sum += a[i];
	}
 
	int pref = 0;
	for (int i = 0; i < n - 1; ++i){
		pref += a[i];
		ans = min(ans, abs(pref - (sum - pref)));
	}
 
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);

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

    int N,Q;
    cin>>N>>Q;
    vector<pair<int, pair<int, int>>> stx(N);
    rep(i,N){
        cin>>stx[i].second.first>>stx[i].second.second>>stx[i].first;
    }
    //xでソート
    sort(all(stx));
    vector<int> S(N), T(N), X(N);
    rep(i,N){
        S[i] = stx[i].second.first;
        T[i] = stx[i].second.second;
        X[i] = stx[i].first;
    }
    vector<int> D(Q), ans(Q, -1);
    set<int> set;
    map<int, int> idx;
    rep(i,Q){
        cin>>D[i];
        idx[D[i]] = i;
        set.insert(D[i]);
    }

    rep(i,N){
        auto l_itr = set.lower_bound(S[i] - X[i]);
        while(l_itr != set.end()){
            if(*l_itr >= T[i] - X[i])break;
            ans[idx[*l_itr]] = X[i];
            set.erase(l_itr++);
        }
    }
    rep(i,Q){
        cout<<ans[i]<<endl;
    }
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    if(a - b == 0)
      ans++;
    else
      ans = 0;

    if(ans == 3) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}


Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<pair<long, long>> LR(N);
  vector<long> L;
  vector<long> R;

  rep (i, N) {
    long l, r;
    cin >> l >> r;
    LR[i] = make_pair(l, r);
    L.push_back(l);
    R.push_back(r);
  }

  // 1問とその他に分けるケースのカバー
  long one_and_others = 0;
  {
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    sort(R.begin(), R.end());
    for (auto it: LR) {
      long first_L = it.first;
      long first_R = it.second;
      long first_score = first_R - first_L + 1;
      long second_L = L[0];
      long second_R = R[0];
      if (second_L == first_L) second_L = L[1];
      if (second_R == first_R) second_R = R[1];
      long second_score = second_R - second_L + 1;
      if (second_score < 0) second_score = 0;
      one_and_others = max(one_and_others, first_score + second_score);
    }
  }

  // LRを昇順に並べ、どこかで前と後ろの2つに分ける
  sort(LR.begin(), LR.end());

  vector<long> minRmemo(N); // 先頭〜N番目までのRの最小値
  vector<long> minRmemoRev(N); // N番目〜末尾までのRの最小値
  minRmemo[0] = LR[0].second;
  for (long i = 1; i < N; i++) {
    minRmemo[i] = min(minRmemo[i-1], LR[i].second);
  }
  minRmemoRev[N-1] = LR[N-1].second;
  for (long i = N - 2; i >= 0; i--) {
    minRmemoRev[i] = min(minRmemoRev[i+1], LR[i].second);
  }

  long split_ans = 0;
  for (long i = 0; i < N - 1; i++) {
    long first_score = minRmemo[i] - LR[i].first + 1;
    if (first_score < 0) first_score = 0;

    long second_score = minRmemoRev[i+1] - LR[N-1].first + 1;
    if (second_score < 0) second_score = 0;

    split_ans = max(split_ans, first_score + second_score);
  }

  // 「1問+その他」パターンと、「昇順ちょんぎりパターン」のうち、大きい方を答えとする
  long ans = max(one_and_others, split_ans);
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 5228
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(o) {cerr<<#o<<" "<<o<<endl;}
#define DUMPC(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (string s; cin >> s;) {
		int d[12] = {};
		REP(i, s.size())d[s[i] - '0']++;
		string ans = "";
		FOR(x, 1, 10) {
			//DUMP(x);
			int e[12] = {};
			REP(i, 12)e[i] = d[i];
			e[x]++;
			if (*max_element(e, e + 10) <= 4) {
				//?????¢?????°???
				FOR(y, 1, 10) {
					int c[12] = {};
					REP(i, 12)c[i] = e[i];
					if (c[y] >= 2)c[y] -= 2;
					else continue;
					//DUMP(y)
					//DUMPC(c)
					//????????????????¶????
					FOR(z, 1, 10) {
						if (c[z] < 0) {
							break;
						}
						if (c[z] >= 3) {
							c[z] -= 3;
						}
						if (c[z] <= 2) {
							c[z + 1] -= c[z];
							c[z + 2] -= c[z];
							c[z] = 0;
						}
					}
					//DUMPC(c);
					if (*min_element(c, c + 12) == 0 && *max_element(c, c + 12) == 0) {
						ans += char(x + '0');
						ans += " ";
						break;
					}
				}
			}
		}
		if (ans == "") cout << 0 << endl; 
		else cout << ans.substr(0, ans.size() - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
from itertools import accumulate
N = int(input())
a = list(map(int, input().split()))
cum = [0] + list(accumulate(a))
# dp[i][j] := merge i..j
dp = [[0] * N for i in range(N)]
for l in range(1, N):
    for i in range(N-l):
        j = i + l
        dp[i][j] = cum[j+1] - cum[i] + min(dp[i][k] + dp[k+1][j] for k in range(i, j))
print(dp[0][N-1])

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

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

const ll INF = 1LL<<60;
const int MAX_V = 100100;

int main() {
    int n, W;
    cin >> n >> W;
    vector<vector<ll>> dp(n+1, vector<ll>(MAX_V, INF));
    dp[0][0] = 0;
    rep(i, n) {
        int w, v;
        cin >> w >> v;
        rep(j, MAX_V) {
            int jv = j-v;
            
            if (jv >= 0) {
               chmin(dp[i+1][j], dp[i][jv]+w);
            }
            
            chmin(dp[i+1][j], dp[i][j]);

            // printf("dp[%d] = %lld\n", j, dp[i+1][j]);
        }
    }

    ll ans = 0;
    rep(i, MAX_V) if (dp[n][i]<=W) ans = i; 
    cout << ans << endl;

    return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && b == c && c == a){
    cout << 1 << endl;
  }
  else if(a != b && b != c && c != a){
    cout << 3 << endl;
  }
  else{
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
char buf[30000];
sz;
N,H,W;
main()
{
	read(0,buf,30000);
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		H=H*10+k-'0';
	}
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		W=W*10+k-'0';
	}
	int ans=0;
	for(int i=0;i<N;i++)
	{
		int A=0,B=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			B=B*10+k-'0';
		}
		ans+=A>=H&&B>=W;
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long

using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0LL, c - a + b) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)2e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

vector<vector<int> > xc(100001), yc(100001);

PII func(PII p){
    PII res(0, 0);
    if(!xc[p.first].empty()){
        vector<int> line = xc[p.first];
        xc[p.first].clear();
        ++res.first;
        for(auto &i:line){
            res = res + func(PII(p.first, i));
        }
    }
    if(!yc[p.second].empty()){
        vector<int> line = yc[p.second];
        yc[p.second].clear();
        ++res.second;
        for(auto &i:line){
            res = res + func(PII(i, p.second));
        }
    }
    return res;
}

signed  main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a<=c and c<=b ? "Yes":"No") << endl;
}



Measured memory_bytes: 4992
n = int(input())

ans = []
a = n
while a != 0:
    b = a % (-2)
    a //= (-2)
    if b == -1:
        a += 1
        b = 1
    ans.append(b)
if not ans: ans = [0]
ans.reverse()    
print(*ans, sep='')        


Measured memory_bytes: 9104