akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    s << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    s << ']';
	return s;
}

ll dp[51][51][2501] = {0};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

	int n, a;
	cin >> n >> a;

	vector<int> x(n);
	rep(i, n) cin >> x[i];

	dp[0][0][0] = 1;
	for(int i = 1; i <= n; ++i){
	    for(int j = 0; j <= n; ++j){
			for(int s = 0; s <= 2500; ++s){
				if(s < x[i-1]) dp[i][j][s] = dp[i-1][j][s];
				else if(j >= 1 and s >= x[i-1]) dp[i][j][s] = dp[i-1][j][s] + dp[i-1][j-1][s-x[i-1]];
			}
	    }
	}

	ll ans = 0ll;
	for(int i = 1; i <= n; ++i){
	    ans += dp[n][i][a*i];
	}
	ppp(ans);



    return 0;
}


Measured memory_bytes: 50048
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val isUp = 1L << 53
  solve
  def solve: Unit = {
    val n = readLine.trim.toLong
    if (n == 0) return
    val origin = readLine.trim.toCharArray.map {
      _.asDigit
    }.toLong

    var rest = n
    var e = 0
    var s = origin + (1L << 52)
    var a = origin + (1L << 52)
    while (rest != 0 && a != 0) {
      val untilUp = (isUp - s + a - 1) / a
      if (rest >= untilUp) {
        rest -= untilUp
        s += a * untilUp
        e += 1
        s /= 2
        a /= 2
      } else {
        s += a * rest
        rest = 0L
      }
    }
    println(
      e.toBinaryExpression(12) + (s - (1L << 52)).toBinaryExpression(52)
    )
    solve
  }
  implicit class ConvertLong(val value: Long){
    def toBinaryExpression(digit: Int): String = {
      var result: List[Long] = Nil
      var rest = value
      for (_ ← 0 until digit){
        result ::= rest % 2
        rest /= 2
      }
      result.mkString
    }
  }
  implicit class ConvertString(val array: Array[Int]) {
    def toLong: Long = array.foldLeft(0L){case (l, r) ⇒ l * 2 + r}
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 54932
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  
  printf("%d\n", max(max(a+b, a-b), a*b));
}

Measured memory_bytes: 256
import sys
def query(n):
	print "? %d"%n
	sys.stdout.flush()
	return raw_input()
i=1
while i<=1000000000 and query(i)=="Y":
	i*=10
if i==1000000000*10:
	while i!=0 and query(i+1)=="Y":
		i/=10
	print "! %d"%(i*10 if i!=0 else 1)
else:
	l=i/10
	r=i-1
	while l+1!=r:
		if query(((l+r)/2)*10)=="Y":
			r=(l+r)/2
		else:
			l=(l+r)/2
	print "! %d"%r


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

using namespace std;
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#define pb push_back;
#define mp make_pair;
#define fi first;
#define se second;
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define forin(i, n) for (auto& i : (n))
#define make_unique(x) sort(all((x))); (x).erase(unique(all((x))), (x).end()

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

const int INF = 1 << 29;
const int MOD = 1e9 + 7;
 
