akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int N;
vector<long long> A;
vector<long long> sum;

int main() {
    cin >> N;
    A.resize(N); sum.resize(N + 1); sum[0] = 0;
    for (int i = 0; i < N; ++i) cin >> A[i], sum[i + 1] = sum[i] + A[i];

    long long res = 1LL << 60;
    for (int i = 0; i <= N; ++i) {
        // P < Q となる最大の切れ目を求める: 二分探索を終えた時の left_low
        int low = 0, high = i;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] >= sum[i] - sum[mid]) high = mid;
            else low = mid;
        }
        long long P = sum[low], Q = sum[i] - sum[low]; // 候補1
        long long P2 = sum[high], Q2 = sum[i] - sum[high]; // 候補2
        long long left_min = min(P, Q), left_max = max(P, Q);
        if (abs(P2 - Q2) < abs(P - Q)) left_min = min(P2, Q2), left_max = max(P2, Q2);

        low = i, high = N;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] - sum[i] >= sum[N] - sum[mid]) high = mid;
            else low = mid;
        }

        long long R = sum[low] - sum[i], S = sum[N] - sum[low];
        long long R2 = sum[high] - sum[i], S2 = sum[N] - sum[high];
        long long right_min = min(R, S), right_max = max(R, S);
        if (abs(R2 - S2) < abs(R - S)) right_min = min(R2, S2), right_max = max(R2, S2);

        long long tmp = max(left_max, right_max) - min(left_min, right_min);
        res = min(res, tmp);
    }
    cout << res << endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string s;
	cin >> s;

	int w;
	cin >> w;

	rep(i, s.size()){
		if(i % w == 0) cout << s[i];
	}

	cout << endl;
}

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

int main() {
	int n, q;
	int cnt = 0;;

	cin >> n;
	int* S = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> S[i];
	}


	cin >> q;
	int* T = new int[q];
	for (int i = 0; i < q; i++) {
		cin >> T[i];
	}

	for (int i = 0; i < q; i++) {
		for (int j = 0; j < n; j++) {
			if (T[i] == S[j]) {
				cnt++;
				break;
			}
		}
	}

	cout << cnt << endl;

	delete[] S;
	delete[] T;
	return 0;

}


Measured memory_bytes: 3104
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N;
    cin >> N;
    if (N / 100 == N % 10)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from functools import reduce
N = int(input())
T = []
for _ in range(N):
    T.append(int(input()))


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def lcm(a, b):
    if b > a:
        b, a = a, b
    return a * b // gcd(a, b)


