akhauriyash/Code-Regression huggingface dataset:
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))



#bfs内で処理すると使い回しが効かないのでsearch_color とか幅探索後の具体的な処理は別個にしたほうがいい
def bfs(s,n,node):
    check=[-1 for _ in range(n)]
    check[0]=0
    
    side_num_arr=list(map(lambda x :len(x),node))
    l=max(side_num_arr)
    #print(l)
    queue=[-1 for _ in range(n)]
    now=0
    queue[now]=s
    ans=[-1 for _ in range(n)]
    ans[0]=[0]
    last_ind=1
    while last_ind<n:
        
        if now>=n:
            return []
        check[queue[now]]=True
        if side_num_arr[queue[now]]<=0:
            now+=1
            continue
        for i in node[queue[now]]:
            edge=i[0]
            
            ind=i[1]
            if side_num_arr[edge]<=0 or check[edge]==True:
                continue
            side_num_arr[edge]-=1
            side_num_arr[queue[now]]-=1
            queue[last_ind]=edge
            last_ind+=1
            check[edge]=True
            
            ans[edge]=queue[now]
        now+=1
    return ans



n,m=input_list()
node=[[] for _ in range(n)]
for i in range(m):
    u,v=input_list()
    u-=1
    v-=1
    node[u].append([v,i])
    node[v].append([u,i])

#print(np.array(node))

ans=bfs(0,n,node)
if len(ans)==0:
    print("No")
    exit()

print("Yes")
for each in ans[1:]:
    print(each+1)








Measured memory_bytes: 92192
import java.util.Scanner;

class dice {
	private int _u, _s, _e, _w, _n, _d;
	dice(int[] a) {
		_u = a[0];
		_s = a[1];
		_e = a[2];
		_w = a[3];
		_n = a[4];
		_d = a[5];
	}
	void roll(char o) {
		int temp;
		switch (o) {
			case 'E' :
				temp = _e;
				_e = _u;
				_u = _w;
				_w = _d;
				_d = temp;
				break;
			case 'N' :
				temp = _n;
				_n = _u;
				_u = _s;
				_s = _d;
				_d = temp;
				break;
			case 'S' :
				temp = _s;
				_s = _u;
				_u = _n;
				_n = _d;
				_d = temp;
				break;
			case 'W' :
				temp = _w;
				_w = _u;
				_u = _e;
				_e = _d;
				_d = temp;
				break;
		}
	}
	int top() {
		return _u;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] num = new int[6];
		for (int i = 0; i < 6; ++i) {
			num[i] = sc.nextInt();
		}
		sc.nextLine();
		dice d = new dice(num);
		String str = sc.nextLine();
		for (int i = 0; i < str.length(); ++i) {
			d.roll(str.charAt(i));
		}
		System.out.println(d.top());
	}
}


Measured memory_bytes: 26248
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
int main(){
ll n;
cin >>n;
ll p[n];
REP(i,n){
cin >>p[i];
}
map<ll,ll> a;
REP(i,n){
a[p[i]-1]=i;
}
ll count=1;
ll max=0;
REP(i,n-1){
if(a[i]>a[i+1]){
if(max<count)
max=count;
count=1;
}
else
count++;
}
if(max<count)
max=count;

cout<<n-max;
return 0;
}

Measured memory_bytes: 14336
#include<iostream>
using namespace std;
int main(){
    int a,b=0,c=0;
    cin>>a;
    if(a==5)b++;
    if(a==7)c++;
    cin>>a;
    if(a==5)b++;
    if(a==7)c++;
    cin>>a;
    if(a==5)b++;
    if(a==7)c++;
    if(b==2&&c==1)cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

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

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = a+b+c+d;
    printf("%d\n%d\n", ans/60, ans%60);
    return 0;
}



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

int main()
{
    
    int n;
    while(1){
        cin>>n;
        if(n==0)
            break;

        vector<int> s(n);

        for(int i=0;i<n;i++){
            cin>>s.at(i);
        }

        long double mean=0;
        for(int i=0;i<n;i++){
            mean +=s.at(i);
        }
        mean /=(long double)n;

        long double dist=0,sd;
        for(int i=0;i<n;i++){
            dist+=pow((s.at(i)-mean),2);
        }
        dist/=(long double)n;
        sd=sqrt(dist);

        cout << fixed << setprecision(15) << sd << endl;
    }

    return 0;
}