int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  forn(i,n){
    int m;
    cin >> m;
    if(m >= k) ++ans;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
int a[maxn];
int b[10]={0,2,5,5,4,5,6,3,7,6};
void compare(string &a,string b)
{
    if(a=="Accept") a=b;
    else if(a.size()<b.size())a=b;
    else if(a.size()==b.size())
    {
        if(a<b)
        a=b;
    }
}
int main()
{
    int m,n;
    cin>>n>>m;
    for(int i=0;i<m;i++)
        cin>>a[i];
        string dp[maxn];
    for(int i=0;i<maxn;i++)
        dp[i]="Accept";

    dp[0]="";
    for(int i=0;i<=n;i++)
        for(int j=0;j<m;j++)
        {
             if(dp[i]=="Accept")
                 continue;
            compare(dp[i+b[a[j]]],dp[i]+char(a[j]+'0'));
        }
        cout<<dp[n]<<endl;
        return 0;

}


Measured memory_bytes: 44928
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, -1, 0, 1 };
	static int R, C, M;
	static boolean[][] f;
	static int[][] m1, m2, m3, time;
	static int[] tr, tc;
	static int curTime, total;

	public static void main(String[] args) {
		R = sc.nextInt();
		C = sc.nextInt();
		M = sc.nextInt();
		f = new boolean[R][C];
		m1 = new int[R][C];
		m2 = new int[R][C];
		m3 = new int[R][C];
		time = new int[R][C];
		for (int i = 0; i < R; ++i) {
			char[] line = sc.next().toCharArray();
			for (int j = 0; j < C; ++j) {
				f[i][j] = line[j] == '.';
			}
			Arrays.fill(time[i], -1);
		}
		tr = new int[M];
		tc = new int[M];
		for (int i = 0; i < R; ++i) {
			for (int j = 0; j < C; ++j) {
				m1[i][j] = sc.nextInt();
			}
		}
		for (int i = 0; i < R; ++i) {
			for (int j = 0; j < C; ++j) {
				m2[i][j] = sc.nextInt();
			}
		}
		for (int i = 0; i < R; ++i) {
			for (int j = 0; j < C; ++j) {
				m3[i][j] = sc.nextInt();
			}
		}
		for (int i = 0; i < M; ++i) {
			tr[i] = sc.nextInt();
			tc[i] = sc.nextInt();
		}
		time[tr[0]][tc[0]] = 0;
		total += m2[tr[0]][tc[0]];
		for (int i = 0; i < M - 1; ++i) {
			move(tr[i], tc[i], tr[i + 1], tc[i + 1]);
		}
		for (int i = 0; i < R; ++i) {
			for (int j = 0; j < C; ++j) {
				if (time[i][j] != -1) {
					total += m3[i][j];
				}
			}
		}
		System.out.println(total);
	}

	static void move(int fr, int fc, int tr, int tc) {
		ArrayList<Integer> path = new ArrayList<Integer>();
		for (int i = 0; i < 4; ++i) {
			int nr = fr + DR[i];
			int nc = fc + DC[i];
			if (nr < 0 || R <= nr || nc < 0 || C <= nc || !f[nr][nc]) continue;
			path.add((nr << 10) + nc);
			if (dfs(i, nr, nc, tr, tc, path)) {
				return;
			}
			path.remove(path.size() - 1);
		}
	}

	static boolean dfs(int dir, int cr, int cc, int tr, int tc, ArrayList<Integer> path) {
		if (cr == tr && cc == tc) {
			for (int i = 0; i < path.size(); ++i) {
				int pr = path.get(i) >> 10;
				int pc = path.get(i) & 0xFF;
				int nowTime = curTime + i + 1;
				if (time[pr][pc] == -1) {
					total += m2[pr][pc];
				} else {
					int onOff = m2[pr][pc] + m3[pr][pc];
					int keep = m1[pr][pc] * (nowTime - time[pr][pc]);
					total += Math.min(onOff, keep);
				}
				time[pr][pc] = nowTime;
			}
			curTime += path.size();
			return true;
		}
		for (int i = 0; i < 4; ++i) {
			if (i == ((dir + 2) & 3)) continue;
			int nr = cr + DR[i];
			int nc = cc + DC[i];
			if (nr < 0 || R <= nr || nc < 0 || C <= nc || !f[nr][nc]) continue;
			path.add((nr << 10) + nc);
			if (dfs(i, nr, nc, tr, tc, path)) {
				return true;
			}
			path.remove(path.size() - 1);
		}
		return false;
	}
}

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

int main(){
	int a,b,c,k; cin>>a>>b>>c>>k;
	int mx=max(a,max(b,c));
	int ans=mx;
	rep(i,k) ans*=2;
	cout<<ans+a+b+c-mx<<endl;
}

Measured memory_bytes: 3604
SA = list(input())
SB = list(input())
SC = list(input())

dic = dict()
SA.reverse()
SB.reverse()
SC.reverse()
dic['a'] = SA
dic['b'] = SB
dic['c'] = SC

tmp = 'a'
while dic[tmp] != []:
    tmp = dic[tmp].pop()
    

print (tmp.upper())


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final int X = s.nextInt();
			final int Y = s.nextInt();

			if(Math.abs(X - Y) > 1) {
				System.out.println(Math.max(X, Y) * 2 - 1);
			} else {
				System.out.println(X + Y);
			}
		}
	}
}


Measured memory_bytes: 24020
// E - Sum of gcd of Tuples (Hard)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