x = reduce(lcm, T)
print(x)


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    for (int i = 0; i < 3; i++) reverse(s[i].begin(), s[i].end());

    while (true) {
        static int now = 0;
        if (s[now].empty()) {
            cout << (now == 0 ? 'A' : now == 1 ? 'B' : 'C') << endl;
            break;
        }
        int nxt = s[now].back() - 'a';
        s[now].pop_back(), now = nxt;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;

signed main(){
    int n,ch,m,s;
    cin >> n;
    m = n/2 * (n/2 - 1 )*2;
    if(n % 2 == 0){
        ch = 0;
        s = n + 1;
    } else {
        ch = 1;
        s = n;
        m += n-1;
    }
    cout << m << endl;
    rep(i, s-1) {
        for(int j = i;j < s-1;j++) {
            if(i != j && i + j + 2 != s) {
                cout << i+1 << ' ' << j+1 << endl;     
            }
        }
    }
    if(ch == 1) {
        rep(i, s - 1) {
            cout << i+1 << ' ' << s << endl; 
        }
    }
    return 0;
}

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

#define ll long long int

using namespace std;


int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    int cnt=1;
    if(a[1]!=a[0]) cnt++;
    if(a[2]!=a[1]) cnt++;
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
s = gets
i = s.split('').map(&:to_i)
c = ''
c = 'No'
c = []
2.times do |o|
  if i[o] == 9
    c = 'Yes'
  else
    c = 'No'
  end
  if c == 'Yes'
    break
  end
end
puts c

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int A[200000], B[200000], N;
int main(){
  int i, k;
  long long res;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  for(i=0;i<N;i++){
    if(A[i]!=B[i]){
      break;
    }
  }
  if(i==N){
    wt_L(0);
    putchar_unlocked('\n');
    return 0;
  }
  k = 1073709056;
  for(i=0;i<N;i++){
    if(A[i] > B[i]){
      chmin(k, B[i]);
    }
  }
  res = -k;
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<(N-1) + 1;KL2GvlyY++){
      res += A[KL2GvlyY];
    }
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180208-1

// --- original code ---
// int N, A[2d5], B[2d5];
// {
//   int i, k;
//   ll res;
//   rd(N,(A,B)(N));
//   
//   rep(i,N) if(A[i]!=B[i]) break;
//   if(i==N){
//     wt(0);
//     return 0;
//   }
// 
//   k = int_inf;
//   rep(i,N) if(A[i] > B[i]) k <?= B[i];
// 
//   res = -k;
//   res += A[0..N-1];
//   
//   wt(res);
// }


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

ll cal(ll H){
  if(H == 1){
    return 1;
  }
  return 1 + 2 * cal(H/2);
}

int main(){
  ll H;
  cin >> H;
  cout << cal(H) << endl;
  return 0;
}


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


using lli = long long int;
template <class T> using Vec = std::vector<T>;
template <class T> using Wec = std::vector<Vec<T>>;

struct P{
    int a;
    int b;
    int c;
    bool operator ==(P other)const{
        return (a == other.a) and (b == other.b) and (c == other.c);
    }
    bool operator <(P other)const{
        if(a != other.a) return a < other.a;
        if(b != other.b) return b < other.b;
        return c < other.c;
    }
};

int main(void){
    int a, b, c; scanf("%d%d%d", &a, &b, &c);
    /*  a_{n+1} = (b_n + c_n) / 2
        b_{n+1} = (c_n + a_n) / 2
        c_{n+1} = (a_n + b_n) / 2 */
    std::set<P> F; F.insert({a, b, c});
    int cnt = 0;
    while(a % 2 == 0 and b % 2 == 0 and c % 2 == 0){
        P T = {a, b, c};
        a = (T.b + T.c) >> 1;
        b = (T.c + T.a) >> 1;
        c = (T.a + T.b) >> 1;
        T = {a, b, c};
        if(F.find(T) != F.end()){ puts("-1"); return 0;}
        else{ F.insert(T); cnt++;}
    }
    printf("%d\n", cnt);
    return 0;
}

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

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    int ans = x / (y + z);
    int tmp = (y + z) * ans;

    if(x - tmp < z) cout << ans - 1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int ans = 700;
  string s;
  cin >> s;
  rep(i,3){
    if(s[i]=='o')ans +=100;
  }
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int n, k;
  cin >> n >> k;
  int l[n];
  for(int i = 0; i < n; i++){
    cin >> l[i];
  }

  sort(l, l + n);
  int sum = 0;
  for(int i = n - 1; i >= n - k; i--){
    sum += l[i];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    e = collections.defaultdict(list)
    for _ in range(n-1):
        a,b = LI()
        e[a].append(b)
        e[b].append(a)

    t = -1
    for i in range(n):
        if len(e[i]) > 2:
            t = i
            break
    if t < 0:
        return 1

    def f(i, s):
        c = 0
        t = 0
        for d in e[i]:
            if d == s:
                continue
            r = f(d, i)
            if r == 0:
                c += 1
            else:
                t += r

        if c > 1:
            t += c - 1
        return t

    return f(t, -1)



print(main())




Measured memory_bytes: 87544
import sys
input = sys.stdin.readline
A, B, K = map(int, input().split())
chk = K - A
if chk > 0:
    if K - A - B >= 0:
        print(0, 0)
    else:
        print(0, A + B - K)
elif chk <= 0:
    print(A-K, B)

Measured memory_bytes: 38384
def main():
    D = int(input())
    C = list(map(int,input().split()))
    S = []
    for _ in range(D):
        s = list(map(int,input().split()))
        S.append(s)

    ans = 0

    last = [0] * 26
    for j in range(1,D+1):
        t = int(input())
        last[t-1] = j
        SUM = 0
        for i in range(26):
            SUM += C[i] * (j-last[i])
        ans -= SUM
        ans += S[j-1][t-1]
        print(ans)

main()

Measured memory_bytes: 9356
#include <stdio.h>

int gcd(int a,int b);
int gcd3(int a,int b,int c);
void swap(int* a,int* b);

int main(void)
{
    int k=0;
    int sum=0;
    scanf("%d",&k);


    for(int h=1;h<=k;h++){
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                sum+=gcd3(h,i,j);
            }
        }
    }

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

int gcd(int a,int b){
    int temp=0;
    if(a<b) swap(&a,&b);
    do{
        temp=b;
        b=a%b;
        a=temp;
    } while (b!=0);
    return a;
}

int gcd3(int a,int b,int c){
    int ab=0;
    ab=gcd(a,b);
    if(ab<c) swap(&ab,&c);

    return gcd(ab,c);
}

void swap(int* a,int* b){
    int temp=0;
    temp=*a;
    *a=*b;
    *b=temp;
}


Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long double a, b, c;
    cin >> a >> b >> c;
    long double x = sqrtl(a * b);
    if (2 * x < c - a - b)
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
  
    return 0;
}

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

