akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

string s[10];
bool used[10][10];
int h, w; 
void dfs(int y, int x){
	if(y + 1 < h && x < w && s[y + 1][x] == '#'){
		s[y + 1][x] = '.';
		used[y + 1][x] = true;
		dfs(y + 1, x);
	}else if(y < h && x + 1 < w && s[y][x + 1] == '#'){
		s[y][x + 1] = '.';
		used[y][x + 1] = true;
		dfs(y, x + 1);
	}
	return;
}

int main(void){
	cin >> h >> w;
	rep(i, h) cin >> s[i];
	rep(i, 10)rep(j, 10)used[i][j] = false;
	if(s[0][0] == '#'){
		used[0][0] = true;
		s[0][0] = '.';
		dfs(0, 0);
	}else{
		printf("Impossible\n");
	}

	rep(i, h)rep(j, w){
		if(s[i][j] == '#'){
			printf("Impossible\n");
			return 0;
		}
	}
	if(used[h - 1][w - 1]){
		printf("Possible\n");
	}else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 384
# include <iostream>
using namespace std;
int n,s;
void work (void)
{
	int i,p,q;
	for (i=1;i<=n;i++)
	{
		cin>>p>>q;
		s+=q-p+1;
	}
	cout<<s;
}
int main (void)
{
	cin>>n;
	work ();
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
ans = 0 + (0 not in a)
for x in a:
    ans *= x
    if ans > 10 ** 18:
        print(-1)
        exit()
if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)


Measured memory_bytes: 21580
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
int const TREE_SIZE = 1 << 20;
long long int seg_tree[TREE_SIZE] = {};
bool is_a[TREE_SIZE] = {}; // その区間に値が代入されたかどうか

long long int getsum(int a, int b, int index, int l, int r){
	
	// [a, b) の合計値を求める
	if(r <= a || b <= l){
		return 0;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	if(is_a[index]){
		return seg_tree[index] / (r - l) * (min(r, b) - max(l, a)); // 
	}
	long long int ret = 0;
	ret += getsum(a, b, index * 2, l, (l + r) / 2);
	ret += getsum(a, b, index * 2 + 1, (l + r) / 2, r);
	return ret;
}

long long int update(int a, int b, int index, int num, int l, int r){
	
	// [a, b) を num に変更する
	
	if(r <= a || b <= l){
		//cout << l << " " << r << " " << seg_tree[index] << endl;
		return seg_tree[index];
	}
	if(a <= l && r <= b){
		seg_tree[index] = num * (r - l);
		is_a[index] = true;
		//cout << l << " " << r << " " << seg_tree[index] << endl;
		return seg_tree[index];
	}
	long long int ret = 0;
	if(is_a[index]){
		is_a[index * 2] = true;
		seg_tree[index * 2] = seg_tree[index] / 2;
		is_a[index * 2 + 1] = true;
		seg_tree[index * 2 + 1] = seg_tree[index] / 2;
		is_a[index] = false;
	}
	ret += update(a, b, index * 2, num, l, (l + r) / 2);
	ret += update(a, b, index * 2 + 1, num, (l + r) / 2, r);
	//cout << l << " " << r << " " << ret << endl;
	return seg_tree[index] = ret;
}

int main(){
	
	int n, q;
	cin >> n >> q;
	
	for(int i = 0; i < q; i++){
		long long int num, a, b, c;
		cin >> num;
		if(num == 0){
			cin >> a >> b >> c;
			update(a, b + 1, 1, c, 0, TREE_SIZE / 2);
		}else{
			cin >> a >> b;
			cout << getsum(a, b + 1, 1, 0, TREE_SIZE / 2) << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 4904
n,m = map(int,input().split())
dp = [0]*(n+1)
dp[0],dp[1] = 1,1

for _ in range(m):
  a = int(input())
  dp[a] = -1

for i in range(0,n-1):
  if dp[i+2]==-1:
    continue
  if dp[i]==-1 and dp[i+1]==-1:
    dp[i+2] = -1
  elif dp[i]==-1:
    dp[i+2] = dp[i+1]
  elif dp[i+1]==-1:
    dp[i+2] = dp[i]
  else:
    dp[i+2] = dp[i] + dp[i+1]

print(dp[n]%(10**9+7) if dp[n]!=-1 else 0)

Measured memory_bytes: 466108
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		int M =sc.nextInt();
		int[] num =new int[N];
		Arrays.fill(num, -1);
		boolean ableFlg = true;

		if (N == 1 && M == 0) {
			System.out.print(0);
		}else if(N == 1 && M == 1){
			int insert = sc.nextInt();
			int number = sc.nextInt();
			System.out.println(number);
		}else {
			for (int i = 0; i < M; i++) {
				int insert = sc.nextInt();
				int number = sc.nextInt();

				if (insert == 1 && number == 0) {
					ableFlg = false;
					break;
				}

				if (num[insert - 1] != -1 && num[insert - 1] != number) {
					ableFlg = false;
					break;
				}

				num[insert - 1] = number;

			}

			if (ableFlg) {
				for (int i = 0; i < N; i++) {
					if (num[0] == -1) {
						num[0] = 1;
					}

					if (num[i] == -1) {
						System.out.print(0);
					}else {
						System.out.print(num[i]);
					}
				}
			}else {
				System.out.println(-1);
			}
		}
	}
}

Measured memory_bytes: 35644
n=int(input())
tou=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for _ in range(n):
   b,f,r,v=map(int, input().split())
   tou[b-1][f-1][r-1]+=v

for i in range(4):
   for j in range(3):
       print(' ', end='')
       print(*tou[i][j])
   if i!=3: print('#'*20)


Measured memory_bytes: 5628
#include<stdio.h>
int ub(int l,int r,int n,int *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n>d[m]?ub(l,m,n,d):ub(m+1,r,n,d);
}
int main(){
  int n,j,r=1,a,d[100010]={};
  scanf("%d %d",&n,&d[0]);
  while(--n){
    scanf("%d",&a);
    j=ub(0,r,a,d);
    d[j]=a;
    if(r==j)r++;
  }
  printf("%d\n",r);
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main()
{
   int a,b,r;
   scanf("%d %d %d",&a,&b,&r);
   if(1<=a && a<=100 && 1<=b && b<=100 && 1<=r && r<=100)
   {
    if(b-a == r-b) printf("\nYES");
    else printf("\nNO");

   }
return 0;
}

Measured memory_bytes: 1732
K = int(input())
A, B = map(int,input().split())
count = 0
for i in range(A,B+1):
    if i%K == 0:
        count += 1
    else:
        count += 0

        
        
if count >= 1:
    print("OK")
elif count == 0:
    print("NG")


Measured memory_bytes: 9172
A, B, C, D = map(int, input().split())
mycnt = 1
while A > 0 and C > 0:
    if mycnt%2 != 0:
        C -= B
    else:
        A -= D
    mycnt += 1
    #print(A, C)
if (mycnt - 1)%2 == 0:
    print('No')
else:
    print('Yes')

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(a,1,n+1) {
    ll k = n / a;
    ll sn = k * (2*a + (k-1) * a) / 2;
    ans += sn;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3752
## coding: UTF-8
## coding: UTF-8
#N, M, K = 9, 3, 4
#N, M, K = map(int,input().split())
#N = 7
N = int(input())
mod = 10 ** 9 + 7
p = 10 ** 9 + 7


# 返り値: a と b の最大公約数
# 返り値: ax + by = gcd(a, b) を満たす (x, y) が格納される
def aug_gcd(a, b):
    lq = []
    while b > 0:
        q = int(a/b)
        r = a % b
        a = b
        b = r
        lq.append(q)
    x = 1
    y = 0
    for i in range(len(lq)):
        tmp = x
        x = y
        y = tmp - lq[(-1)*(i+1)] * y
    return a, x, y

#拡張ユークリッドの互除法による逆元計算
#拡張ユークリッドの方が二分累乗法より高速/mが素数でなくとも良い
def modinv(a, p):
    inv = aug_gcd(a, p)[1] #ax == 1(mod p) <==> ax + py == 0, xの値が逆元
    if(inv < 0):
        inv += p #pがマイナスだったらプラスに書き換える
    return inv


#[NC0, NC1, NC2, NC3, ..., NCN % p]
def N_Combination_k(N, p):
    #NCkのリストを作ります
    l = [1]
    res = 1
    for i in range(1, N+1):
        res *= (N+1-i)
        res %= p
        res *= modinv(i, p)
        res %= p
        l.append(res)
    return l

number_terms = N // 3
ret = 0
for i in range(1, number_terms+1):
    #print(i, )
    tmp = N_Combination_k(N-2*i-1, p)
    #print(tmp, tmp[i-1])
    ret += tmp[i-1]
    ret %= p
print(ret)

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

namespace AtCoderCs
{

    class Program
    {

        const int Mod = 1000000007;

        static void Main()
        {

            Console.WriteLine((Console.ReadLine().Split(' ').Select(x => int.Parse(x)).Sum() < 22 ? "win" : "bust"));

        }


    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
typedef complex<double> P;
const double eps = 1e-7;
const double pi = acos(-1);



int N;
double R;
vector<P> ps;

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

namespace std {
  bool operator < (const P &a, const P &b) {
    if(a.real() != b.real()) return a.real() < b.real();
    return a.imag() < b.imag();
  }
}

P getRotateP(P p, double rad) {
  double x = p.real();
  double y = p.imag();
  return P(x*cos(rad)-y*sin(rad),
	   x*sin(rad)+y*cos(rad));
}

int main() {
  while(cin >> N >> R) {
    ps.resize(N);
    for(int i = 0; i < N; ++i) {
      cin >> ps[i].real() >> ps[i].imag();
    }
    double rad = (double)rand()/(double)RAND_MAX * pi * 2;
    for(int i = 0; i < N; ++i) {
      ps[i] = getRotateP(ps[i], rad);
    }
    sort(ps.begin(), ps.end());
    bool vis[N];
    fill(vis, vis+N, false);
    int res = 0;
    for(int i = 0; i < N; ++i) {
      if(vis[i]) continue;
      vis[i] = true;
      ++res;
      for(int j = i+1; j < N && ps[j].real()-ps[i].real() <= R; ++j) {
	double d = abs(ps[i]-ps[j]);
	if(equals(d,R) || d < R) {
	  vis[j] = true;
	}
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 4440
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int main(void){
  string s;
  ll k;
  cin >> s >> k;

  int Ite;
  char hozon = '1';
  for(int i = 0; i < s.size(); i++){
    if(s[i] != '1') {
      Ite = i;
      hozon = s[i];
      break;
    }
  }
  if(Ite >= k) cout << '1' << endl;
  else cout << hozon << endl;

  return 0;
}


Measured memory_bytes: 256
#[derive(Debug)]
struct Card {
    b: usize,
    c: u64,
}

impl Card {
    pub fn new(b: usize, c: u64) -> Self {
        Card {b: b, c: c}
    }
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut cards = buf.split_whitespace()
        .map(|x| Card::new(1, x.parse::<u64>().unwrap()))
        .collect::<Vec<_>>();

    for _ in 0..m {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        let b: usize = iter.next().unwrap().parse().unwrap();
        let c: u64 = iter.next().unwrap().parse().unwrap();

        cards.push(Card::new(b, c));
    }

    cards.sort_by(|a, b| b.c.cmp(&a.c));

    let mut ans = 0u64;
    let mut remain = n;
    for card in cards.iter() {
        if card.b >= remain {
            ans += card.c * (remain as u64);
            break;
        }
        else {
            ans += card.c * (card.b as u64);
            remain -= card.b;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 11840
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: isize = iterator.next().unwrap().parse().unwrap();
    let v: usize = iterator.next().unwrap().parse().unwrap();
    let b: isize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();
    let t: usize = iterator.next().unwrap().parse().unwrap();

    if w >= v {
        return "NO".to_string();
    }

    let d = v - w;
    return if t * d >= (a - b).abs() as usize {
        "YES".to_string()
    } else {
        "NO".to_string()
    };
}


Measured memory_bytes: 2168
#!/usr/bin/env python3.4

# abc127_c

import itertools
import functools

def main():
    # Input
    n, m = [int(s) for s in input().split()]
    lrs = [[int(s) for s in input().split()] for _ in range(m)]
    ls = [lr[0] for lr in lrs]
    rs = [lr[1] for lr in lrs]
    # Get ans
    l = functools.reduce(max, ls)
    r = functools.reduce(min, rs)
    ans = r-l+1 if l<=r else 0
    # Output
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 23368
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();    
        String S = r.s();
        int i = S.length()-1;
        if(i%2 == 1)
            i--;
        while(true){
            if(S.substring(0, i/2).equals(S.substring(i/2, i))){
                println(i);            
                return;
            } else
                i -= 2;            
        }
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21204
#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int N;
int A[100010];
vector<int> B(100010);

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  int l = 0;
  B[l] = A[0];
  for (int i = 1; i < N; i++) {
    if (A[i] > B[l]) {
      B[l+1] = A[i];
      l++;
    }
    else {
      auto it = lower_bound(B.begin(), B.begin()+l, A[i]);
      //cout << it-B.begin() << endl;
      B[it-B.begin()] = A[i];
    }
    //cout << 'e' << B[l] << endl;
  }
  cout << l+1 << endl;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
        long long int a, b, k; cin >> a >> b >> k;
        long long int z = 0;
        if (k <= a) cout << a-k << " " << b << endl;
        else cout << 0 << " " << max(z, b-(k-a)) << endl;
    return 0;
}



Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD =1000000007;

int main(){
  ll H,W,K,ans=1000000;
  cin >> H >> W >> K;
  vector<string> S(H);
  rep(i,H) cin >> S.at(i);
  for (int tmp = 0; tmp < (1 << H-1); tmp++) {
NEXT:
    bitset<9> s(tmp);
    vector<ll> T(10,0);
    ll x=0,y=0;
    y+=s.count();
    rep(i,W){
RETURN:
      ll t=0;
      if(S.at(0).at(i)=='1'){
        T.at(t)++;
        if(T.at(t)>K){
          if(x==0){
            x++;
            y++;
            rep(k,10) T.at(k)=0;
            goto RETURN;
          }else{
            x=0;
            tmp++;
            if(tmp==(int)pow(2,H-1)){
              goto END;
            }
            goto NEXT; 
          }
        }
      }
      rep(j,H-1){
        if(s.test(j)){
          t++;
        }
        if(S.at(j+1).at(i)=='1'){
          T.at(t)++;
          if(T.at(t)>K){
            if(x==0){
              x++;
              y++;
              rep(k,10) T.at(k)=0;
              goto RETURN;
            }else{
              x=0;
              tmp++;
              if(tmp==(int)pow(2,H-1)){
                goto END;
              }
              goto NEXT; 
            }
          }
        }
      }
      x=0;
    }
    ans=min(ans,y);
  }
END:
  cout << ans << endl;
  
  
  
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <istream>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>


using namespace std;


int main() {
    int n, a, b; cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
    return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<ll> v(N);
  rep(i,N)cin >> v[i];
  sort(all(v));
  int count = 0;
  int pre = v[0];
  int ans = 0;
  v.push_back(0);
  rep(i,N+1){
    if(pre!=v[i]){
      if(pre > count)ans+=count;
      else ans += count - pre;
      count = 1;
    }else ++count;
    pre = v[i];
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const long long mod = pow(10, 9) + 7;

uint64_t inverseModp(uint64_t a, uint64_t p) {
    assert(p < (1ull << 63));
    assert(a < p);
    assert(a != 0);
    uint64_t ex = p-2, result = 1;
    while (ex > 0) {
        if (ex % 2 == 1) {
            result = (result*a) % p;
        }
        a = (a*a) % p;
        ex /= 2;
    }
    return result;
}

long long ncr(long long n, long long r) {
    long long ans = 1;
    for (long long i=1; i<=r; i++) {
        ans = ((n-r+i)*ans) % mod;
        ans = ans*inverseModp(i, mod);
        ans %= mod;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long x, y;
    cin >> x >> y;

    if (2*x >= y && 2*y >= x && (2*x-y)%3 == 0 && (2*y-x)%3 == 0) {
        cout << ncr((x+y)/3, (2*x-y)/3) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


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

ll H,W;
string S[401];
bool checked[401][401]={};
int main(){
    cin>>H>>W;
    for(ll i=0;i<H;i++){
        cin>>S[i];
    }
    ll ans=0;
    for(ll i=0;i<H;i++){
        for(ll j=0;j<W;j++){
            if(checked[i][j])continue;
            ll blackCnt=0,whiteCnt=0;
            queue<ll> qh,qw;
            qh.push(i);
            qw.push(j);
            checked[i][j]=true;
            while(!qh.empty()){
                ll nh=qh.front();qh.pop();
                ll nw=qw.front();qw.pop();
                if(S[nh][nw]=='#')blackCnt++;
                else whiteCnt++;
                ll dh[4]={0,1,0,-1};
                ll dw[4]={1,0,-1,0};
                for(ll k=0;k<4;k++){
                    ll h=nh+dh[k];
                    ll w=nw+dw[k];
                    if(h<0||H<=h || w<0||W<=w)continue;
                    if(checked[h][w])continue;
                    if(S[nh][nw]==S[h][w])continue;
                    qh.push(h);
                    qw.push(w);
                    checked[h][w]=true;
                }
            }
            ans+=blackCnt*whiteCnt;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>  
#define LL long long  
using namespace std;  
const int AX = 2e5+66;  
LL a[AX];  
LL b[AX];  
LL c[AX];  
int n ;   
  
LL Binary(LL k)  
{  
    int l = 1 , r = n + 1;  
    while( l < r ){  
        int mid = ( l + r ) >> 1;  
        if(c[mid] >= k) r = mid ;   
        else l = mid + 1 ;  
    }  
    return l;  
}  
  
int main(){  
    cin >> n ;  
    for( int i = 1 ; i <= n ; i++ ){  
        cin >> a[i];  
    }  
    for( int i = 1 ; i <= n ; i++ ){  
        cin >> b[i];  
    }  
    LL res = 0 ;  
    for( int k = 1 ; k <= 29 ; k ++ ){  
        LL tmp = (1<<k) - 1;  
        for( int i = 1 ; i <= n ; i++ ){  
            c[i] = b[i] & tmp;  
        }  
        LL cnt = 0;  
        sort( c + 1, c + n + 1 );  
        for( int i = 1 ; i <= n ; i++ ){  
            cnt += n - Binary( ( (1<<(k-1)) -(tmp & a[i]) ) )+1;  
        }  
        for( int i = 1 ; i <= n ; i++ ){  
            cnt -= Binary( (1<<k)+(1<<(k-1))-(tmp&a[i])) - Binary((1<<k)-(tmp&a[i]));  
        }  
        if( cnt & 1 ) res += (1<<(k-1));  
    }  
    cout << res << endl;  
    return 0 ;  
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

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

    int N;
    cin >> N;
    vi x(N);
    rep(i, N) cin >> x[i];
    int L;
    cin >> L;

    // vv[k][i] = 街jから2^i日で到達可能な最大のインデックス
    const int MAX_LOG = 20;
    vvi vv(MAX_LOG + 1, vi(N));
    rep(i, N) {
        vv[0][i] = std::distance(begin(x), upper_bound(all(x), x[i] + L)) - 1;
    }
    rep(k, MAX_LOG) {
        rep(i, N) {
            vv[k + 1][i] = vv[k][vv[k][i]];
        }
    }
    // printVV(vv);

    auto check = [&](int m, int a, int b) {
        int pos = a;
        rep(k, MAX_LOG) {
            if (m & 1) {
                pos = vv[k][pos];
                if (pos >= b) {
                    return true;
                }
            }
            m >>= 1;
        }
        return false;
    };

    int Q;
    cin >> Q;
    rep(_, Q) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);

        int l = 0;
        int r = N;
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (check(m, a, b)) {
                r = m;
            } else {
                l = m;
            }
        }
        cout << r << endl;

    }
}


Measured memory_bytes: 18304
#![allow(unused)]

use std::cmp::{max, min};
use std::io::stdin;
use std::str::FromStr;

fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse()
}

fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|x| x.parse()).collect()
}

fn main() {
    let n: usize = input().unwrap();
    let mut a: Vec<usize> = input_vec().unwrap();

    let p = *a.iter().max().unwrap();
    let pos = a.iter().position(|x| *x == p).unwrap();
    a.swap_remove(pos);
    let q = a.iter().min_by_key(|x| (p as i64 / 2 - **x as i64).abs()).unwrap();
    println!("{} {}", p, q);
}


Measured memory_bytes: 6396
#include<cstdio>
const int MaxN=200010,inf=1<<30;
int N;
struct Edge{int to;Edge*next;};
struct Tree{
	int X,fa[MaxN],D[MaxN];
	Edge E[MaxN*2],*ne,*fir[MaxN];
	void link(int u,int v){*ne=(Edge){v,fir[u]};fir[u]=ne++;}
	void dfs(int i){
		for(Edge*e=fir[i];e;e=e->next)if(e->to!=fa[i]){
			fa[e->to]=i;
			D[e->to]=D[i]+1;
			dfs(e->to);
		}
	}
	void read(){
		ne=E;
		for(int i=1;i<=N;i++)fir[i]=0;
		for(int i=1,u,v;i<N;i++)scanf("%d%d",&u,&v),link(u,v),link(v,u);
		dfs(X);
	}
	bool dis3(int x,int y){
		int d=0;
		while(x!=y&&d<3)D[x]>D[y]?x=fa[x]:y=fa[y],d++;
		return d==3;
	} 
}A,B;
int dfs(int i){
	int res=B.D[i];
	for(Edge*e=A.fir[i];e;e=e->next)if(e->to!=A.fa[i]){
		if(B.dis3(i,e->to))return inf;
		if(A.D[e->to]<B.D[e->to]){
			int tmp=dfs(e->to);
			if(tmp>res)res=tmp;
		}
	}
	return res;
}
int main(){
	scanf("%d%d%d",&N,&A.X,&B.X);
	A.read();B.read();
	int ans=dfs(A.X);
	printf("%d\n",ans==inf?-1:ans*2);
}

Measured memory_bytes: 24960
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$X = getq();
$ans_b=array();
if($X<=3){echo "1\n";exit;}
for ($i=$X; $i >= 1; $i--) {
	for ($j=$X; $j >=2 ; $j--) {
		$temp=pow($i,$j);
		if($temp<=$X){
			array_push($ans_b,$temp);
		}
	}
}
echo max($ans_b)."\n";
?>


Measured memory_bytes: 4856
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Scanner.Scan<string>();
            var T = Scanner.Scan<string>();
            var answer = 0;
            for (var i = 0; i < S.Length; i++)
            {
                if (S[i] != T[i]) answer++;
            }

            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28136
import itertools

H, W, K = map(int, input().split())
squares = []
blacks = 0

H_cnt = [0] * H
W_cnt = [0] * W

for i in range(H):
    squares.append(list(input()))
    H_cnt[i] = squares[i].count('#')
    blacks += H_cnt[i]

for i in range(W):
    num = 0
    for j in range(H):
        if squares[j][i] == '#':
            num += 1
    
    W_cnt[i] = num
    
H_p = [0] * (2**H)
for i in range(2**H):
    cnt = 0
    for j in range(H):
        if (i >> j) & 1:
            cnt += H_cnt[j]
    
    H_p[i] = cnt

W_p = [0] * (2**W)
for i in range(2**W):
    cnt = 0
    for j in range(W):
        if (i >> j) & 1:
            cnt += W_cnt[j]
    
    W_p[i] = cnt

ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = H_p[i] + W_p[j]
        #print(cnt)
        for k in range(H):
            if (i >> k) & 1:
                for l in range(W):
                    if (j >> l) & 1:
                        if squares[k][l] == '#':
                            #print(bin(i), bin(j), k, l)
                            cnt -= 1
        
        cnt = blacks - cnt
        if cnt == K:
            ans += 1
            
print(ans)

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

int white[64];
int blue[64];
int red[64];

int main()
{
    int h, w;

    cin >> h >> w;
    vector<string> flag(h);
    for (int i = 0; i < h; i++){
        cin >> flag[i];
        white[i] = w - count(flag[i].begin(), flag[i].end(), 'W');
        blue[i] = w - count(flag[i].begin(), flag[i].end(), 'B');
        red[i] = w - count(flag[i].begin(), flag[i].end(), 'R');
    }

    int mini = h * w;
    int W = 0;
    for (int i = 0; i < h - 2; i++){
        W += white[i];
        int B = 0;
        int R = accumulate(red + i + 1, red + h, 0);
        for (int j = i + 1; j < h - 1; j++){
            B += blue[j];
            R -= red[j];
            mini = min(mini, W + B + R);
            // cout << " " << W << " " << B << " " << R << endl;
        }
    }

    cout << mini << endl;

    return 0;
}

Measured memory_bytes: 1216
"use strict"
function Main(input) {
  const inputArray = input.split(" ");
  let count5 = 0, count7 = 0;
  inputArray.forEach(value => {
    if(value == 5) count5++;
    else if(value == 7) count7++;
  });
  if(count5 === 2 && count7 === 1) console.log("YES");
  else console.log("NO");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
package main

import (
	"fmt"
	"math"
	"sort"
)

type Ingredient struct {
	Value float64
}

type Ingredients []Ingredient

func (ing Ingredients) Len() int {
	return len(ing)
}

func (ing Ingredients) Swap(i, j int) {
	ing[i], ing[j] = ing[j], ing[i]
}

func (ing Ingredients) Less(i, j int) bool {
	return ing[i].Value < ing[j].Value
}

func main() {
	var n int
	fmt.Scan(&n)

	nums := scanNums(n)
	var ingredients Ingredients
	for _, num := range nums {
		ingredients = append(ingredients, Ingredient{Value: float64(num)})
	}

	sort.Sort(ingredients)

	current := ingredients[0].Value

	if len(ingredients) > 1 {
		for i, ing := range ingredients {
			if i == 0 {
				continue
			}

			current = (current + ing.Value) / 2.0
		}
	}

	fmt.Println(current)
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}


Measured memory_bytes: 512
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  if (a + b > c + d)
    puts("Left");
  else if (a + b < c + d)
    puts("Right");
  else
    puts("Balanced");
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
char buf[1 << 23], *ps = buf, *pt = buf, pbuf[1 << 23], *pp = pbuf;
#define getchar() (ps == pt && (pt = (ps = buf) + fread(buf, 1, 1 << 23, stdin), ps == pt) ? EOF : *ps++)
#define putchar(x) (pp == pbuf + (1 << 23) ? fwrite(pbuf, 1, 1 << 23, stdout), pp = pbuf : 0, *pp++ = x)
struct _IO_flusher{ ~_IO_flusher(){ fwrite(pbuf, 1, pp - pbuf, stdout); }} IO_flusher;
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
void print(int x){
	int num[30], cnt = 0;
	if (!x) return putchar('0'), void(0);
	for (x = x < 0 ? -x : x; x; x /= 10) num[++cnt] = x % 10;
	while (cnt) putchar(num[cnt] ^ '0'), --cnt;
}
#define N 10000005
#define P 1000000007
int n, k, fac[N], inv[N];
int qpow(int a, int b){
	int s = 1;
	for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) s = 1ll * s * a % P;
	return s;
}
void init(int n){
	fac[0] = 1;
	for (register int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
	inv[n] = qpow(fac[n], P - 2);
	for (register int i = n; i; --i) inv[i - 1] = 1ll * inv[i] * i % P;
}
int C(int n, int m){
	if (n < m) return 0;
	return 1ll * fac[n] * inv[m] % P * inv[n - m] % P;
}
int main(){
	n = read(), k = read(), init(n);
	for (register int i = 1; i <= k; ++i){
		int ans = 1ll * C(n - k + 1, i) * C(k - 1, i - 1) % P;
		print(ans), putchar('\n');
	}
}

Measured memory_bytes: 6400
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define int long long
#define ll long long
using namespace std;
signed main() {
	char a;
	cin >> a;
	if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')cout << "vowel" << endl;
	else cout << "consonant" << endl;
	getchar(); getchar(); return 0;
}

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

int main() {
    int N, Y;
    cin >> N >> Y;

    int res10000 = -1, res5000 = -1, res1000 = -1;
    for(int a = 0; a <= N; a++) {
        for(int b = 0; b + a <= N; b++) {
            int c = N - a - b; 
            int total = 10000*a + 5000*b + 1000*c;
            if(total == Y) {
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	long double ans = 0;
	while (n--)
	{
		long double temp;
		cin >> temp;
		ans += 1.L / temp;
	}
	cout << fixed << setprecision(15) << 1.L / ans << endl;

	char I;
	cin >> I;
}

Measured memory_bytes: 256
def main():
    from itertools import chain
    N, M, K = map(int, input().split())

    A = map(int, input().split())
    B = list(map(int, input().split()))

    answer = 0

    sum_b = sum(B)
    idx_b = M
    remain = K

    for i, a in enumerate(chain([0], A)):
        remain -= a
        if remain < 0:
            break

        while sum_b > remain and idx_b >= 0:
            idx_b -= 1
            b = B[idx_b]
            sum_b -= b

        i += idx_b
        answer = i if answer < i else answer

    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 48572
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
typedef complex<double> P;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD = 1000000007;
struct edge {
    lli f, t, c;
};
int main()
{
    int n, m;
    cin >> n >> m;
    lli dis[105][105] = {};
    rep(i, 105)
    {
        rep(j, 105) dis[i][j] = MOD * MOD;
    }
    lli a, b, c;
    vector<edge> p;
    rep(i, m)
    {
        cin >> a >> b >> c;
        a--, b--;
        dis[a][b] = c;
        dis[b][a] = c;
        p.push_back(edge{a, b, c});
    }
    rep(k, n) rep(j, n) rep(i, n) dis[i][j] = min(dis[i][k] + dis[k][j], dis[i][j]);
    int ans = 0;
    rep(i, m)

    {
        if (p[i].c > dis[p[i].f][p[i].t])
            ans++;
    }
    cout << ans << endl;
}


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

int main() {
  int N, K, sum = 0;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    if(x < (K - x))
      sum += x;
    else
      sum += (K-x); 
  }
  cout << sum * 2 << endl;
 
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	nextToken func() ([]byte, error)
	nextLine  func() ([]byte, error)

	OutputBuffer *bufio.Writer

	OutputWriter io.Writer
)

// set up IO functions
func init() {

	SetInput(os.Stdin)
	SetOutput(os.Stdout)

}
// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}
func main() {
	defer Flush()

	N := readi()
	D := make([][]int, N)
	for i := range D {
		_, D[i] = readInts(2)
	}

	for i := 2; i < N; i++ {
		ok := true
		for j := 0; j < 3; j++ {
			ok = ok && D[i-j][0] == D[i-j][1]
		}
		if ok {
			println("Yes")
			return
		}
	}
	println("No")

}



Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m, q; cin >> n >> m >> q;
  V<string> s(n); for (int i = 0; i < n; i++) cin >> s[i];
  VV<> v; assign(v, n + 1, m + 1);
  for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) v[i + 1][j + 1] = v[i + 1][j] + v[i][j + 1] - v[i][j] + (s[i][j] == '1');
  VV<> e; assign(e, 2 * n, 2 * m);
  for (int i = 0; i < 2 * n - 1; i++) for (int j = 0; j < 2 * m - 1; j++) {
    e[i + 1][j + 1] = e[i + 1][j] + e[i][j + 1] - e[i][j];
    if (i & 1 and !(j & 1)) e[i + 1][j + 1] += (s[i / 2 + 1][j / 2] == '1' and s[i / 2][j / 2] == '1');
    if (!(i & 1) and j & 1) e[i + 1][j + 1] += (s[i / 2][j / 2 + 1] == '1' and s[i / 2][j / 2] == '1');
  }
  for (int iq = 0; iq < q; iq++) {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2, x1--, y1--;
    int sv = v[x2][y2] - v[x2][y1] - v[x1][y2] + v[x1][y1];
    x1 *= 2, y1 *= 2, x2 = 2 * x2 - 1, y2 = 2 * y2 - 1;
    int se = e[x2][y2] - e[x2][y1] - e[x1][y2] + e[x1][y1];
    cout << sv - se << '\n';
  }
}

Measured memory_bytes: 86016
//53
#include<iostream>
#include<set>
#include<algorithm>

using namespace std;

int n,m;
int d[101][101];
set<int> s;
set<int>::iterator l,h;
bool p[101];

void dfs(int v){
  if(p[v]++)return;
  for(int i=1;i<=n;i++){
    if(*l<=d[v][i]&&d[v][i]<=*h){
      dfs(i);
    }
  }
}

int main(){
  while(cin>>n>>m,n|m){
    fill(d[0],d[101],-1);
    s.clear();
    s.insert(1<<30);
    while(m--){
      int a,b,w;
      cin>>a>>b>>w;
      d[a][b]=d[b][a]=w;
      s.insert(w);
    }
    l=h=s.begin();
    int sn=1<<30;
    for(;;){
      fill(p,p+101,false);
      dfs(1);
      if(find(p+1,p+n+1,false)==p+n+1){
	sn=min(sn,*h-*l);
	l++;
      }else{
	if(*h==1<<30){
	  break;
	}else{
	  h++;
	}
      }
    }
    cout<<((sn==1<<30)?-1:sn)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1416
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

sum = 0

for i in range(n):
    sum += b[a[i]-1]
    if(i>0):
        if(a[i]==(a[i-1]+1)):
                sum += c[a[i-1]-1]

print(sum)


Measured memory_bytes: 3064
"""
知識問題
- 全列挙
  - 条件数は数え上げ可能
    - 最大で2^10 = 1024
- ビット演算を利用して、個数をカウントする
  - 2進数:1010 => 10進数:10であることを利用して、1の個数をカウント。この場合、期待値は2
    - 10進数の値を配列のindex = 10
    - 2進数にした時の1の個数を、その配列のindexの値 = 2
  - 何桁かは事前に分かっている必要がある
  - カウント方法は下記:
    - 桁数: 10
    - 条件のindex = 500
    - 条件のindexをバイナリにした時の1の個数は、桁数毎に1とのandの合計: sum(500 >> j & 1 for j in range(10))
- 店舗iが、何回同じ時間帯に開店したかは、bit演算andを利用
  - index & F[i]
- 同じ時間帯
"""

n = int(input())
f = []
for _ in range(n):
    f.append(int("0b{}".format(input().replace(' ', '')), 2))

p = []
for _ in range(n):
    p.append(list(map(int, input().split())))

pattern = [sum(i >> j & 1 for j in range(10)) for i in range(2 ** 10)]

candidates = []
for j in range(1, 2 ** 10):
    total = 0
    for i in range(n):
        total += p[i][pattern[f[i] & j]]
    candidates.append(total)
print(max(candidates))


Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int N, M, C, count = 0;
	int A[20][20], B[20];
	int seki[20][20];
	int wa[20];
	scanf("%d%d%d", &N, &M, &C);
	for (int i = 0; i < M; i++) {
		scanf("%d", &B[i]);
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			scanf("%d", &A[i][j]);
		}
	}
	for (int i = 0; i < N; i++) {
		wa[i] = 0;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			seki[i][j] = A[i][j] * B[j];
			//printf("seki=%d ", seki[i][j]);
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			wa[i] += seki[i][j];
		}
		wa[i] += C;
		if (wa[i] > 0) {
			count++;
		}
	}
	//for (int i = 0; i < N; i++) {
		//printf("%d ", wa[i]);
	//}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int N;
	scanf("%d", &N);
	int a[N];
	int i, j, k;
	for (i = 0; i < N; i++)
		scanf("%d", &a[i]);
	
	for (i = 0; i < N; i++) {
		for (j = i + 1; j < N; j++) {
			if (a[i] < a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}

	int alice = 0, bob = 0;
	for (i = 0; i < N; i++) {
		if (i % 2 == 0)
			alice += a[i];
		else
			bob += a[i];
	}

	printf("%d\n", alice - bob);

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int main(void){
    double a,b,c,d;
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    if(ceil(a/d)>=ceil(c/b)) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 1752
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""



import heapq

def dijkstra():
    #n:辺数,w:スタート一
    #n,w = map(int,input().split())
    n = onem()
    edge = [[] for i in range(n)]
    dg = 10**7
    # edge[i]:[コスト]
    for i in range(n-1):
        x,y,z = map(int,input().split())
        x -= 1
        y -= 1
        edge[x].append(z*dg + y)
        edge[y].append(z*dg + x)
    q,w = m()
    s = w-1
    d = [-1]*n
    d[s] = 0

    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)

        

    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        v,c = minedge%dg,minedge//dg
        if d[v] >= 0:
            continue
        d[v] = c
        for e in edge[v]:
            vNext = e%dg
            if d[vNext]:
                heapq.heappush(edgelist, (e//dg+d[v])*dg + vNext)

    

    for i in range(q):
        x,y = m()
        print(d[x-1]+d[y-1])


def warshall_floyd(n,d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

dijkstra()


Measured memory_bytes: 32596