Measured memory_bytes: 3248
#include <stdio.h>
int main (void){
        int N,A,B,now,ans=0,sum;
        scanf("%d",&N);
        scanf("%d",&A);
        scanf("%d",&B);

        for (int i = 1; i <= N; i++) {
                now=i;
                sum=0;
                for(; now!=0; now/=10) {
                        sum+=(now%10);
                }
                if(sum>=A&&sum<=B) {
                        ans+=i;
                        //  printf("%d\n",sum);
                }
        }

        printf("%d",ans);
        return 0;
}

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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  string s;
  cin >> s;
  ll ans = 0;
  int a_count = 0;
  REP(i,s.length()-1) {
    if(s[i] == 'A') {
      ++a_count;
      continue;
    }
    if(s[i] == 'B' && s[i+1] == 'C') {
      ans += a_count;
      ++i;
      continue;
    }
    a_count = 0;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<fstream>
#include<stack>
using namespace std;

using ll = long long;
const int MAXI = 1024 * 128;

int n, m;
ll a[MAXI];
vector<vector<int> > g;
vector<pair<ll, int> > arr;
int pred[MAXI];
char used[MAXI];
map<int, int> minInPred;

void input() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		used[i] = 0;
	}

	g.resize(n);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
}

bool arr_comp(const pair<ll, int> &p1, const pair<ll, int> &p2) {
	return p1.first < p2.first;
}

void dfs(int v) {
	stack<int> s;
	used[v] = 1;
	pred[v] = v;
	int minInd = v;
	s.push(v);
	while (!s.empty()) {
		int x = s.top();
		if (a[minInd] > a[x])
			minInd = x;
		s.pop();
		for (int i = 0; i < g[x].size(); i++) {
			if (!used[g[x][i]]) {
				used[g[x][i]] = 1;
				s.push(g[x][i]);
				pred[g[x][i]] = v;
			}
		}
	}
	minInPred.insert(make_pair(v, minInd));
}

void auxConstructions() {
	for (int i = 0; i < n; i++)
		arr.push_back(make_pair(a[i], i));
	sort(arr.begin(), arr.end(), arr_comp);

	for (int i = 0; i < n; i++) 
		if (!used[i]) 
			dfs(i);

	for (int i = 0; i < n; i++)
		used[i] = 0;
}

int findPred(int v) {
	if (v != pred[v])
		pred[v] = findPred(pred[v]);
	return pred[v];
}

ll algo() {
	
	ll sum = 0LL;

	if (n < 2 * (n - m - 1))
		return -1;
	if (n == m + 1)
		return 0;
	
	for (map<int, int>::iterator it = minInPred.begin(); it != minInPred.end(); it++) {
		used[it->second] = 1;
		sum += a[it->second];
	}

	for (int i = 0, k = n - m; i < n, k < 2 * (n - m - 1); i++) {
		if (!used[arr[i].second]) {
			sum += arr[i].first;
			k++;
		}
	}
	
	return sum;

	/*
	int t1 = 0, t2 = 1;

	ll sum = 0LL;

	while (t2 < n) {
		while (t2 < n && (used[t2] || findPred(arr[t1].second) == findPred(arr[t2].second)))
			t2++;

		if (t2 == n)
			break;

		sum += arr[t1].first + arr[t2].first;
		
		pred[findPred(arr[t1].second)] = findPred(arr[t2].second);

		used[t1] = 1;
		used[t2] = 1;
		while (t1 < n && used[t1])
			t1++;
		while (t2 < n && (used[t2] || t1 == t2))
			t2++;
	}

	int bigPred = findPred(0);
	for (int i = 1; i < n; i++)
		if (findPred(i) != bigPred)
			return -1LL;

	return sum;
	*/
}

int main() {

	input();
	auxConstructions();
	ll sum = algo();
	if (sum >= 0LL)
		cout << sum;
	else
		cout << "Impossible";

	return 0;
}

Measured memory_bytes: 11504
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    int x,c;
	scanf("%d",&x);
	for(int i=0;i<x;i++){
		scanf("%d",&c);
		printf("Case %d:\n",i+1);
		for(int j=1;j<=10;j++){
			c=c*c;
			c%=1000000;
			c/=100;
			printf("%d\n",c);
		}
	}
    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000