using namespace std;

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

	map<long long, long long> cnt;
	for(int i = 0; i < N; i++){
        cnt[a[i]]++;
    }

	bool ans = false;

    if(cnt.size() == 1 && cnt[0] == N){
		ans = true;
	}else if(cnt.size() == 2){
        long long b[2];
		long long d[2];
		long long c = 0;
		for(auto i : cnt){
			b[c] = i.second;
			d[c] = i.first;
			c++;
		}

		sort(b, b+2);
		sort(d, d+2);
        
		if(N % 3 == 0){
			if(cnt[d[1]] == cnt[d[0]]*2 && d[0] == 0){
                ans = true;
            }
		}
    }else if(cnt.size() == 3){
        long long b[3];
		long long d[3];
		long long c = 0;
		for(auto i : cnt){
			b[c] = i.second;
			d[c] = i.first;
			c++;
		}

        sort(b, b+3);

        if(N % 3 == 0 && ((d[0]^d[1])==d[2])&&((d[0]^d[2])==d[1])&&((d[1]^d[2])==d[0])){
            if(b[0] == N/3 && b[1] == N/3 && b[2] == N/3){
                ans = true;
            }
        }
    }

	cout << (ans ? "Yes" : "No") << endl;


    return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>

using namespace std;
#define DEBUG(x) cout<<#x<<": "<<x<<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INT(a) int((a)+1e-9)
int DX[4]={1,0,-1,0};
int DY[4]={0,1,0,-1};

#define EMP 0
#define OBS 1
#define WAL 4
#define STT 2
#define GOA 3

#define SUPmaxY 22
#define SUPmaxX 22

int maxY,maxX;
int field[SUPmaxX][SUPmaxY];
int startX,startY;
int result;


int dfs(int x, int y, int depth){
	//DEBUG(x);DEBUG(y);DEBUG(depth);
	if(depth>=result) return 0;
	if(field[x][y]==GOA) {result=depth; return 0;}
	
	FOR(di,0,4){
		int nx=x; int ny=y;
		int dx=DX[di]; int dy=DY[di];
		if(field[x+dx][y+dy]==OBS) continue;
		while(field[nx][ny]==EMP){
			nx+=dx;ny+=dy;
		}
		if(field[nx][ny]==WAL){continue;}
		if(field[nx][ny]==GOA){result=depth+1; return 0;}
		if(field[nx][ny]==OBS){
			field[nx][ny]=EMP;
			dfs(nx-dx,ny-dy,depth+1);
			field[nx][ny]=OBS;
		}
	}
	

}



int main(){
	while(true){
		cin>>maxY>>maxX;			if(!maxY) return 0;
		maxX+=2;maxY+=2;
		FOR(x,0,maxX) FOR(y,0,maxY) field[x][y]=WAL;
		FOR(x,1,maxX-1) FOR(y,1,maxY-1) cin>>field[x][y];
		FOR(x,1,maxX-1) FOR(y,1,maxY-1) if(field[x][y]==STT){startX=x;startY=y;field[x][y]=EMP;}

		result=11;
		dfs(startX,startY,0);
		cout<< ((result==11)?-1:result) <<endl;
	}
}