ll cnt[100001]; // cnt[i]: GCDがiとなる場合の数

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

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

	// GCDがiの倍数となる場合の数（数列のそれぞれの数がiの倍数であればよい）で初期化
	for (int i=1; i<=K; i++) {
		cnt[i] = mod_pow(K/i, N, MOD);
	}

	for (int i=K; i>=1; i--) {
		for (int j=2; i*j<=K; j++) {
			cnt[i] = (cnt[i] - cnt[i*j] + MOD) % MOD;
		}
	}

	ll ans = 0;
	for (int i=1; i<=K; i++) {
		ans = (ans + (cnt[i] * i % MOD)) % MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
#define int long long
using namespace std ;
int read() {
  int x = 0 , f = 1 ;
  char c = getchar() ;
  while(c < 48 || c > 57) {
    if(c == '-') f = -1 ;
    c = getchar() ;
  }
  while(c > 47 && c < 58) {
    x = (x << 1) + (x << 3) + (c & 15) ;
    c = getchar() ;
  }
  return x * f ;
}

int n ;
const int N = 3e5 + 5 ;
int a[N] ;
int c[N][62] ;
int mx = 0 ;
const int mod = 1e9 + 7 ;
signed main() {
  n  = read() ;
  for(int i = 1 ; i <= n ; i ++) a[i] = read() , mx = max(mx , a[i]) ;
  for(int i = 1 ; i <= n ; i ++)
    for(int j = 0 ; (1ll << j) <= a[i] ; j ++)
      if(a[i] & (1ll << j)) c[i][j] = 1 ;
  int ans = 0 ;
  for(int j = 0 ; (1ll << j) <= mx ; j ++) {
    int tot = 0 ;
    for(int i = 1 ; i <= n ; i ++) {
      if(c[i][j]) { tot ++ ; }
    }
    ans=(ans+(1ll<<j)%mod*((tot*(n-tot))%mod)%mod)%mod;  }
  cout << ans << '\n' ;
  return 0 ;
}

Measured memory_bytes: 147840
#include <bits/stdc++.h>
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define INF 1e9
using namespace std;
typedef long long ll;

signed main() {
  // std::ifstream in ("input.txt"); std::cin.rdbuf(in.rdbuf());
  int k, s;
  cin >> k >> s;

  int cnt = 0;
  REP(x, k + 1){
    REP(y, k + 1){
      if ((s - x - y >= 0) && (s - x - y <= k)){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>

using std::cin;
using std::cout;
using std::endl;

int main(void) {
	int t,n;
	cin >> t >> n;

	while ( t != 0 || n != 0 ) {
		std::map< std::pair<int,int>, int> area;
		std::pair<int,int> now,temp;
		for (int i = 0; i < n; i ++) {
			cin >> temp.first >> temp.second;
			area[temp] = -1;
		}

		int count_area = 1;
		cin >> now.first >> now.second;
		std::queue< std::pair<int,int> > search;
		std::queue<int> d;
		search.push(now);
		d.push(0);
		int turn = 0;

		while ( (turn < t) && !(d.empty()) ) {
			now = search.front();
			temp = now;
			area[temp] = -1;

			turn = d.front();
			search.pop();
			d.pop();

			if ( turn < t ) {
				temp.first++;
				if (area[temp] != -1) {
					search.push(temp);
					d.push(turn+1);
					count_area++;
					area[temp] = -1;
				}
				temp.second++;
				if (area[temp] != -1) {
					search.push(temp);
					d.push(turn+1);
					count_area++;
					area[temp] = -1;
				}
				temp.first--;
				if (area[temp] != -1) {
					search.push(temp);
					d.push(turn+1);
					count_area++;
					area[temp] = -1;
				}
				temp.first--;
				temp.second--;
				if (area[temp] != -1) {
					search.push(temp);
					d.push(turn+1);
					count_area++;
					area[temp] = -1;
				}
				temp.second--;
				if (area[temp] != -1) {
					search.push(temp);
					d.push(turn+1);
					count_area++;
					area[temp] = -1;
				}
				temp.first++;
				if (area[temp] != -1) {
					search.push(temp);
					d.push(turn+1);
					count_area++;
					area[temp] = -1;
				}
			}
		}

		cout << count_area << endl;
		cin >> t >> n;
	}

	return 0;
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(c-a+b >= 0) cout << c-a+b << endl;
  else cout << 0 << endl;
  }


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

int main(){

    int X, Y; 
    cin >> X >> Y;

    if(0 != Y%2){
        cout << "No" << endl;
        return 0;
    }

    if(Y/2 <= 2*X && X <= Y/2){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3636
s = input()

LETTERS_A = "BCDEFGHIJKLMNOPQRSTUVWXYZ"
LETTERS_C = "ABDEFGHIJKLMNOPQRSTUVWXYZ"
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
count = 0
is_ok = True
c1, c2 = False, False
for i in range(len(s)):
    if i == 0:
        c1 = (s[i] == "A")
        if s[i] in LETTERS_A:
            is_ok = False
    elif (2 <= i) and (i <= len(s)-2):
        if s[i] == "C":
            count += 1
        if s[i] in LETTERS_C:
            is_ok = False
    elif s[i] in LETTERS:
        is_ok = False
        
c2 = (count == 1)
if c1 and c2 and is_ok:
    print("AC")
else:
    print("WA")


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

int main(int argc, char* argv[])
{
	string s1;
	cin>>s1;
	string s2;
	s2.clear();
	int i=s1.size()-1;
	for (;i>=0;i--){
		s2+=s1[i];
	}
	if (!s1.compare(s2)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            long point = 1;
            for (int i = 0; i < k; i++) {
                point *= a[i];
            }

            for (int i = 0; i < n - k; i++) {
                int r = i + k;
                if (a[r] > a[i]) {
                    out.println("Yes");
                } else {
                    out.println("No");
                }
            }

        }

    }
}



Measured memory_bytes: 60872
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [input() for i in range(h)]
q = []
start = []
ans = 0
dist = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            start.append([i, j])
        else:
            dist[i][j] = True
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
while start:
    check = deepcopy(dist)
    s_y, s_x = start.pop()
    check[s_y][s_x] = True
    q = [(s_y, s_x)]
    cnt = -1
    while q:
        cnt += 1
        qq = []
        for y, x in q:
            for dy, dx in test:
                yy, xx = y + dy, x + dx
                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or check[yy][xx]:
                    continue
                else:
                    check[yy][xx] = True
                    qq.append((yy, xx))
        q = qq
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int main()
{
	int x1, x2, x3, x4, x5 = 0;
	int a = 0;
	cin >> x1 >> x2 >> x3 >> x4 >> x5;
	if (x1 == 0)a = x2 - 1;
	if (x2 == 0)a = x1 + 1;
	if (x3 == 0)a = x2 + 1;
	if (x4 == 0)a = x3 + 1;
	if (x5 == 0)a = x4 + 1;
	cout << a;
    return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <string>

using namespace std;

int main()
{
 string x, y;
  cin >> x;
  cin >> y;
  int ans = 0;
  for (int i = 0 ; i<3;++i)
  {
    ans+= x[i] == y[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
res = dict()
for i in range(n):
    m = input()
    m = sorted(m)
    m = ''.join(m)
    if m in res:
        res[m] += 1
    else:
        res[m] = 1

for i in res:
  res[i] = res[i]*(res[i]-1)//2
print(sum(res.values()))

Measured memory_bytes: 62296
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,d = i2()
x = []
for i in range(n):
	a = intl()
	x.append(a)

def dist(a,b,d):
	dist = 0
	for i in range(d):
		dist += (a[i] - b[i])**2
	return dist		

cnt = 0
for i in range(n-1):
	for j in range(i+1,n):
		test = dist(x[i], x[j], d)
		if ( (test)**(1/2) )%1 == 0:
			cnt += 1
print(cnt)


Measured memory_bytes: 9412
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

typedef pair<int, int> P;

int main() {
  int n, k; in(n),in(k);
  map<int, int> M;
  int a;
  loop(i,0,n) {
    in(a);
    M[a]++;
  }
  vector<P> A;
  for (auto&&m : M) {
    A.emplace_back(m.second, m.first);
  }
  sort(A.begin(), A.end());
  int m = A.size();
  int idx = 0;
  ll ans = 0;
  while (m > k) {
    ans += A[idx++].first;
    m--;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 14592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[][] d = new int[n][2];
    for (int i = 0; i < n; i++) {
      d[i] = sc.nextIntArray(2);
    }
    boolean found = false;
    int count = 0;
    for (int[] di : d) {
      if (di[0] == di[1]) count++;
      else count = 0;
      if (count == 3) {
        found = true;
        break;
      }
    }
    System.out.println(found ? "Yes" : "No");
  }
}

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

using namespace std;

//#define DEBUG

#ifdef DEBUG
#define dump(i) cout << "[*] " #i " : " << i << endl;
#define debug(i) i
#else
#define dump(i)
#define debug(i)
#endif

int main() {
        int n;
        cin >> n;
        vector<int> a(n+2);
        a[0] = a[n+1] = 0;
        for (int i = 1; i <= n; ++i) {
                cin >> a[i];
        }
        long long int sum = 0;
        for (int i = 0; i < a.size()-1; ++i) {
                sum += (long long int)abs(a[i+1] - a[i]);
        }
        dump(sum);

        for (int i = 1; i < n+1; ++i) {
                cout << sum + (abs(a[i+1]-a[i-1])-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])) << endl;
        }

        return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }


void solve(long long P, long long Q, long long R){
	ll res = 1e8;
	chmin(res, P+Q);
	chmin(res, P+R);
	chmin(res, R+Q);
	cout << res << "\n";
}

int main(){
    long long P;
    scanf("%lld",&P);
    long long Q;
    scanf("%lld",&Q);
    long long R;
    scanf("%lld",&R);
    solve(P, Q, R);
    return 0;
}


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

using namespace std;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	string x=s.substr(0,n/2);
	x=x+x;
	if(x==s)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
list2 = [4, 6, 9, 11]

if x == 2 or y == 2:
    print('No')
else:
    if x in list2 and y in list2:
        print('Yes')
    else:
        if x not in list2 and y not in list2:
            print('Yes')
        else:
            print('No')

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

int main() {
  int N;
  cin >> N;
  map<string, int> S;
  
  for(int i=0; i<N; i++){
    string s;
    cin >> s;
    S[s]+=1;
  }
  
  //max求める
  int max = 0;
  for(auto s :S){
    auto val = s.second;
    if(val>max){
      max=val;
    }
  }
  
  map<string,int> Ans;
  for(auto s : S){
    if(s.second==max){
      Ans[s.first] = 1;
    }
  }
  
  for(auto a : Ans){
    cout << a.first << endl;
  }
  
  //cout << S.begin() << endl;
  
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));

  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
    //}
  //}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}

int main(){
	ll N; cin>>N;
    vector<ll> a(N+1);
  vector<ll> l(N+1,0);
  vector<ll> r(N+2,0);
    rep1(i,N){
      cin>>a[i];
    }
  ll ans=0;
  	l[0]=0;
  	r[N+1]=0;
  	l[1]=a[1];
  	r[N]=a[N];
  	for(int i=2;i<=N;i++) {
    	l[i]=gcd(l[i-1],a[i]);
    }
  for(int i=N-1;i>=1;i--){
  	r[i]=gcd(r[i+1],a[i]);
  }
  rep1(i,N){
  	if(i==1){
    	ans=max(ans,r[2]);
    }else if(i==N){
    	ans=max(ans,l[N-1]);
    }else{
    	ans=max(ans,gcd(l[i-1],r[i+1]));
    }
  }
  cout<<ans<<endl;
}

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

int main(){
    ll T1,T2,A1,A2,B1,B2;cin>>T1>>T2>>A1>>A2>>B1>>B2;
    ll C=T1*A1-T1*B1,D=T2*A2-T2*B2;
    if(C+D==0)cout<<"infinity"<<endl;
    else if(C>0){
        ll ans;
        if(C+D>0)ans=0;
        else{
            ans=C/(-C-D)*2+1;
            if(C%(-C-D)==0)ans-=1;
        }
        cout<<ans<<endl;
    }
    else{
        ll ans;
        if(C+D<0)ans=0;
        else{
            ans=-C/(C+D)*2+1;
            if(-C%(C+D)==0)ans-=1;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
int n,aa[110],m;
pair<int,int> ab[110];
signed main(){
	cin>>n;
	rep(i,n){
		cin>>aa[i];
	}
	cin>>m;
	rep(i,m){
		cin>>ab[i].first>>ab[i].second;
	}
	rep(i,m){
		int c=0;
		rep(j,n){
			c+=aa[j];
		}
		cout<<c+ab[i].second-aa[ab[i].first-1]<<endl;
	}	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      while(1)
      {

            c-=b;
            if (c<=0)break;a-=d;
            if (a<=0)break;
      }
      if (a>0) cout << "Yes" << endl;
      else cout << "No" << endl;
 	return 0;
}



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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int N;
string S;
vector<char> P{'3', '5', '7'};

lint cnt = 0;
void dfs(int i, string& X) {

    if (0 < i) {
        bool wit_3 = false, wit_5 = false, wit_7 = false;
        for (int j = 0; j < X.size(); j++) {
            if (X[j] == '3') wit_3 = true;
            if (X[j] == '5') wit_5 = true;
            if (X[j] == '7') wit_7 = true;
        }
        bool less = (stoi(X) <= stoi(S));
        if (wit_3 && wit_5 && wit_7 && less) {
            cnt++;
            // dump(X);
        }
    }

    if (i == N) { return; }

    for (int j = 0; j < 3; j++) {
        X.push_back(P[j]);
        dfs(i + 1, X);
        X.pop_back();
    }
}

int main() {
    cin >> S;
    N = S.size();

    string A = "";
    dfs(0, A);
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

template <typename T>
T powi(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <ll mod>
class ModInt {
private:
    ll num;
public:
    ModInt() {};
    ModInt(ll n) { num = n % mod; }
    ModInt inv() const { return powi(*this, mod-2); }
    explicit operator ll() const { return num; }

    ModInt& operator+=(const ModInt& a) {
        num += a.num; 
        if (num >= mod) num -= mod; 
        return *this;
    }
    ModInt& operator-=(const ModInt& a) {
        if (num < a.num) num += mod;
        num -= a.num;
        return *this;
    }
    ModInt& operator*=(const ModInt& a) {
        num = num * a.num % mod;
        return *this;
    }
    ModInt& operator/=(const ModInt& a) { return *this *= a.inv(); }
    friend ModInt operator+(const ModInt& a, const ModInt& b) { return ModInt(a) += b; }
    friend ModInt operator-(const ModInt& a, const ModInt& b) { return ModInt(a) -= b; }
    friend ModInt operator*(const ModInt& a, const ModInt& b) { return ModInt(a) *= b; }
    friend ModInt operator/(const ModInt& a, const ModInt& b) { return ModInt(a) /= b; }

    friend ostream& operator<<(ostream& os, const ModInt& a) { return os << a.num; }
    friend istream& operator>>(istream& is, ModInt& a) {
        ll tmp;
        is >> tmp;
        a.num = tmp % mod;
        return is;
    }
};
using mint = ModInt<1000000007>;
//using mint = ModInt<998244353>;

int main() {
    string l;
    cin >> l;
    int n = l.length();

    int pcnt = 0;
    mint ans = 0;
    for (int i = 0; i < n; ++i) {
        if (l[i] == '0') continue;
        ans += powi<mint>(2, pcnt) * powi<mint>(3, n-i-1);
        ++pcnt;
    }
    ans += powi<mint>(2, pcnt);

    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, i;
    cin >> n;
    string s;
    cin >> s;
    int cntW = count(all(s), 'W');
    //[x, n-1] ; x = n - cnwW
    int l = s.size() - cntW;
    int ans = count(s.begin() + l, s.end(), 'R');
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define poly vector<ll>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool d=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') d=0;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return d?x:-x;
}
inline void write(ll x){
	if(x<0) x=-x,putchar('-');
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2e5+5;
int head[N],opt,sz[N];
struct info{
	int to,nxt;
}e[N<<1];
void add(int x,int y){
	e[++opt]=(info){y,head[x]};head[x]=opt;
	e[++opt]=(info){x,head[y]};head[y]=opt;
}
int mx[N],cmx[N],mn[N];
ll ans;
char s[N];
void dfs1(int u,int fa){
	if(s[u]=='1') mn[u]=0,sz[u]=1;
	else mn[u]=0x3f3f3f3f;
	for(int i=head[u];i;i=e[i].nxt){
		int k=e[i].to;
		if(k==fa) continue;
		dfs1(k,u);sz[u]+=sz[k];
		int t=mx[k]+1;
		if(mx[u]<t) cmx[u]=mx[u],mx[u]=t;
		else cmx[u]=max(cmx[u],t);
		if(sz[k]) mn[u]=min(mn[u],t);
	}
}
void dfs2(int u,int fa){
	int ssw=min(mx[u]-1,cmx[u]+1);
	if(ssw>=mn[u]) ans+=ssw-mn[u]+1;
	for(int i=head[u];i;i=e[i].nxt){
		int k=e[i].to;
		if(k==fa) continue;
		int t=mx[u]==mx[k]+1?cmx[u]+1:mx[u]+1;
		if(mx[k]<t) cmx[k]=mx[k],mx[k]=t;
		else cmx[k]=max(cmx[k],t);
		if(sz[k]<sz[1]) mn[k]=min(mn[k],t);
		dfs2(k,u);
	}
}
int main(){
	int n=read();
	For(i,1,n-1) add(read(),read());
	scanf("%s",s+1);
	dfs1(1,0);dfs2(1,0);
	cout<<ans+1;
}

Measured memory_bytes: 22732
#include<stdio.h>
#include<vector>
#include<math.h>
#include<cstring> 
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
const int MAXN = 1e5 + 7;
int ans[MAXN];
int v1[MAXN];
int v2[MAXN];
bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &ans[i]);
		if (i % 2 == 0)
			v1[ans[i]]++;
		else
			v2[ans[i]]++;
	}
	int x=0, y=0;
	for (int i = 1; i <= MAXN; i++)
	{
		if (v1[i] > v1[x])
		{
			x = i;
		}
		if (v2[i] > v2[y])
		{
			y = i;
		}
	}
	sort(v1, v1 + MAXN, cmp);
	sort(v2, v2 + MAXN, cmp);
	if (x != y)
	{
		cout << n - v1[0] - v2[0] << endl;
	}
	else
	{
		cout << min(n - v1[0] - v2[1], n - v1[1] - v2[0]) << endl;
	}
	return 0;
}


Measured memory_bytes: 1536
fn main() {
    // input
    // S
    let s = read_line::<String>();

    let weather = vec!["Sunny", "Cloudy", "Rainy"];

    for (i, &val) in weather.iter().enumerate() {
        if s == val {
            println!("{}", weather[(i + 1) % 3]);
            break;
        }
    }
}

#[allow(dead_code)]
fn read_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())

uf = UnionFind(n)
for i in range(m):
    a,b=map(int,input().split())
    uf.union(a-1,b-1)

print(len(uf.roots())-1)


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

const int N = (int)2e5 + 5;

ll d[N], c[N], n;

void init() {
  cin >> n;
  for(int i = 1 ; i <= n ; ++i) cin >> d[i] >> c[i];
}
void solve() {
  ll ans = 0;
  vector<int> left;
  for(int i = 1 ; i <= n ; ++i) {
    while(c[i] > 1) {
      if(c[i] % 2) left.push_back(d[i]);
      ans += (c[i] / 2) * ((d[i] >= 5) + 1);
      if(d[i] >= 5) d[i] = (d[i] + d[i]) / 10 + (d[i] + d[i]) % 10;
      else d[i] = d[i] + d[i];
      c[i] /= 2;
    }
    left.push_back(d[i]);
  }
  for(int i = 1 ; i < (int)left.size() ; ++i) {
    int sum = left[i] + left[i - 1];
    if(sum >= 10) ans += 2, left[i] = sum / 10 + sum % 10;
    else ans += 1, left[i] = sum;
  }
  cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  init();
  solve();
}


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

int main(){
  int A, B;
  cin >> A >> B;
  int s, t, u, v;
  int ans = 0;
  for(int i = A; i <=  B; i ++ ){
    s = i % 10, t = i / 10000 % 10;
    u = i / 10 % 10;  v = i / 1000 % 10;
    if( s == t && u == v) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring> 
#include<string>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int dp[100000][3];
int main()
{
	  int a,b,c,d;
	  cin>>a;
	  dp[0][0]=0;
	  dp[0][1]=0;
	  dp[0][2]=0;
	  for(int i=1;i<=a;i++)
	  {
	  	cin>>b;
	  	cin>>c;
	  	cin>>d;	 
	  	dp[i][0]=max(dp[i-1][2],dp[i-1][1])+b;
	  	dp[i][1]=max(dp[i-1][0],dp[i-1][2])+c;
	  	dp[i][2]=max(dp[i-1][0],dp[i-1][1])+d;
	  }	  
	  cout<<max(max(dp[a][0],dp[a][1]),dp[a][2])<<endl;
	  return 0;
}

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

using namespace std;

const int N = 1e5 + 5;

set<int> e[N], g[N];
int p[N];
int find(int x) { return p[x] < 0 ? x : p[x] = find(p[x]); }
bool merge(int u, int v) {
  if ((u = find(u)) == (v = find(v)))
    return false;
  if (-p[u] > -p[v])
    swap(u, v);
  p[v] += p[u];
  p[u] = v;
  return true;
}

vector<tuple<int, int, int> > ans;

int main() {
  memset(p, -1, sizeof p);
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (merge(u, v)) {
      g[u].insert(v);
      g[v].insert(u);
    }
    else {
      e[u].insert(v);
      e[v].insert(u);
    }
  }
  if (m & 1) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    while (e[i].size() >= 2) {
      auto it = e[i].begin(), it2 = it;
      ++it2;
      ans.emplace_back(*it, i, *it2);
      e[*it].erase(i);
      e[i].erase(it);
      e[*it2].erase(i);
      e[i].erase(it2);
    }
  }
  priority_queue<pair<int, int> > pq;
  for (int i = 1; i <= n; ++i) {
    pq.emplace(-(int)g[i].size(), i);
  }
  while (!pq.empty()) {
    int v = pq.top().second, cnt = -pq.top().first; pq.pop();
    if (cnt != g[v].size()) continue;
    if (g[v].empty()) continue;
    assert(g[v].size() == 1);
    auto it = g[v].begin();
    int par = *it;
    g[v].erase(it);
    g[par].erase(v);
    pq.emplace(-(int)g[par].size(), par);
    if (e[v].size() > 0) {
      assert(e[v].size() == 1);
      it = e[v].begin();
      ans.emplace_back(*it, v, par);
      e[*it].erase(v);
      e[v].erase(it);
    }
    else {
      if (e[par].size() > 0) {
        assert(e[par].size() == 1);
        it = e[par].begin();
        ans.emplace_back(*it, par, v);
        e[*it].erase(par);
        e[par].erase(it);
      }
      else {
        e[par].insert(v);
        e[v].insert(par);
      }
    }
  }
  for (auto boom : ans) {
    int u, v, w;
    tie(u,v,w) = boom;
    printf("%d %d\n%d %d\n", v, u, v, w);
  }
  return 0;
}

Measured memory_bytes: 22648
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;
int main() {
ll N, M;cin >> N >> M;
vector<ll> A(M);
vector<ll> B(M);
rep(i, 0, M)cin >> A[i] >> B[i];
if(*min_element(ALL(B)) - *max_element(ALL(A)) + 1 < 0){cout << 0;exit(0);}
cout << *min_element(ALL(B)) - *max_element(ALL(A)) + 1;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VI  ok(n), pn(n);
	rep(i, m){
		int p; string s;
		cin >>p >>s;
		if(s[0]=='A') ok[p-1]=1;
		else{
			if(ok[p-1]!=1) pn[p-1]++;
		}
	}
	int ac=0, pen=0;
	rep(i, n){
		if(ok[i]==1){
			ac++;
			pen += pn[i];
		}
	}
	cout << ac <<" "<<pen <<"\n";
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <bitset>
#include <math.h>
#define INPUT(X) cin >> X
#define OUTPUT(X) cout << X << endl
#define REPEAT(i,n) for(int i=0;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
const ll MOD = 1e9+7;
#define INF 10000000000000


inline ll Upstair(ll n){
	ll rt;
	if(n==1) return 1;
	return n*Upstair(n-1);
}

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

class Tree
{
	public:
//		Tree(int _root);
		int root;
		vector<int> next;
		int value = 0;
};

int main(void) {


	int N;
	INPUT(N);
	vector<ll> h(N);
	vector<ll> dp(N,INF);
	REPEAT(i,N)INPUT(h[i]);

	dp[0] = 0;
	dp[1] = abs(h[0]-h[1]);
//	OUTPUT(dp[0]);
//	OUTPUT(dp[1]);
	for(int i=2;i<N;i++){
		ChangeMinimum( dp[i], dp[i-1] + abs(h[i-1]-h[i]) );
		ChangeMinimum( dp[i], dp[i-2] + abs(h[i-2]-h[i]) );
//		OUTPUT(dp[i]);
	}

	int ans = dp[N-1];

	OUTPUT(ans);
		
}

Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author win11905
 */

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};


class TaskA {
private:
	int n;
public:
	void solve(istream& cin, ostream& cout) {
		cin >> n;
		cout << (n == 3 or n == 5 or n == 7 ? "YES" : "NO") << endl;
	}
};

class Solver {
public:
	void solve(std::istream& in, std::ostream& out) {
		TaskA *obj = new TaskA();
		obj->solve(in, out);
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	Solver solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
lst = []
pnt = []
for i in range(n):
    a,b = map(int,input().split())
    lst.append((a,b))

for i in range(m):
    c,d = map(int,input().split())
    pnt.append((c,d))

for e in lst:
    for j in range(m):
        d = abs(e[0]-pnt[j][0]) + abs(e[1]-pnt[j][1])
        if j==0:
            mindis = d
            loc = j+1
        elif d < mindis:
            mindis = d
            loc = j+1
    print(loc)

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

alias P = Tuple!(int, "to", long, "a", long, "b");
alias S = Tuple!(int, "i", long, "c");

void main()
{
    auto nmst = readln.split.to!(int[]);
    auto N = nmst[0];
    auto M = nmst[1];
    auto s = nmst[2]-1;
    auto t = nmst[3]-1;
    
    auto G = new P[][N];
    foreach (_; 0..M) {
        auto uvab = readln.split.to!(int[]);
        auto u = uvab[0]-1;
        auto v = uvab[1]-1;
        long a = uvab[2];
        long b = uvab[3];

        G[u] ~= P(v, a, b);
        G[v] ~= P(u, a, b);
    }

    auto DP1 = new long[](N);
    DP1[] = long.max/3;
    DP1[s] = 0;
    auto Q = heapify!"a.c > b.c"([S(s, 0)]);
    while (!Q.empty) {
        auto i = Q.front.i;
        auto c = Q.front.c;
        Q.removeFront();
        if (DP1[i] < c) continue;
        foreach (n; G[i]) if (DP1[n.to] > c + n.a) {
            DP1[n.to] = c + n.a;
            Q.insert(S(n.to, c + n.a));
        }
    }

    auto DP2 = new long[](N);
    DP2[] = long.max/3;
    DP2[t] = 0;
    Q = heapify!"a.c > b.c"([S(t, 0)]);
    while (!Q.empty) {
        auto i = Q.front.i;
        auto c = Q.front.c;
        Q.removeFront();
        if (DP2[i] < c) continue;
        foreach (n; G[i]) if (DP2[n.to] > c + n.b) {
            DP2[n.to] = c + n.b;
            Q.insert(S(n.to, c + n.b));
        }
    }

    S[] cs;
    foreach (i; 0..N) {
        cs ~= S(i, DP1[i] + DP2[i]);
    }
    sort!"a.c < b.c"(cs);
    foreach (i; 0..N) {
        while (cs[0].i < i) cs = cs[1..$];
        writeln(10L^^15 - cs[0].c);
    }
}

Measured memory_bytes: 28340
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define in (void)scanf
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009,4999999999999997
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
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 sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
//typedef struct fac { LL n, exp; }F;
//LL fact(LL n,F*a){LL x=n,i,j,c=0;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
LL nibtan(LL* a,LL n,LL x){LL p=0,q=n/2,r=n-1;while(r-p>1){if(x>=a[q])p=q;if(x<=a[q])r=q;q=(p+r)/2;}return a[p]==x?p:r;}
//snippet

#define N 300009

void run(void) {
	char s[4];
	in("%s", s);
	s[3] = '\0';
	if (!strcmp(s, "RRR"))printf("3");
	else if (!strcmp(s, "RRS") || !strcmp(s, "SRR"))printf("2");
	else if (!strcmp(s, "SSS"))printf("0");
	else printf("1");
}

int main(void) {
	int test = 1;
//	in("%d", &test);
	while (test--) {
		run();
		fflush(stdout);
	}
	return 0;
}

Measured memory_bytes: 1644