int main(){

	int N;
	cin>>N;
	
	vector<long long> A(N);
	
	for(int i=0;i<N;i++)cin>>A[i];
	
	int now = 1;
	
	long long ans = 0;
	
	for(int i=0;i<N;i++){
		if(A[i]==now){
			now ++;
			continue;
		}
		else{
			ans += (A[i]-1)/now;
			if(now==1)now++;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main (){
  
  int W[10],K[10],s1,s2;

  for(int i=0; i < 10 ; i++){
    cin >>W[i];
  }
  
  for(int i=0; i < 10 ; i++){
    cin >>K[i];
  }

  sort(W,W+10);
  sort(K,K+10);

  s1=W[9]+W[8]+W[7];
  s2=K[9]+K[8]+K[7];

  cout <<s1<<" "<<s2<<endl;

  return 0;

}
  

Measured memory_bytes: 1180
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,n;
    cin >> a>>b>>n;
    /*
    for(ll i=1;i<=n;i++){
        cout<<(a*i/b)-a*(i/b)<<"\n";
    }
    */
    if(b-1>n)
        cout << (a * (n) / b) - a * ((n) / b) << "\n";
    else
    cout<<(a*(b-1)/b)-a*((b-1)/b)<<"\n";
}


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

ll INF = 1e15;

ll dist[51][2510];

int main() {
  int N, M, S;
  cin >> N >> M >> S;
  S = min(S, 2500);
  vector<vector<ll>> A(N, vector<ll>(N)), B(N, vector<ll>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      A[i][j] = B[i][j] = INF;
    }
    A[i][i] = B[i][i] = 0;
  }
  for (int i = 0; i < M; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    A[u][v] = A[v][u] = a;
    B[u][v] = B[v][u] = b;
  }

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

  for (int i = 0; i < 51; i++) {
    for (int j = 0; j < 2510; j++) {
      dist[i][j] = INF;
    }
  }
  dist[0][S] = 0;
  priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>,
                 greater<pair<ll, pair<int, int>>>>
      que;
  que.push({0, {0, S}});
  while (!que.empty()) {
    ll d = que.top().first;
    int v = que.top().second.first;
    int s = que.top().second.second;
    que.pop();
    // cout << d << " " << v << " " << s << endl;
    if (dist[v][s] < d) continue;

    if (s < 2500 && d + D[v] < dist[v][min(s + C[v], 2500)]) {
      dist[v][min(s + C[v], 2500)] = d + D[v];
      que.push({d + D[v], {v, min(s + C[v], 2500)}});
    }

    for (int u = 0; u < N; u++) {
      if (u == v || A[v][u] == INF || s < A[v][u]) continue;
      if (d + B[v][u] < dist[u][s - A[v][u]]) {
        dist[u][s - A[v][u]] = d + B[v][u];
        que.push({d + B[v][u], {u, s - A[v][u]}});
      }
    }
  }

  for (int i = 1; i < N; i++) {
    ll ans = INF;
    for (int j = 0; j <= 2500; j++) {
      ans = min(ans, dist[i][j]);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 6344
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            Dictionary<string, int> stringMap = new Dictionary<string, int>();

            for (int i = 0; i < N; i++)
            {
                string s = Console.ReadLine();
                IEnumerable<char> cs = s.OrderBy(c => c);
                string sortedS = new string(cs.ToArray());
                if (!stringMap.ContainsKey(sortedS)) stringMap.Add(sortedS, 1);
                else stringMap[sortedS]++;
            }

            long ans = 0;

            foreach (var item in stringMap)
            {
                ans += (long)item.Value * (long)(item.Value - 1) / 2;
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }


}


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

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static Dictionary<int, long> memo;
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int m = cin.Int();
			memo = new Dictionary<int, long>();
			Dictionary<int, bool> a = new Dictionary<int, bool>();
			for (int i = 0; i < m; i++) {
				a[cin.Int()] = true;
			}

			long ans = DFS(0, a, n);
			Console.WriteLine(ans);
		}
		
		public static long DFS(int n, Dictionary<int, bool> a, int max)
		{
			if (n >= max) {
				return 1;
			}

			if (memo.ContainsKey(n)) {
				return memo[n];
			}

			long ret = 0;
			if (a.ContainsKey(n + 1) == false) {
				ret = (ret + DFS(n + 1, a, max)) % MOD;
			}

			if (n + 2 <= max && a.ContainsKey(n + 2) == false) {
				ret = (ret + DFS(n + 2, a, max)) % MOD;
			}

			memo[n] = ret;

			return ret;
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 24156
#include <cstdio>
#include <algorithm>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;
  cout << max(a+b, max(a-b, a*b)) << endl;
  return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;

int dp[100010][4];
int A[100010];
int B[100010];
int C[100010];

void Main()
{
	int N; cin >> N;
	rep(i,N) {
		int a, b, c; cin >> a >> b >> c;
		A[i] = a;
		B[i] = b;
		C[i] = c;
	}
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	rep(i,N) {
		dp[i + 1][0] = max(dp[i][1] + A[i], dp[i][2] + A[i]);
		dp[i + 1][1] = max(dp[i][0] + B[i], dp[i][2] + B[i]);
		dp[i + 1][2] = max(dp[i][0] + C[i], dp[i][1] + C[i]);
	}
	int res = max({dp[N][0], dp[N][1], dp[N][2]});
	cout << res << endl;
}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main(){
int n;cin>>n;
int a[n];
rep(i,n)cin>>a[i];
int count=0;
rep(i,n) if(a[i]!=i+1)count++;
if(count<=2)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
N,A,B,C = map(int, input().split())
L = [A,B,C]
l = []       
for n in range(N):
    l.append(int(input()))

mp = []
for i in range(4**N):
    Test = [0,0,0]
    MP = 0
    for j in range(N):
        n = i%4
        if n < 3:
            MP += 10 if Test[n] else 0
            Test[n] += l[j]
        i >>= 2
    for i in range(3):
        MP += abs(L[i]-Test[i]) if Test[i] else 3000
    mp.append(MP)

print(min(mp))

Measured memory_bytes: 5728
#include<bits/stdc++.h>
using namespace std;
#define y1 y114514
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define M 1000000007
#define all(a) a.begin(), a.end()
typedef long long ll;

int main(){
	int n;
	scanf("%d", &n);
	if(n == 3) puts("2 5 63");
	else if(n == 4) puts("2 5 20 63");
	else if(n == 6) puts("3 4 5 6 8 34");
	else{
		if(n & 1){
			int tot = min(15000, n - 2);
			while((tot % 3 != 0 && tot % 3 != 2) || tot % 2 != 1) --tot;
			for(int i = 1; i <= tot; ++i) printf("%d ", i * 2);
			n -= tot;
			for(int i = 1; i <= n; ++i) printf("%d ", 3 * (2 * i - 1));
		}else{
			int tot = min(15000, n - 2);
			while((tot % 3 != 0 && tot % 3 != 2) || tot % 2 != 0) --tot;
			for(int i = 1; i <= tot; ++i) printf("%d ", i * 2);
			n -= tot;
			for(int i = 1; i <= n; ++i) printf("%d ", 3 * (2 * i - 1));
		}
	}
	
#ifndef ONLINE_JUDGE
	system("pause");
#endif
	return 0;
}


Measured memory_bytes: 632
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
S = [0] * 2
S[0] = input()
S[1] = input()

ans = 1
prev = 1 # 1 = vertical, 2 = horizontal
i = 0
if S[0][0] == S[1][0]:
    ans *= 3
    i += 1
    prev = 1
else:
    ans *= 6
    i += 2
    prev = 2

while i < N:
    if S[0][i] == S[1][i]:
        if prev == 1:
            ans *= 2 
        else:
            ans *= 1
        i += 1
        prev = 1
    else:
        if prev == 2:
            ans *= 3
        else:
            ans *= 2 
        i += 2
        prev = 2
    ans %= MOD
print(ans)

Measured memory_bytes: 9476
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

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

ll lcm(ll a, ll b)  {
    return (a*b)/gcd(a, b);
}

ll fact(ll n){
    if(n==0)
        return 1;
    else
        return n*fact(n-1);
}

void solve(){

    ll N;
    cin>>N;
    ll c = 0, f= 0;
    while(N--){
        ll x,y;
        cin>>x>>y;
        if(x==y){
            c++;
        }
        else{
            c = 0;
        }
        if(c==3)
            f = 1;
    }
    if(f==1)
        cout<<"Yes";
    else
        cout<<"No";




}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("D:\\codes\\1input.txt","r",stdin);
    //freopen("D:\\codes\\1output.txt","w",stdout);
    ll T=1;
    //cin>>T;
    for(ll t=1;t<=T;t++){
        //cout<<"Case #"<<t<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 3640
#include<stdio.h>
int main()
{int i,j,k,m,H,W;

for(m=1;;m++)
{scanf("%d%d",&H,&W);
if(H==0 && W==0)break;
for(i=1;i<=H;i++)
{
    if(i==1||i==H)
    {for(j=1;j<=W;j++)
    {
        printf("#");
    }
    }

    else
    {for(k=1;k<=W;k++)
     if(k==1||k==W)
     {
         printf("#");
     }

    else printf(".");
    }
    printf("\n");
    }
    printf("\n");
}
return 0;
}



Measured memory_bytes: 2056
package main

import "fmt"

func main() {
	var n, ans, i, j int64
	ans = 0
	fmt.Scanf("%d", &n)

	for i = 1; i*i <= n; i++ {
		if n%i == 0 {
			j = n / i
			ans = i + j - 2
		}
	}
	fmt.Printf("%d", ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main () {
  int n;
  cin >> n;
  // vector<string> S(n);
  vector<int> min_count(26, 100);
  for(int i=0;i<n;++i){
    string S;
    cin >> S;
    
    vector<int> count(26, 0);
    for(auto c: S){
      count[c - 'a'] ++;
    }
    for (int j=0;j<26;++j){
      min_count[j] = min(min_count[j], count[j]);
    }
  }
  for (int j=0;j<26;++j){
    char c = 'a' + j;
    for (int k=0; k<min_count[j]; ++k){
      cout << c;
    }
  }
}


Measured memory_bytes: 3528
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ct = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500 + b*100 + c*50 == X:
                ct += 1

print(ct)

Measured memory_bytes: 39536
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
cnt = 0
#bubbleSort(A, N)
flag = 1
while flag:
    flag = 0
    for i in range(N - 1, 0, -1):
        if A[i] < A[i - 1]:
            a = A[i]
            b = A[i - 1]
            A[i] = b
            A[i - 1] = a
            flag = 1
            cnt += 1
print(' '.join(map(str, A)))
print(cnt)


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

int main() {
	ll n;
	cin>>n;
	if(n==1){
		cout<<1<<endl;
		return 0;
	}
	vector<ll>v(n+1);
	v.at(0)=2;
	v.at(1)=1;
	for(int i=2;i<n+1;i++){
		v.at(i)=v.at(i-1)+v.at(i-2);
	}
	cout<<v.at(n)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

char z[6][6];

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

    int H,W,K;cin>>H>>W>>K;
    int tot=0;
    for (int i=0;i<H;i++) {
      for (int j=0;j<W;j++) {
        cin>>z[i][j];
        if (z[i][j]=='#') tot++;
      }
    }
    int res=0;
    for (int m1=0;m1 < (1<<H);m1++) {
      for (int m2=0;m2 < (1<<W);m2++) {
        int cnt=tot;
        for (int i=0;i<H;i++) {
          for (int j=0;j<W;j++){
            if (!(m2&(1<<j)) && !(m1&(1<<i))) continue;
            if (z[i][j]=='#')
              cnt--;
          }
        }
        if (cnt==K) res++;
      }
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll w,h,n,l=0,d=0;
    cin>>w>>h>>n;
    vector<ll> x(n),y(n),a(n);
    rep(i,n) {
        cin>>x[i]>>y[i]>>a[i];
    }
    rep(i,n){
        if(a[i]==1){
            l = max(x[i],l);
        }else if(a[i]==2){
            w = min(x[i],w);
        }else if(a[i]==3){
            d = max(y[i],d);
        }else if(a[i]==4){
            h = min(y[i],h);
        }
    }
    if((w-l)<0 || (h-d)<0) cout<<0<<endl;
    else cout<<(w-l)*(h-d)<<endl;
    return 0;
}

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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

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

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

vector<vector<int>> all_comb(int n, int k) {
  vector<vector<int>> combs(nCr(n, k), vector<int>(k));
  for(int i=0; i<k; i++) {
    combs[0][i] = i;
    combs[1][i] = i;
  }
  
  for(long i=1; i<nCr(n, k); i++) {
    int p = 1;
    while(combs[i][k - p] == n - p) {
      p++;
      if(p > k) {
        break;
      }
    }
    combs[i][k - p]++;
    int q = combs[i][k - p];
    for(int j=1; j<p; j++) {
      combs[i][k - p + j] = q + j;
    }

    if(i < nCr(n, k) - 1) {
      for(int j=0; j<k; j++) {
        combs[i + 1][j] = combs[i][j];
      }
    }
  }

  return combs;
}

int main() {
  std::cout << std::setprecision(9);
  string s;
  cin >> s;

  vector<char> s_c(s.begin(), s.end());
  vector<int> ans(s_c.size(), 0);
  int last_change = 0;
  for(int i=1; i<s_c.size(); i++) {
    if(s_c[i] == 'R' && s_c[i - 1] == 'L') {
      last_change = i;
    }
    if(s_c[i] == 'L' && s_c[i - 1] == 'R') {
      vector<int> mini_ans(2, 0);
      for(int j=last_change; j<s_c.size(); j++) {
        if(s_c[j] == 'R' && s_c[j - 1] == 'L' && j > i) {
          break;
        }
        mini_ans[j % 2]++;
      }
      ans[i] = mini_ans[i % 2];
      ans[i - 1] = mini_ans[(i - 1) % 2];
    }
  }

  for(int i=0; i<s_c.size(); i++) {
    if(i > 0) {
      cout << ' ';
    }
    cout << ans[i];
  }
  cout << endl;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N,H;cin>>N>>H;
  std::vector<int> a(N),b(N);
  for(int i=0;i<N;i++)cin>>a[i]>>b[i];typedef pair<int,int> P;
  std::vector<P> v(2*N);
  for(int i=0;i<N;i++)v[i]=P(a[i],0);
  for(int i=0;i<N;i++)v[i+N]=P(b[i],1);
  sort(v.rbegin(),v.rend());
  int ans=0;
  for(int i=0;i<2*N;i++){
    if(H<=0){cout<<ans<<endl;return 0;}
    if(v[i].second){H-=v[i].first;ans++;}
    else{
      cout<<ans+(H-1)/v[i].first+1<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 4992
// Last modify : 2019年01月23日 星期三 23时15分59秒
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int main()
{
    bool ok;
    int N, Y;
    while (cin >> N >> Y)
    {
        ok = false;
        Y /= 1000;
        // 10 5 1 组成 Y，共 N 张
        for (int i = 0; i <= Y / 10; i++)
        {
            for (int j = 0; j * 5 + i * 10 <= Y; j++)
            {
                int x = N - i - j;
                if (Y - 10 * i - 5 * j - x == 0) 
                {
                    printf("%d %d %d\n", i, j, x);
                    ok = true;
                }
                if (ok) break;
            }
            if (ok) break;
        }
        if (!ok) printf("-1 -1 -1\n");
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;
		int puls = 1;
		
		while (puls<B) {
			puls--;
			 puls +=A;
			 ans++;
			
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    N = int(inp.readline().strip())
    V = list(map(int, inp.readline().strip().split(' ')))
    V = sorted(V)
    r = V[0]
    for v in V:
        r = (r + v) / 2
    return str(r)


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import sys

N, K = map(int, input().split())
H = list(map(int, input().split()))
DP = [0] * N  # N番目までに使用する最小エネルギ-
for n in range(1, N):
    if n == 1:
        DP[1] = abs(H[1] - H[0])
    else:
        min_value = sys.maxsize
        for j in range(1, K + 1 if K < n else n+1):
            tmp_dpn = abs(H[n] - H[n - j]) + DP[n - j]
            if tmp_dpn < min_value:
                min_value = tmp_dpn
        DP[n] = min_value
print(DP[-1])


Measured memory_bytes: 52448
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    long K = lread();
    long N = S.length;
    long[] len;
    long i;
    while (i < N)
    {
        long l;
        char prev = S[i];
        while (i + l < N && S[i + l] == prev)
            l++;
        len ~= l;
        i += l;
    }
    if (len.length == 1)
    {
        writeln(len[0] * K / 2);
        return;
    }
    long ans = len.map!"a/2"().sum() * K;
    if (S[0] == S[$ - 1])
    {
        ans -= (len[0] / 2) * (K - 1);
        ans -= (len[$ - 1] / 2) * (K - 1);
        ans += ((len[0] + len[$ - 1]) / 2) * (K - 1);
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main()
{
	int n;
	cin >> n;
	vector<int> c(n - 1), s(n - 1), f(n - 1), ans(n);
	int tmp = 0;
	rep(i, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}
	rep(i, n - 1) {
		ans[i] = s[i] + c[i];
		for (int j = i + 1; j < n - 1; ++j) {
			if (ans[i] < s[j])	ans[i] = s[j] + c[j];
			else {
				ans[i] = s[j] + f[j] * ceil(double(ans[i] - s[j]) / f[j]) + c[j];
			}
		}
	}
	ans[n - 1] = 0;

	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
 
    void run(){
        Scanner sc = new Scanner(System.in);
        for(;;){
            int n = sc.nextInt();
            if(n==0)break;
            int[] id = new int[n], p = new int[n], q = new int[n], r = new int[n];
            for(int i=0;i<n;i++){
                id[i] = sc.nextInt();
                p[i] = sc.nextInt();
                q[i] = sc.nextInt();
                r[i] = sc.nextInt();
            }
            List<Integer> l = new ArrayList<Integer>();
            int P = sc.nextInt(), Q = sc.nextInt(), R = sc.nextInt(), C = sc.nextInt();
            for(int i=0;i<n;i++){
                if(p[i]<=P && q[i]<=Q && r[i]<=R && p[i]*4+q[i]*9+r[i]*4<=C)l.add(id[i]);
            }
            if(l.isEmpty())System.out.println("NA");
            else for(int x:l)System.out.println(x);
        }
    }
     
    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 65608
import java.util.*;

public class Main{ 
        
    public static void main(String[] args){
      
       Scanner sc = new Scanner(System.in);
       
       int x = sc.nextInt();
       int a = sc.nextInt();
       int b = sc.nextInt();
       
       System.out.println(Math.abs(b-x) > Math.abs(a-x) ? "A":"B");                                                 
       
    }    
}       



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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

const int mod=1000000007;

int main(){
  int n;
  cin>>n;
  string s1,s2;
  cin>>s1;
  cin>>s2;
  long long ans;
  if(s1[0]==s2[0]){
    ans=3;
    rep(i,1,n){
      if(s1[i]==s2[i]&&s1[i-1]==s2[i-1]){
        ans*=2;
        ans%=mod;
      }
      else if(s1[i]==s2[i]&&s1[i-1]!=s2[i-1]){
        ans%=mod;
      }
      else if(s1[i]!=s2[i]&&s1[i-1]==s2[i-1]){
        ans*=2;
        ans%=mod;
        ++i;
      }
      else if(s1[i]!=s2[i]&&s1[i-1]!=s2[i-1]){
        ans*=3;
        ans%=mod;
        ++i;
      }
    }
  }
  else{
    ans=6;
    rep(i,2,n){
      if(s1[i]==s2[i]&&s1[i-1]==s2[i-1]){
        ans*=2;
        ans%=mod;
      }
      else if(s1[i]==s2[i]&&s1[i-1]!=s2[i-1]){
        ans%=mod;
      }
      else if(s1[i]!=s2[i]&&s1[i-1]==s2[i-1]){
        ans*=2;
        ans%=mod;
        ++i;
      }
      else if(s1[i]!=s2[i]&&s1[i-1]!=s2[i-1]){
        ans*=3;
        ans%=mod;
        ++i;
      }
    }
  }
  cout<<ans<<endl;
}
      
      
  


Measured memory_bytes: 256
using System;

namespace AOJ
{
    class AOJ0202
    {
        static void Main(string[] args)
        {
            var ps = Prims(1000000);

            for (;;)
            {
                var line = Console.ReadLine ().Split ();
                var n = int.Parse(line[0]);
                var m = int.Parse(line[1]);
                if (n == 0 && m == 0) break;

                var xs = new int[n];
                for (var i = 0; i < n; i++)
                {
                    xs[i] = int.Parse(Console.ReadLine());
                }

                var ans = 0;
                var dp = new bool[m + 1];
                dp[0] = true;
                for (var i = 0; i < n; i++)
                {
                    for (var j = xs[i]; j <= m; j++)
                    {
                        if (dp[j - xs[i]])
                        {
                            dp[j] = true;
                            if (ps[j])
                            {
                                ans = Math.Max(ans, j);
                            }
                        }
                    }
                }

                Console.WriteLine(ans != 0 ? ans.ToString() : "NA");
            }
        }

        static bool[] Prims(int n)
        {
            bool[] prims = new bool[n + 1];

            for (var i = 2; i <= n; i++) prims[i] = true;

            for (var i = 2; i <= n; i++)
            {
                if (prims[i])
                {
                    for (var j = i + i; j <= n; j += i) prims[j] = false;
                }
            }

            return prims;
        }
    }
}

Measured memory_bytes: 11064
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

signed main() {
   tezz
   
   int n,m;
   cin >> n >> m;
   string s[n];
   for(int i=0; i<n; i++){
       cin >> s[i];
   }
   int dp[n][m];
   bool flag=true;
   for(int i=0; i<n; i++){
       if(flag && s[i][0]=='.')dp[i][0]=1;
       else dp[i][0]=0,flag=false;
   }
   flag=true;
   for(int i=0; i<m; i++){
       if(flag && s[0][i]=='.')dp[0][i]=1;
       else dp[0][i]=0,flag=false;
   }
   for(int i=1; i<n; i++){
       for(int j=1; j<m; j++){
           if(s[i][j]=='.')dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
           else dp[i][j]=0;
       }
   }
   cout << dp[n-1][m-1]%mod << endl;
   
   return 0;
}


Measured memory_bytes: 9088
#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 << "Left" << endl;
  else if (a+b == c+d) cout << "Balanced" << endl;
  else cout << "Right" << endl;
  
}

Measured memory_bytes: 256
n=int(input())
a=[]*6
[a.append(int(input())) for x in range(n)]
minimam_num=a[0]
abs_num = -1001001001
for i in range(1,n):
    if minimam_num > a[i-1]:
        minimam_num=a[i-1]
    if abs_num < (a[i]-minimam_num):
        abs_num=(a[i]-minimam_num)
print(abs_num)


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size()/2; ++i) {
        if (s[i] != s[s.size()-1-i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
N,x = map(int,(input().split()))
if N == 2:
    if x == 2:
        print("Yes")
        for i in range(1,4):
            print(i)
    else:
        print("No")
else:
    M = 2*N-1
    if x == 1 or x ==M:
        print("No")
    else:
        print("Yes")

        ans = [0]*(M)
        num = deque(list(range(1,M+1)))
        if x == 2:
            ans[M//2] = x
            ans[M//2-1] = 1
            num.remove(x)
            num.remove(1)
            for i in range(M):
                if ans[i] == 0:
                    ans[i] = num.popleft()
        else:
            ans[M//2] = x
            ans[M//2-1] = x+1
            ans[M//2-2] = x-2
            ans[M//2+1] = x-1
            num.remove(x)
            num.remove(x+1)
            num.remove(x-2)
            num.remove(x-1)
            for i in range(M):
                if ans[i] == 0:
                    ans[i] = num.popleft()
    
        for i in range(M):
            print(ans[i])

Measured memory_bytes: 55000
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << (a==b?a*2:max(a,b)*2-1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 2147483647

struct edge{
	int to,cost;
};
int V,E; 

vector <edge> G[100010];

multimap <int,int> l;


ll d[500010];


void dijkstra(int s){
	fill(d,d+V,INF);
	d[s] = 0;
	
	l.insert(make_pair(0,s));
	
	while(l.size() > 0){
		int p = l.begin()->first;
		int v = l.begin()->second;
		l.erase(l.begin());
		
		if(d[v] < p) continue;
		
		for(int i = 0;i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				l.insert(make_pair(d[e.to], e.to));
			}
		}
	}
}


int main(){
	
	int r;
	cin >> V >> E >> r;
	for(int i = 0;i < E; i++){
 		edge e;
		int from;
		cin >> from >> e.to >> e.cost;
		G[from].push_back(e);
	}
	
	dijkstra(r);
	
	for(int i = 0;i < V; i++){
		if(d[i] != INF) cout << d[i] << endl;
		else cout << "INF" <<endl;
	}
	return 0;
} 

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

using namespace std;

int solve(int l, int r, int d) {
    int cnt = 0;
    for (int i = l; i <= r; i ++) {
        if (i % d == 0) cnt ++;
    }

    return std::move(cnt);
}

int main() {
    int l, r, d;

    cin >> l >> r >> d;
    cout << solve(l, r, d) << endl;

    return 0;
}

Measured memory_bytes: 3584
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#define N 200100

//head

int n;
int a[N], b[N];
stack<int> st1, st2;

void print() {
  cout << "Yes\n";
  rep(i, n) cout << b[i] << (i == n-1?'\n':' ');
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  reverse(b, b+n);
  int u = -1;
  rep(i, n) {
    if(a[i] == b[i]) u = i;
  }
  if(u == -1) {
    print();
    return 0;
  }
  int z = a[u];
  auto itr = equal_range(a, a+n, z);
  int la = itr.first-a;
  int ra = itr.second-a;
  reverse(b, b+n);
  itr = equal_range(b, b+n, z);
  int lb = n-(itr.second-b);
  int rb = n-(itr.first-b);
  reverse(b, b+n);
  if(ra-la + rb-lb > n) {
    cout << "No\n";
    return 0;
  }
  rep(i, n) {
    if((la > i or ra <= i) and (lb > i or rb <= i)) {
      if(!st2.empty()) {
        swap(b[i], b[st2.top()]);
        st2.pop();
      }
      else st1.emplace(i);
    }
    else if(la <= i and i < ra and lb <= i and i < rb) {
      if(!st1.empty()) {
        swap(b[i], b[st1.top()]);
        st1.pop();
      }
      else st2.emplace(i);
    }
  }
  print();
}

Measured memory_bytes: 5548
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define U 1000000007
#define N 100005
#define ins insert
using namespace std;
vector<int>v[N];
int n, dp[N][2];
int dfs(int s, int par, int c){
    if(dp[s][c]!=-1) return dp[s][c];

    dp[s][c]=1;
    rep(i,0,sz(v[s])){
        if(par!=v[s][i]){
            int ns=1;
            if(c==0) ns=dfs(v[s][i],s,1);
            else ns=dfs(v[s][i],s,0)+dfs(v[s][i],s,1);
            dp[s][c]*=ns;
            dp[s][c]%=U;
        }
    }
    return dp[s][c];
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    rep(i,0,n-1){
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    rep(i,0,N) rep(j,0,2) dp[i][j]=-1;
    int ans=dfs(1,-1,0)+dfs(1,-1,1);
    cout<<ans%U;




}

Measured memory_bytes: 15616