Measured memory_bytes: 1160
/*
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

ll factor(ll x) {
	ll ret = 1;
	ll tmp = 0;
	for (ll p = 2;;p++) {
		if (x == 1) {
			ret *= tmp + 1;
			break;
		}
		if (x % p == 0) {
			tmp += 1;
			x /= p;
			p--;
			continue;
		}
		ret *= tmp + 1;
		tmp = 0;
	}
	return ret;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start

	ll N;
	cin >> N;
	ll ans = 0;

	for (ll i = 1; i <= N; i++) {
		ll ret = factor(i);
		ll tmp = ret;
		ans += i * tmp;
	}

	cout << ans << endl;



EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}


*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	string N;
	cin >> N;
	for (int i = 0; i < N.size(); i++) {
		if (N[i] == '0') {
			continue;
		}
		if ((N[i] - '0') % 7 == 0) {
			cout << "Yes" << endl;
			goto EndPoint;
		}
	}
	cout << "No" << endl;

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3108
using System;
using System.Linq;
namespace ABC
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine(Console.ReadLine()=="1" ?
				"Hello World" :
				(int.Parse(Console.ReadLine()) + int.Parse(Console.ReadLine())).ToString()
			);
		}
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define SIZE 100105
using namespace std;

struct point{
	int x;
	int y;
	int ind;
}p[SIZE], sx[SIZE], sy[SIZE];
bool cmpx(point a, point b){
	return a.x<b.x;
}
bool cmpy(point a, point b){
	return a.y<b.y;
}

struct edge{
	int u, v, w;
	edge(){};
	edge(int uu, int vv, int ww){
		u=uu;
		v=vv;
		w=ww;
	}
}ed[4*SIZE];

bool cmpw(edge a, edge b){
	return a.w<b.w;
}

int eds;
int n;
int par[SIZE];
int sz[SIZE];

int root(int x){
	if(par[x]==x) return x;
	return root(par[x]);
}

int merger(int u, int v, int w){
	u=root(u);
	v=root(v);
	if(u==v) return 0;
	if(sz[u]<sz[v]) swap(u, v);
	sz[u]+=sz[v];
	par[v]=par[u];
	return w;
}

void init(){
	for(int i=0; i<SIZE; i++){
		par[i]=i;
		sz[i]=1;
	}
}

void construct_edges(){
	sort(sx, sx+n, cmpx);
	sort(sy, sy+n, cmpy);
	eds=0;
	for(int i=0; i<(n-1); i++){
		ed[eds]=edge(sx[i].ind, sx[i+1].ind, sx[i+1].x-sx[i].x);
		eds++;
		ed[eds]=edge(sy[i].ind, sy[i+1].ind, sy[i+1].y-sy[i].y);
		eds++;
	}
	sort(ed, ed+eds, cmpw);
}

int kruskal(){
	int res=0;
	init();
	construct_edges();
	for(int i=0; i<eds; i++){
		res+=merger(ed[i].u, ed[i].v, ed[i].w);
	}
	return res;
}

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d %d", &p[i].x, &p[i].y);
		p[i].ind=i;
		sx[i]=sy[i]=p[i];
	}
	printf("%d\n", kruskal());
	return 0;
}


Measured memory_bytes: 9216
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let a1 = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let a2 = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let ans = ref 0 in
  for i=0 to n-1 do
    let tmp = ref 0 in
    for j=0 to i do
      tmp := !tmp + a1.(j);
    done;
    for k=i to n-1 do
      tmp := !tmp + a2.(k);
    done;
    if !tmp > !ans then ans := !tmp else ();
  done;

  Printf.printf "%d\n" !ans


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

int main(){
    //input
    int n; 
    cin >> n;
    int A[n];
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    
    //first output
    for(int j=0;j<n-1;j++){
        cout << A[j] << " ";
    }
    cout << A[n-1] << endl;
    
    //calculation and output
    for(int i=1;i<n;i++){
        int key = A[i];
        int j = i-1;
        while(j>=0 & A[j]>key){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;
        
        //output
        for(int j=0;j<n-1;j++){
            cout << A[j] << " ";
        }
        cout << A[n-1] << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;


int main(){
    int t=1;
    //cin>>t;
    while(t--){
        int r;
        cin>>r;
        ld pi=3.14;
        cout<<2*r*pi;
    }
    return 0;
}
    

Measured memory_bytes: 3756
using System;
class StepUpSum{
	static void Main(){
		for(;;){
			string s=Console.ReadLine();
			if(s==null)break;
			long n=long.Parse(s);
			if(n==0)break;
			long r=0;
			int i=2;
			for(;;i++){
				long x=n-(long)i*(i-1)/2;
				if(x<i)break;
				if(x%i==0)r++;
			}
			Console.WriteLine(r);
		}
	}
}

Measured memory_bytes: 9212
import sys

def merge(A, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = []
    R = []
    for i in range(n1):
        L.append(A[left+i])
    for i in range(n2):
        R.append(A[mid+i])
    L.append("INFTY")
    R.append("INFTY")
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
        global c
        c += 1


def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right) / 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    N = int(lines[0])
    nums = [int(n) for n in lines[1].split(" ")]
    c = 0
    mergeSort(nums, 0, N)
    print " ".join(map(str, nums))
    print c

Measured memory_bytes: 75420
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn=500;
const int maxm=200000;
const int maxq=100000;

int N,M,Q;
int cnt[maxn+1][maxn+1]={0};
int q_1[maxq],q_2[maxq];
int sum[maxn+1][maxn+1]={0};

int main(){
    
    cin >> N >> M >>Q;
    
    rep(i,M){
        int a,b;
        scanf("%d%d",&a,&b);
        cnt[a][b]++;
    }
    
    rep(i,Q){
        scanf("%d%d",&q_1[i],&q_2[i]);
        q_1[i];q_2[i];
    }
    
    rep(i,N+1){
        rep(j,N){
            cnt[i][j+1]+=cnt[i][j];
        }
    }
    
    
    rep(i,Q){
        int res=0;
        for(int j=q_1[i];j<=q_2[i];j++){
            res+=cnt[j][q_2[i]]-cnt[j][q_1[i]-1];
        }
        printf("%d\n",res);
    }
    
    return 0;
}



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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;

int main() {
	int h, w;
	cin >> h >> w;

	char a[101][101];
	rep(i, h){
		rep(j, w){
			cin >> a[i][j];
		}
	}

	bool h_flag[101];
	bool w_flag[101];
	rep(j, w){
	w_flag[j] = true;
		rep(i, h){
			if(a[i][j] == '#'){
				w_flag[j] = false;
				break;
			}
		}
	}

	rep(i, h){
	h_flag[i] = true;
		rep(j, w){
			if(a[i][j] == '#'){
				h_flag[i] = false;
				break;
			}
		}
	}

	rep(i, h){
		if(h_flag[i] == false){
			rep(j, w){
				if(w_flag[j] == false){
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;

typedef pair<int, int> p;

namespace SCC{
    vector<int> g[1 << 17], r[1 << 17], dfn;
    int chk[1 << 17], pv;
    void dfs(int v){
        chk[v] = 1;
        for(auto i : g[v]){
            if(!chk[i]) dfs(i);
        }
        dfn.push_back(v);
    }
    void rdfs(int v, int color){
        chk[v] = color;
        for(auto i : r[v]){
            if(!chk[i]) rdfs(i, color);
        }
    }
    void getSCC(int n){
        memset(chk, 0, sizeof chk); dfn.clear();
        for(int i=0; i<n; i++) if(!chk[i]) dfs(i);
        memset(chk, 0, sizeof chk); pv = 0; reverse(all(dfn));
        for(auto i : dfn) if(!chk[i]) rdfs(i, ++pv);
    }
    void init(){
        for(int i=0; i<(1 << 17); i++){
            g[i].clear(), r[i].clear();
        }
    }
    void addEdge(int s, int e){
        g[s].push_back(e); r[e].push_back(s);
    }
};
using namespace SCC;

const int sz = 1 << 16, inv = 1 << 15;
int n, x[101010], y[101010], id[101010][2];
vector<p> pt;

void connect(int now, int l, int r, int node = 1, int s = 0, int e = sz-1){
    if(l > r) return;
    if(r < s || e < l) return;
    if(l <= s && e <= r){
        addEdge(now, node); return;
    }
    int m = s + e >> 1;
    connect(now, l, r, node << 1, s, m);
    connect(now, l, r, node << 1 | 1, m+1, e);
}

int solve(int m){
    init();
    for(int i=1; i<(1 << 16); i++){
        addEdge(i, i << 1);
        addEdge(i, i << 1 | 1);
    }
    for(int i=0; i<n; i++){
        addEdge(id[i][0] | sz | inv, id[i][1] | sz);
        addEdge(id[i][1] | sz | inv, id[i][0] | sz);
    }
    for(int i=0; i<n; i++){
        int a = lower_bound(all(pt), p(x[i]-m+1, -1)) - pt.begin();
        int b = upper_bound(all(pt), p(x[i]+m, -1)) - pt.begin() - 1;
        connect(id[i][0] | sz, a | inv, id[i][0] - 1 | inv);
        connect(id[i][0] | sz, id[i][0] + 1 | inv, b | inv);
        a = lower_bound(all(pt), p(y[i]-m+1, -1)) - pt.begin();
        b = upper_bound(all(pt), p(y[i]+m, -1)) - pt.begin() - 1;
        connect(id[i][1] | sz, a | inv, id[i][1] - 1 | inv);
        connect(id[i][1] | sz, id[i][1] + 1 | inv, b | inv);
    }
    getSCC(1 << 17);
    for(int i=0; i<inv; i++) if(chk[i | sz] == chk[i | sz | inv]) return 0;
    return 1;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i];
        if(x[i] > y[i]) swap(x[i], y[i]);
        pt.push_back({x[i], i});
        pt.push_back({y[i], i+n});
    }
    sort(all(pt));
    for(int i=0; i<n; i++){
        id[i][0] = lower_bound(all(pt), p(x[i], i)) - pt.begin();
        id[i][1] = lower_bound(all(pt), p(y[i], i+n)) - pt.begin();
    }
    int l = 0, r = 1e9+7;
    while(l < r){
        int m = l + r + 1 >> 1;
        if(solve(m)) l = m;
        else r = m - 1;
    }
    cout << l;
}

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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<int, int>> vpi;
typedef long long LL;

const lld INF = (1ll) << 56;
const long long OO = 2e18;
const double pi = 2 * acos(0.0);

lld dp[2001][2001], n, m, c = 0 ;
char  a[1001][1001];

//TOP-DOWN
lld gridOne(lld i, lld j) {
	lld count1 = 0, count2 = 0;
	if (i > n - 1 || j > m - 1) return dp[i][j] = 0;
	if (i == n - 1 && j == m - 1) {
		return dp[i][j] = (count1 + count2 + 1) % MOD;
	}
	if (dp[i][j] != -1) return dp[i][j];
	if (a[i + 1][j] == '.') count1 = max(count1, gridOne(i + 1, j) ) ;
	if (a[i][j + 1] == '.')	count2 = max(count2, gridOne(i, j + 1) ) ;
	return dp[i][j] = (count1 + count2) % MOD;
}

int main() {
	fast;
	cin.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	lld i, j;
	cin >> n >> m;
	memset(dp, -1, sizeof(dp));
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	cout << gridOne(0, 0) << endl;

}

Measured memory_bytes: 32640
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9, mod = 1e9 + 7;
const long long OO = 1e18+25;

int n, m,u,v, mx, mem[N];
vector <int> g[N];

int dp(int p)
{
    int &ret = mem[p];
    if(ret != 0) return ret;
    for(int to : g[p])
        ret = max(ret, dp(to)+1);
    return ret;
}

int main()
{
    scanf("%d%d",&n,&m);
    while(m--)
    {
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
    }
    for(int i=1; i <= n; i++)
    {
        mx = max(mx, dp(i));
    }
    printf("%d\n",mx);
    return 0;
}
	     		 					   	 	 								 	

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}

};

string a, b;
int ans;

void rec(string s,int l) {
	if (ans <= l)return;
	int loc = -1;
	rep(i, s.size()) {
		if (s[i] != b[i]) {
			loc = i; break;
		}
	}
	if (loc == -1)ans = l;
	int dif = (b[loc] - s[loc] );
	rep(i,s.size() - loc) {
		int c = s[loc + i]-'0';
		c = (c + dif + 10) % 10;
		s[loc + i] = c + '0';
		rec(s, l + 1);
	}
}

void solve(int n) {
	cin >> a >> b;
	ans = INF;
	rec(a,0);
	cout << ans << endl;
}

int main() {
	int n;
	while (cin >> n, n) {
		solve(n);
	}
}



Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {
	public static void main(String[] args) throws Exception {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		ArrayList<String> list1 = new ArrayList<String>();
		int[] list2 = new int[3001];
		int[] list3 = new int[3001];
		int i = 0;
		while (true) {
			list1.add(br.readLine());

			list2[i] = Integer.parseInt(SubStringStart(list1.get(i)));//???????????°???
			list3[i] = Integer.parseInt(SubStringEnd(list1.get(i)));//????°??????°???
			if (list2[i] == 0 && list3[i] == 0) {
				for (int k = 0; k < list1.size(); k++) {
					if (list2[k] > list3[k]) {
						System.out.println(list3[k] + " " + list2[k]);
					} else if (list2[k] < list3[k]) {
						System.out.println(list2[k] + " " + list3[k]);
					} else if (list2[k] == list3[k] && list2[k] != 0 && list3[k] != 0) {
						System.out.println(list2[k] + " " + list3[k]);
					}
				}
				break;
			}
			i = i + 1;
		}
	}

	public static String SubStringStart(String str) {
		int index = str.indexOf(" ");
		return (str.substring(0, index));
	}

	public static String SubStringEnd(String str) {
		int index = str.indexOf(" ");
		return (str.substring(index + 1));
	}
}
//class Main {
//	public static void main(String[] args) throws Exception {
//		InputStreamReader is = new InputStreamReader(System.in);
//		BufferedReader br = new BufferedReader(is);
//
//		String[] list1 = new String[3001];
//		int[] list2 = new int[3001];
//		int[] list3 = new int[3001];
//		int i = 0;
//		while (true) {
//			list1[i] = br.readLine();
//
//			list2[i] = Integer.parseInt(SubStringStart(list1[i]));//???????????°???
//			list3[i] = Integer.parseInt(SubStringEnd(list1[i]));//????°??????°???
//			if (list2[i] == 0 || list3[i] == 0) {
//				for (int k = 0; k < list1.length; k++) {
//					if (list2[k] > list3[k]) {
//						System.out.println(list3[k] + " " + list2[k]);
//					} else if(list2[k] < list3[k]){
//						System.out.println(list2[k] + " " + list3[k]);
//					}else if(list2[k] == list3[k]|| list2[k]!=0|| list3[k]!=0){
//						System.out.println(list2[k] + " " + list3[k]);
//					}
//				}
//				break;
//			}
//			i = i + 1;
//		}
//	}
//
//	public static String SubStringStart(String str) {
//		int index = str.indexOf(" ");
//		return (str.substring(0, index));
//	}
//
//	public static String SubStringEnd(String str) {
//		int index = str.indexOf(" ");
//		return (str.substring(index + 1));
//	}
//}

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

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

class dijkstra{
  public:
	struct edge{ int to, cost;};
	int V;
	vector<vector<edge> > G;
	vector<int> d;
	dijkstra(int nv){
		nv += 10;
		d = vector<int>(nv); 
		V = nv;
		G = vector<vector<edge> >(nv);
	}
	
	void run(int s){
		priority_queue<P, vector<P>, greater<P> > que;
		fill(d.begin(), d.end(), INT_MAX);
		d[s] = 0;
		que.push(P(0, s));

		while(!que.empty()){
			P p = que.top(); que.pop();
			int v = p.second;
			if(d[v] < p.first) 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;
					que.push(P(d[e.to],e.to));
				}
			}
		}
	}
};

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

	while(true){
		int n,k; cin >> n >> k;
		if(n == 0) break;
		dijkstra g(n);
		for (int i = 0;i < k;i++){
			int a; cin >> a;
			if(a == 0){
				int b,c; cin >> b >> c;
				g.run(b);
				cout << (g.d[c] == INT_MAX? -1 : g.d[c]) << endl;
			}else{
				int b,c,d; cin >> b >> c >>  d;
				g.G[b].push_back({c,d});
				g.G[c].push_back({b,d});
			}
		}
	}

	return 0;

}



Measured memory_bytes: 3168
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()

    # N個の頂点を持つ有向グラフのデータを生成
    # 辺が存在しない場合には値をinfinityとする
    graph = [[INF] * N for _ in range(N)]
    for _ in range(N):
        v1, k, *vertices = il()
        for idx in range(0, k * 2, 2):
            v2, c = vertices[idx:idx + 2]
            graph[v1][v2] = c

    # ダイクストラ法
    dist = [INF] * N  # 各頂点までの距離を保持する配列
    dist[0] = 0       # 開始始点の頂点は距離をゼロとする
    visited = [0] * N # 各頂点の訪問状態を保持する配列[0: 未訪問, 1: 訪問済み]
    while True:
        min_cost, u = INF, INF
        # 起点となる頂点の探索
        for i in range(N):
            if min_cost > dist[i] and visited[i] != 1:
                u = i
                min_cost = dist[i]

        # 起点となる頂点が存在しない場合には処理を終了
        if u == INF: break
        visited[u] = 1  # 起点を訪問済みにする

        # 起点から次の頂点までの距離を更新
        for v in range(N):
            if graph[u][v] != INF and visited[v] != 1:
                if dist[v] > dist[u] + graph[u][v]:
                    dist[v] = dist[u] + graph[u][v]

    # 回答
    for n in range(N):
        print(n, dist[n])


if __name__ == '__main__':
    main()



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD =  1000000007;


int main() {
    ll n, a, b; cin >> n >> a >> b;
    if((a + b) % 2 == 0){
        cout << abs(a - (a + b) / 2) << endl;
        return 0;
    }
    cout << min(a - 1, n - b) + 1 + ((b - a - 1) / 2) << endl;

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <math.h>

using namespace std;
typedef long double ld;

ld a,b,x;

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

  cin >> a >> b >> x;

  ld area = x / a;
  if (area >= a*b/2) {
    ld h = (a*b-area)*2 / a;
    ld radian = atan2(h, a);
    ld degree = radian * 180.0 / M_PI;
    printf("%.10Lf\n", degree);
    return 0;
  } else {
    ld w = area*2/b;
    ld radian = atan2(b, w);
    ld degree = radian * 180.0 / M_PI;
    printf("%.10Lf\n", degree);
    return 0;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int N;
  scanf("%d",&N);
  int units = N % 10;

  switch (units) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
            puts("hon");
            break;
    case 3:
            puts("bon");
            break;
    default:
            puts("pon");
            break;
  }
  return 0;
}


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

int main() {
	int N;
	cin >> N; /*実行回数*/

	int D, Dn;

	int count = 0;
	int countt = 0;

	while (true) {
		if (countt == N) {
			break;
		}

		cin >> D >> Dn;

		if (D == Dn) {
			count++;
			if (3 <= count) {
				cout << "Yes";
				return 0;
			}
		}
		else if (D != Dn) {
			if (3 <= count) {
				cout << "Yes";
				return 0;
			}
			else {
				count = 0;
			}
		}

		countt++;
	}
		cout << "No";
	
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C;
  str S1,S2,S3;
  vector<int>N(3);
  cin>>A>>B;
  cout<<(A-1)*(B-1)<<endl;
}


Measured memory_bytes: 256
count = STDIN.gets.split(' ')[1].to_i
s = STDIN.gets.chomp
t = [];t[0] = 0
c_tmp = 0
(s.length).times do |c|
    if s[c] == 'A'
        if s.length > c + 1  and s[c+1] == 'C'
            c_tmp +=1;
            t[c+1] = c_tmp
        else
            t[c+1] = t[c]
        end
    else
      t[c+1] = t[c]
    end
end
count.times do |c|
    start = STDIN.gets.split(' ').map(&:to_i)
    puts t[start[1] - 1] - t[start[0] - 1]
end

Measured memory_bytes: 3452
n, w = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(n)]
p.insert(0, [0, 0])
dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, w + 1):
        if j >= p[i][0]:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - p[i][0]] + p[i][1])
        else:
            dp[i][j] = dp[i - 1][j]
print(dp[n][w])

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e9;

int main() {
  ll h, w;
  cin >> h >> w;
  ll a[h][w];
  rep(i, h) rep(j, w) cin >> a[i][j];
  vector<vector<ll>> ans;

  rep(i, h - 1) {
    rep(j, w) if (a[i][j] % 2) {
      a[i + 1][j]++;
      ans.push_back({i, j, i + 1, j});
    }
  }
  rep(i, w - 1) if (a[h - 1][i] % 2) {
    a[h - 1][i + 1]++;
    ans.push_back({h - 1, i, h - 1, i + 1});
  }

  cout << ans.size() << endl;
  rep(i, ans.size()) rep(j, 4) cout << ans[i][j] + 1 << (j == 3 ? "\n" : " ");
  return 0;
}


Measured memory_bytes: 12848
import re

n = input()

# 正規表現は無理かも．．．
# res = re.search("(\d)\1{3,}", n)
# print(res)

if(n[0] == n[1] == n[2] or n[1] == n[2] == n[3]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int x,y;cin >> x >> y;
    bool can = false;

    //iはカメの数
    for(int kame=0; kame<=x; kame++){
        int turu = x-kame;
        int nun = kame * 4 + turu * 2;
        if(nun == y) can = true;
    }

    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  rep(i, N) cin >> V[i];
  sort(V.begin(), V.end());
  double ans = 0;
  rep(i, N-1) {
    if(i == 0) ans = (V[i] + V[i+1]) / 2.0;
    else ans = (ans + V[i+1]) / 2.0;
  }
  cout << ans << endl;
  return 0;
}


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

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

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

// Description: [1,x]のクエリに対するデータ構造 
// TimeComplexity: 更新$\mathcal{O}(\log n)$ クエリ$\mathcal{O}(\log n)$
// Verifyed: ARC 033 C

struct Binary_indexed_tree{ 
	using T=ll;
	int n; 	
	vector<T> data;
	
	Binary_indexed_tree(int _n):n(_n){data.assign(n+1,0);}
	   
	void add(int i,T x){
		for(;i<=n;i+=i&-i) data[i]+=x;
	}

	T sum(int i){
		T ret=0;
		for(;i>0;i-=i&-i) ret+=data[i];
		return ret;
	}
};

const ll mod=1000000007LL;
const int limit=1<<20;

ll fact[limit];
bool used[limit];
int ary[limit];

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> ary[i];
	rep(i,n) used[ary[i]]=true;

	vector<ll> unuse;
	rep(i,1,n+1) if(used[i]==false) unuse.push_back(i);
	const ll k=ll(unuse.size());

	fact[0]=1LL;
	rep(i,1,n+1) fact[i]=1LL*i*fact[i-1]%mod;

	ll ans=fact[k],zero=0LL,sum=0LL;
	Binary_indexed_tree bit(n);

	rrep(i,n){
		ll cur=0LL;
		if(ary[i]){
			cur+=1LL*bit.sum(ary[i])*fact[k]%mod; //(i,j)=(non_zero,non_zero)
			cur+=1LL*zero*(lower_bound(begin(unuse),end(unuse),ary[i])-begin(unuse))%mod*fact[k-1]%mod; //(i,j)=(non_zero,zero)
			bit.add(ary[i],1);
			sum+=1LL*(end(unuse)-lower_bound(begin(unuse),end(unuse),ary[i]))*fact[k-1]%mod; //(i,j)=(zero,non_zero)
			sum%=mod;
		}else{
			ll allsum=(k*(k-1)/2LL)%mod;
			cur+=1LL*allsum*fact[k-2]%mod*zero%mod; //(i,j)=(zero,zero)
			cur+=sum; //(i,j)=(zero,non_zero)
			zero++;
		}
		ans+=cur%mod*fact[n-1-i]%mod;
		ans%=mod;
	}

	cout << ans << endl;
	return 0;
}

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

int main()
{
    char s[3];
    int n=3;
    int con_A=0,con_B=0;
    for(int i=0;i<n;i++)
    {
        scanf("%c",&s[i]);
        if(s[i]=='A')
        {
            con_A++;
        }
        else
        {
            con_B++;
        }
    }
    if(con_A==0||con_B==0)
    {
        printf("No\n");
    }
    else
    {
        printf("Yes\n");
    }
    
    
    return 0;
}


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


int main()
{	
	ll x;
	cin>>x;
	for(ll a=0;a<=1000;a++)
	{
		//cout<<"a:"<<a<<endl;
		for(ll i=0;i*i*i*i*i<=abs(a*a*a*a*a-x);i++)
		{
			//cout<<i<<endl;
			if(i*i*i*i*i==a*a*a*a*a-x)
			{
				cout<<a<<" "<<i<<endl;
				return 0;
			}
			if((-1)*i*i*i*i*i==a*a*a*a*a-x)
			{
				cout<<a<<" "<<(-1)*i<<endl;
				return 0;	
			}
		}
	}
}	

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

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 long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

bool is_prime[1000010];


int main() {
    int n;
    ll ans = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<ll>());
    if(n %2 == 1){
        for (int i = 0; i <= n/2; ++i) {
            ans += 2*a[i];
        }
        ans -= a[0];
        ans -= a[n/2];
    }else{
        for (int i = 0; i < n/2; ++i) {
            ans += 2*a[i];
        }
        ans -= a[0];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4056