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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int n, k; cin >> n >> k;
    string s; cin >> s;

    int groups = 1;
    for(int i = 1; i < n; ++i) {
        if(s[i] != s[i-1]) groups++;
    }

    int ans = min(n-1, n-groups + 2*k);

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


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		char[] data1 = s1.toCharArray();
		String s2 = sc.next();
		char[] data2 = s2.toCharArray();
		for (int k = 0; k < data1.length - 1; k++) {
			for (int i = 0; i < data1.length - 1; i++) {
				if (data1[i] > data1[i + 1]) {
					char a = data1[i];
					data1[i] = data1[i + 1];
					data1[i + 1] = a;
				}
			}
		}
		for (int k = 0; k < data2.length - 1; k++) {
			for (int i = 0; i < data2.length - 1; i++) {
				if (data2[i] < data2[i + 1]) {
					char a = data2[i];
					data2[i] = data2[i + 1];
					data2[i + 1] = a;
				}
			}
		}

		String st1 = String.valueOf(data1);
		String st2 = String.valueOf(data2);
		int j = st1.compareTo(st2);
		if (j < 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}

}

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


struct tree{
	tree* left;
	tree* right;
	tree* parent;
	int val;
};

void printPreorder(tree* root){
	if(root== NULL)return;
	cout << " " << root->val;
	printPreorder(root->left);
	printPreorder(root->right);
	return;
}
void printInorder(tree* root){
	if(root== NULL)return;
	printInorder(root->left);
	cout << " " << root->val;
	printInorder(root->right);
	return;
}

void find(int val, tree* root){
	if(root->val == val) cout << "yes" << endl;
	else{
		tree* next;
		if(val < root->val)next = root->left;
		else next = root->right;

		if(next)find(val,next);
		else cout << "no" << endl;
	}
}

void insert(int val, tree* root){
	tree* next;
	bool flag = val < root->val;
	if(flag)next = root->left;
	else next = root->right;

	if(next == NULL){
		tree* newNode = (tree*)malloc(sizeof(tree));
		newNode->val = val;
		newNode->left = NULL;
		newNode->right = NULL;
		newNode->parent = root;
		if(flag)root->left = newNode;
		else root->right = newNode;
	}else{
		insert(val,next);
	}
}

int main(){
	ios_base::sync_with_stdio(false);

	tree* root = (tree*)malloc(sizeof(tree));

	char order[10];
	int val;
	int numOfOrder;

	cin >> numOfOrder;
	cin >> order;
	cin >> val;

	root->val = val;
	root->left = NULL;
	root->right = NULL;
	root->parent = NULL;
	

	for(int i = 0; i <  numOfOrder - 1; i++){
		cin >> order;
		if(order[0] == 'i'){
			cin >> val;
			insert(val, root);
		}else if(order[0] == 'p'){
			printInorder(root);
			cout << endl;
			printPreorder(root);
			cout << endl;
		}else{
			cin >> val;
			find(val,root);
		}
	}


	return 0;

}

Measured memory_bytes: 19956
def foo(l, x):
	return l[x][0]==l[x][1]

n=int(input())
l=[tuple(input().split()) for _ in range(n)]
for i in range(n-2):
	if foo(l, i) and foo(l, i+1) and foo(l, i+2):
		print('Yes')
		quit()
print('No')

Measured memory_bytes: 9208
#include <iostream>
using namespace std;
typedef long long llong;

llong *A;
int n, k;

int check(llong p) {
  int i = 0;
  for (int j = 0; j < k; j++) {
    llong s = 0;
    while (s + A[i] <= p) {
      s += A[i];
      i++;
      if (i == n) return n;
    }
  }
  return i;
}

llong solve(void) {
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while (right - left > 1) {
    mid = (left + right) / 2;
    int v = check(mid);
    if (v >= n) right = mid;
    else left = mid;
  }
  
  return right;
}

int main(void){
  cin >> n >> k;
  A = new llong[n];
  
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    A[i] = v;
  }
  
  llong ans = solve();
  
  cout << ans << endl;
  
  delete[] A; 
  return 0;
}

Measured memory_bytes: 1796
#include <cstdio>

const int MAX_CNT = 50000;

long X;

int main() {
  scanf("%ld", &X);

  int cnt = 0;
  long sum = 0;
  for (int i = 1; i < MAX_CNT; i++) {
    sum += i;
    if (sum >= X) {
      cnt = i;
      break;
    }
  }

  printf("%d\n", cnt);
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////
vector<pair<ll, ll>>prime_factorize(ll n) {
	vector<pair<ll, ll>>res;
	for (ll p = 2; p*p <= n; ++p) {
		if (n%p != 0)continue;
		int num = 0;
		while (n%p == 0) { ++num; n /= p; }
		res.push_back(make_pair(p, num));
	}
	if (n != 1)res.push_back(make_pair(n, 1));
	return res;
}
const int MAX = 210000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}
ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
int main() {
	int N, M, K;
	cin >> N >> M >> K;
	COMinit();
	ll ans = 0;
	for (ll d = 1; d <= N - 1; ++d) {
		ll key = d * (N - d)*M*M%INF;
		ans += key;
		ans %= INF;
	}
	for (ll d = 1; d <= M - 1; ++d) {
		ll key = d * (M - d)*N*N;
		ans += key;
		ans %= INF;
	}
	ll key2 = COM(N*M - 2, K - 2);
	ans *= key2;
	ans %= INF;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5120
n=int(input())
#print(n)

def kaisu(j):
    kotae=0
    while j % 2==0:
        j = j >> 1
        kotae+=1
    return kotae

kaisu0=0
ans=1
for i in range(1,n+1):
    if kaisu0 < kaisu(i):
        kaisu0 = kaisu(i)
        ans = i

print(ans)



Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            List<string> lstN = new List<string>();
            List<string> lstM = new List<string>();
            int iN = int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < iN; i++) { lstN.Add(Console.ReadLine().Trim()); }
            int iM = int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < iM; i++) { lstM.Add(Console.ReadLine().Trim()); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            lstN.Sort();
            lstM.Sort();
            List<int> lstC = new List<int>();
            for (int i = 0; i < iN; i++)
            {
                lstC.Add(lstN.Count(x => x == lstN[i]) - lstM.Count(x => x == lstN[i]));          // LinqでListの該当個数
            }
            lstC.Sort(delegate (int mca1, int mca2) { return (int)(mca2 - mca1); });              // 降順
            iOut = lstC[0] < 0 ? 0 : lstC[0];

            // 出力
            Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


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

using namespace std;
using P = pair<int, int>;

int main() {
  int N, M;
  cin >> N >> M;
  vector<P> p(M);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    p[i] = {b - 1, a - 1};
  }
  sort(begin(p), end(p));

  int cur = 0;
  int ans = 1;
  for (int i = cur + 1; i < M; ++i) {
    if (p[i].second < p[cur].first) continue;
    ++ans;
    cur = i;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
n = int(input())
s = input()
countr, countl = 0, 0

for i in range(n-1, -1, -1):
    if s[i] == ')': countr += 1
    elif countr > 0: countr -= 1
s = '('*countr+s
n = len(s)

for i in range(n):
    if s[i] == '(': countl += 1
    elif countl > 0: countl -= 1
s += ')'*countl

print(s)


Measured memory_bytes: 9064
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 n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = Vec::with_capacity(n);
    let mut b: Vec<usize> = Vec::with_capacity(n);
    for _ in 0..n {
        a.push(iterator.next().unwrap().parse().unwrap());
        b.push(iterator.next().unwrap().parse().unwrap());
    }

    let mut ans = 0;
    for i in (0..n).rev() {
        let x = baisu(a[i] + ans, b[i]);
        ans += x - (a[i] + ans);
    }

    return ans.to_string()
}

fn baisu(a: usize, b: usize) -> usize {
    if a == 0 {
        return 0;
    }
    if b >= a {
        return b;
    }
    if a % b == 0 {
        a
    } else {
        b * (a / b + 1)
    }
}


Measured memory_bytes: 10232
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              push_back
#define all(v)          v.begin(),v.end()

#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

// inline int setBit(int n,int pos) { return n = n | (1 << pos); }
// inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
// inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }

// int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
// int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// unsigned int num = rng();
// shuffle(V.begin(), V.end(), rng);

/******************************************************************************************/

// const int MAX = 500010;
// const int INF = 0x3f3f3f3f;
// const int MOD = 1000000007;

// inline int add(int a, int b) { return a + b >= MOD ? a + b - MOD : a + b; }
// inline int sub(int a, int b) { return a - b < 0 ? a - b + MOD : a - b; }
// inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }


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

    // freopen("in", "r", stdin); 
    // freopen("out", "w", stdout);
    
    string s;
    cin >> s;
    for(int i=0;i<(int)s.size();i++) if(s[i] == '?') s[i] = 'D';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
set<int> s;
s.insert(a);
  s.insert(b);
  s.insert(c);
  if(s.size()==2){cout<<"Yes";}
  else cout<<"No";
  
  return 0;
}



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

int main(){
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<pair<int,int>> a(n);
    rep(i ,n) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    rep(i ,n){
        cout << a[i].first << " " << a[i].second << endl;
    }
}


Measured memory_bytes: 3592
A,B,H,M=map(int,input().split())
import math
M=M+60*H
hd=M/2
md=6*(M%60)
x=max(hd,md)-min(hd,md)
print(math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(x))))

Measured memory_bytes: 9472
#include <stdio.h>

int main(void){

  char s[101];
  int end;
  for (int i = 0; i < 101; i++) {
    scanf("%c", &s[i]);
    if (s[i] < 'a' || s[i] > 'z') {
      end = i;
      break;
    }
  }

  int hugs = 0;
  for (int i = 0; i < end/2; i++) {
    if (s[i] != s[end-1-i]) {
      hugs++;
    }
  }

  printf("%d\n", hugs);

  return 0;
}

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

int main()
{
    long long N;
    cin >> N;

    vector<long long> P(N + 1, 0);
    for (long long i = 1; i <= N; i++)
    {
        long long p;
        cin >> p;
        P[p] = i;
    }

    multiset<long long> s;
    s.insert(0);
    s.insert(0);
    s.insert(N + 1);
    s.insert(N + 1);
    long long ans = 0;
    long long n1, n2, m1, m2;
    for (long long i = N; i > 0; i--)
    {
        s.insert(P[i]);
        auto itr = s.find(P[i]);
        n1 = P[i];
        n1 += -*--itr - 1;
        n2 = *itr;
        n2 += -*--itr - 1;

        itr = s.find(P[i]);
        m1 = -P[i];
        m1 += *++itr - 1;
        m2 = -*itr;
        m2 += *++itr - 1;

        long long count = 0;
        count += (n2 + 1) * (m1 + 1) + (m2 + 1) * (n1 + 1);
        ans += i * count;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int r = sc.nextInt();

		if(n >= 10){
			System.out.println(r);
		}
		else {
			System.out.println(r + 100*(10 - n));
		}
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int a, b; cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		char[] sArray = s.toCharArray();
		Arrays.sort(sArray);

		if(sArray[0] == sArray[1] && sArray[2] == sArray[3] && sArray[1] != sArray[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}

}


Measured memory_bytes: 21844
def countingSort(a,k)
  c = [0]*(k+1)
  a.each do |ai|
    c[ai] += 1
  end
  (1..k).each do |i|
    c[i] = c[i] + c[i-1]
  end
  ans = []
  a.reverse_each do |ai|
    ans[c[ai]-1] = ai
    c[ai] -= 1
  end
  return ans
end

n = gets.to_i
a = gets.split.map(&:to_i)
ans = countingSort(a,a.max)
printf("%s\n", ans.join(" "))


Measured memory_bytes: 153868
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{
		int N = nextInt();
		int D = nextInt();


		for(int i=1;i<20;i++){
			N=N-(2*D+1);
			if(N<=0){
				System.out.println(i);
				return;
			}
		}

	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

using namespace std;

typedef pair<int, int> ii;
map<ii, int> cnt;
set<ii> s;
set<ii>::iterator it;
long long ans[10];
int main(){
	long long h, w, n;
	cin >> h >> w >> n;
	for(int i = 1; i <= n; i++){
		long long x, y;
		cin >> x >> y;
		for(int j = max(1LL, x - 2); j <= min(x, h - 2); j++){
			for(int k = max(1LL, y - 2); k <= min(y, w - 2); k++){
				cnt[ii(j, k)]++;
				s.insert(ii(j, k));
			}
		}
	}
	for(it = s.begin(); it != s.end(); it++){
		ii t = *it;
		ans[cnt[t]]++;
	}
	ans[0] = (h - 2) * (w - 2);
	for(int i = 1; i <= 9; i++)
		ans[0] -= ans[i];
	for(int i = 0; i <= 9; i++)
		cout << ans[i] << '\n';
}

Measured memory_bytes: 98688
#include<bits/stdc++.h> 
using namespace std;
int aa,bb,s;
bool one,two,none;
int main()
{
	cin >> s;
	aa = s / 100;
	bb = s % 100;
	if(aa >= 0 && bb > 0 && bb <= 12) one = true;
	if(aa > 0 && aa <= 12 && bb >= 0) two = true;
	if (one && two) cout << "AMBIGUOUS";
		else if(one) cout << "YYMM";
		else if(two) cout << "MMYY";
		else cout << "NA";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int P[100000], Y[100000];
vector<int> yd[100001];

int main() {
  int n, m;
  cin >> n >> m;
  tuple<int, int, int> data[m];
  rep(i, m) {
    int p, y;
    cin >> p >> y;
    data[i] = make_tuple(y, p, i);
  }
  sort(data, data + m);
  int cnt[n + 1] = {};
  pair<int, int> id[m];
  rep(i, m) {
    int y, p, idx;
    tie(y, p, idx) = data[i];
    ++cnt[p];
    id[idx] = make_pair(p, cnt[p]);
  }
  rep(i, m) {
    cout << setw(6) << setfill('0') << id[i].first;
    cout << setw(6) << setfill('0') << id[i].second << endl;
  }
  return 0;
}


Measured memory_bytes: 6144
N=int(input())
A=list(map(int,input().split()))
s=A[0]^A[1]
for i in range(2,N):
    s=s^A[i]

B=[0]*N
for i in range(N):
    B[i]=s^A[i]

L=[str(a) for a in B]
L=" ".join(L)
print(L)


Measured memory_bytes: 41620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#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...);
}
#else
#define trace(...)
#endif

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

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

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	int h, w;
	cin >> h >> w;
	string s[h];
	for(int i = 0; i < h; i++) {
		cin >> s[i];
	}
	int ans = -1;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			if(s[i][j] == '.') {
				for(int k = 0; k < h; k++) {
					for(int l = 0; l < w; l++) {
						if(s[k][l] == '.') {
							bool vis[h][w];
							int val[h][w];
							memset(vis, 0, sizeof(vis));
							memset(val, 0, sizeof(val));
							queue<pii> q;
							q.push({i, j});
							vis[i][j] = 1;
							while(!q.empty()) {
								int ti = q.front().fi, tj = q.front().se;
								q.pop();
								for(int tt = 0; tt < 4; tt++) {
									if(ti + dx[tt] >= 0 && ti + dx[tt] < h && tj + dy[tt] >= 0 && tj + dy[tt] < w && s[ti + dx[tt]][tj + dy[tt]] == '.' && !vis[ti + dx[tt]][tj + dy[tt]]) {
										q.push({ti + dx[tt], tj + dy[tt]});
										vis[ti + dx[tt]][tj + dy[tt]] = 1;
										val[ti + dx[tt]][tj + dy[tt]] = val[ti][tj] + 1;
									}
								}
							}
							ans = max(ans, val[k][l]);
						}
					}
				}
			}
		}
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}
	
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int d[3] = {0,0,0};
	int n; cin>>n;
	int ans=1;
	for(int i=0;i<n;i++)
	{
		int cnt=0;
		int x; cin>>x; int id=-1;
		for(int j=0;j<3;j++)
		{
			if(d[j]==x)
			{
				id=j; cnt++;
			}
		}
		if(cnt==0)
		{
			cout<<0<<'\n'; return 0;
		}
		ans=mult(ans,cnt);
		d[id]++;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        int m, h;
        while(sc.hasNext()){
            String str = sc.next();
            if(str.equals("-")) break;
               m = sc.nextInt();
            for(int i = 0; i < m; i++){
                h = sc.nextInt();
                str = str.substring(h, str.length()) + str.substring(0, h);
            }
            System.out.println(str);
        }
    }
}


Measured memory_bytes: 26252
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

LL da[100005], db[100005], d[100005];

struct edge {
	LL a, b;
	int to;
	edge(LL _a, LL _b, int _to) :a(_a), b(_b), to(_to) {};
};
using graph = vector<vector<edge> >;

int main() {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--, t--;
	graph g(n);
	REP(i, m) {
		int u, v;
		LL a, b;
		scanf("%d%d%lld%lld", &u, &v, &a, &b);
		u--, v--;
		g[u].PB(edge(a, b, v));
		g[v].PB(edge(a, b, u));
	}
	priority_queue<pair<LL, int>, vector<pair<LL, int>>, greater<pair<LL, int>> > q;
	memset(da, 0x7f, sizeof(da));
	q.push(MP(0LL, s));
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		int pos = tmp.second;
		LL cost = tmp.first;
		if (da[pos] > cost)da[pos] = cost;
		else continue;
		for (auto e : g[pos]) q.push(MP(cost + e.a, e.to));
	}
	memset(db, 0x7f, sizeof(db));
	q.push(MP(0, t));
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		int pos = tmp.second;
		LL cost = tmp.first;
		if (db[pos] > cost)db[pos] = cost;
		else continue;
		for (auto e : g[pos]) q.push(MP(cost + e.b, e.to));
	}
	REP(i, n)d[i] = da[i] + db[i];
	LL tmp = d[n - 1];
	for (int i = n - 1; i >= 0; i--) {
		if (tmp > d[i])tmp = d[i];
		d[i] = tmp;
	}
	REP(i, n) {
		printf("%lld\n", 1000000000000000LL-d[i]);
	}

	return 0;
}

Measured memory_bytes: 14576
#include<cstdio>
#include<string.h>
char a[1000],b[1000];
int main()
{    int i,n;
    scanf("%d",&n);
	scanf("%s",a);
	scanf("%s",b);
	for(i=0;i<n;i++)
	{
		printf("%c%c",a[i],b[i]);
	}
	printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define i64 unsigned long long
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll mod = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}


int pow(ll x, ll y, ll mod){
    ll ret=1;
    for(;y;y>>=1,x=1ll*x*x%mod){
        if(y&1) ret=1ll*ret*x%mod;
    }
    return ret;
}
void kill()
{
    cout << "No" << endl;
    exit(0);
}

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

void  twice(int& a){
    std::cout << a << std::endl;
    a *= 2;
    std::cout << a << std::endl;
}

ll dp[5000][5002];
char s[5010];

int main(){
    sonic();
    ll n, ss;
    scanf("%lld %s", &n, s);
    ss = strlen(s);
    dp[0][0]=1;
    dp[0][1]=2;
    REP(i,1,n)rep(j,n+1){
        if(j!=0)dp[i][j]+=dp[i-1][j-1]*2;
        else dp[i][j]+=dp[i-1][j];
        dp[i][j]+=dp[i-1][j+1];
        dp[i][j]%=mod;
    }
    co(1ll*dp[n-1][ss]*pow(pow(2,ss,mod),mod-2,mod)%mod);
}


Measured memory_bytes: 199040
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
D, X = MAP()
A = [INT() for _ in range(N)]

ans = X

for i in range(N):
	day = 0
	j = 0
	while day <= D:
		day = j*A[i] + 1
		j += 1
	ans += j-1

print(ans)

Measured memory_bytes: 5204
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    h, w = LI()
    ans = 0
    if h == 1 or w == 1:
        print(1)
        return
    x = (h + 1) // 2
    y = h // 2
    ans += (w + 1) // 2 * x
    ans += w // 2 * y
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39152
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
int main(){
    int n;sc(n);
    if (n>=30) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}



Measured memory_bytes: 3748
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef int Weight;
const Weight INF = 1e8;

struct Edge {
    int src, dst;
    Weight weight;
Edge(int f, int t, Weight c) :
    src(f), dst(t), weight(c) {}
    bool operator< (const Edge &e);
};

bool Edge::operator< (const Edge &e)
{
    return weight != e.weight ? weight > e.weight :
        src != e.src ? src < e.src : dst < e.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;


// グラフgの始点sから各頂点までの距離がdistに入る．
// 経路に負閉路が存在しないときtrue，そうでないときfalse．
// また，経路に負閉路を含む場合は，distが負の無限大となる．
// prefは最短路木の親頂点が入る
bool ShortestPath(const Graph &g, int s,
                  vector<Weight> &dist, vector<int> &prev)
{
    int n = g.size();

    dist.assign(n, INF);
    dist[s] = 0;
    prev.assign(n, -2);

    bool negative_cycle = false;
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (auto e = g[i].begin(); e != g[i].end(); ++e) {
                if (dist[e->src] != INF && dist[e->dst] > dist[e->src] + e->weight) {
                    dist[e->dst] = dist[e->src] + e->weight;
                    prev[e->dst] = e->src;
                    if (k == n - 1) {
                        dist[e->dst] = -INF;
                        negative_cycle = true;
                    }
                }
            }
        }
    }
    return !negative_cycle;
}


vector<int> BuildPath(const vector<int> &prev, int t)
{
    vector<int> path;
    for (int u = t; u >= 0; u = prev[u])
        path.push_back(u);
    reverse(path.begin(), path.end());

    return path;
}

int main()
{
    int V, E, r, s, t, d;

    cin >> V >> E >> r;
    Graph g(V);
    for (int i = 0; i < E; ++i) {
        cin >> s >> t >> d;
        g[s].push_back(Edge(s, t, d));
    }

    vector<Weight> dist;
    vector<int> prev;
    if (ShortestPath(g, r, dist, prev)) {
        for (int i = 0; i < V; ++i) {
            if (INF <= dist[i])
                cout << "INF\n";
            else
                cout << dist[i] << '\n';
        }
    }
    else {
        cout << "NEGATIVE CYCLE\n";
    }


    return 0;
}

Measured memory_bytes: 1268
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
using namespace std;
int dp[100001][3];
int main() {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
        cin >> b[i];
        cin >> c[i];
    }
    
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for (int i = 0; i < n; i ++) {
        dp[i+1][0] = max(dp[i+1][0], dp[i][1] + a[i]);
        dp[i+1][0] = max(dp[i+1][0], dp[i][2] + a[i]);

        dp[i+1][1] = max(dp[i+1][1], dp[i][0] + b[i]);
        dp[i+1][1] = max(dp[i+1][1], dp[i][2] + b[i]);

        dp[i+1][2] = max(dp[i+1][2], dp[i][0] + c[i]);
        dp[i+1][2] = max(dp[i+1][2], dp[i][1] + c[i]);
    }
    // for (int j = 0; j < 3; j ++) {
    //     for (int i = 0; i <= n; i ++) {
        
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << max(max(dp[n][0],  dp[n][1]), dp[n][2]) << endl;
}

Measured memory_bytes: 5960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a); i<(b); ++i)
typedef vector<ll> vi;
inline ll in() { ll x; cin >> x; return x; }

#define int ll
void solve() {
  int n = in(), m = in();
  vi ac(n, 0), wa(n, 0);
  FOR (i,0,m) {
    int p = in()-1;
    string s; cin >> s;
    if (ac[p]) continue;
    if (s=="AC") {
      ac[p] = 1;
    } else {
      wa[p]++;
    }
  }
  int AC = 0, WA = 0;
  FOR (i,0,n) {
    if (ac[i]) {
      AC += ac[i];
      WA += wa[i];
    }
  }

  cout << AC << " " << WA << endl;
}

#undef int
int main() {
	solve();
}

Measured memory_bytes: 1792
n, x, y = map(int, input().split())
a = [0 for i in range(n)]
for s in range(1, n): #start
    for g in range(s+1, n+1): #goal
        a[min(g-s, abs(x-s)+1+abs(g-y), abs(y-s)+1+abs(g-x))] += 1

#print(a)
for i in range(1, n):
    print(a[i])

Measured memory_bytes: 47580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    char c; cin >> c;
    int n = c -'A';
    string ans = "a";
    if(0 <= n && n < 26){
        ans = "A";
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef pair<int, int> P;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

struct T
{
  int a;
  int b;
  T(int _a, int _b)
    : a(_a)
    , b(_b)
  {}
  // default compare function for sort
  bool operator<(const T& a) const
  {
    // compare val
    return b < a.b;
  }
  friend ostream& operator<<(ostream& os, const T& a)
  {
    os << a.a << ':' << a.b;
    return os;
  }
};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N;
  cin >> N;
  vector<T> w;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    w.emplace_back(a, b);
  }
  sort(w.begin(), w.end());
  // dumpv(w);
  int t = 0;
  int ans = 0;
  for (T v : w) {
    t += v.a;
    if (v.b < t) {
      ans = 1;
      break;
    }
  }
  if (ans) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 2420
#!/usr/bin/env python

def main():
    n = int(input())
    a_arr = list(map(int, input().split()))
    mod = 10**9 + 7

    a_sum = sum(a_arr)

    ans = 0
    for i in range(n):
        a = a_arr[i]
        a_sum -= a
        ans += a * a_sum % mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 31436
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60, lmod = 1e9+7;

const int MAX_N = 100005;

int main(){
  ll N,X,ans;
  cin >> N >> X;
  ans = N;
  ll a = max(X,N-X);
  ll b = min(X,N-X);
  while(b!=0){
    if(a%b!=0LL) ans += 2*(a/b)*b;
    else ans += (2*(a/b)-1)*b;
    ll a1 = max(a%b,b);
    ll b1 = min(a%b,b);
    a = a1; b = b1;
  }
  cout << ans << endl;
  return 0;
}

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

typedef vector<int> vec;
typedef vector<vec> mat;
int maxm=0,mini=1e9;

int s[2000][2000];
int t[2000][2000];

bool check(const mat &A,int M){
  int H=A.size();
  int W=A[0].size();
  memset(s,0,sizeof(s));
  memset(t,0,sizeof(t));
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if( abs(mini-A[i][j]) > M ){
        s[i][j]=1;
      }
      if( abs(maxm-A[i][j]) > M ){
        t[i][j]=1;
      }
    }
  }
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(i+1<H)t[i+1][j]|=t[i][j];
      if(j+1<W)t[i][j+1]|=t[i][j];
    }
  }

  for(int i=H-1;i>=0;i--){
    for(int j=W-1;j>=0;j--){
      if(i-1>=0)s[i-1][j]|=s[i][j];
      if(j-1>=0)s[i][j-1]|=s[i][j];
    }
  }

  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      if(s[i][j]&&t[i][j])return false;

  return true;
}

int solve(const mat &A){
  int left=0,right=1e9,mid;
  while(left<right){
    mid=(left+right)/2;
    if(check(A,mid))right=mid;
    else left=mid+1;
  }
  return left;
}

void f1(mat &A){
  int H=A.size();
  int W=A[0].size();
  mat res(W , vec(H,0) );
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      res[W-1-j][H-1-i]=A[i][j];
    }
  }
  A=res;
}

void f2(mat &A){
  int H=A.size();
  int W=A[0].size();
  for(int i=0;i<H;i++){
    for(int j=0;j<W/2;j++){
      swap(A[i][j],A[i][W-1-j]);
    }
  }
}

int main(){
  int H,W;
  scanf("%d %d",&H,&W);
  
  mat A( H, vec(W,0) );
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      scanf("%d",&A[i][j]);
      maxm=max(maxm,A[i][j]);
      mini=min(mini,A[i][j]);
    }
  }
  
  int ans=1e9;
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      ans=min(ans,solve(A));
      if(j==0)f1(A);
    }
    if(i==0)f2(A);
  }

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

Measured memory_bytes: 80944
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}

void solve(){
    ll n;
    cin >> n;
    ll mn = inf;
    ll ans = 0;
    fo(i, n){
        ll x;
        cin >> x;
        mn = min(mn ,x);
        if(mn >= x)ans++;
    }
    ANS;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    while(TC--){
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 3756
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int[][] A = new int[1000][1000];

    public static void main(String[] args) {
        int H = ni();
        int W = ni();

        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                A[h][w] = -1;
            }
        }

        for (int h = 0; h < H; h++) {
            String astr = sc.next();
            for (int w = 0; w < W; w++) {
                if (astr.charAt(w) == '#') {
                    A[h][w] = 0;
                }
            }
        }

        // 2回累積和
        accum(H, W);
        accum(H, W);

        int ans = 0;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                ans = Math.max(ans, A[h][w]);
            }
        }

        out.println(ans);
    }

    static void accum(int H, int W) {
        // 右
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (A[h][w] != -1) {
                    w++;
                    while (w < W && (A[h][w] == -1 || A[h][w - 1] < A[h][w])) {
                        A[h][w] = A[h][w - 1] + 1;
                        w++;
                    }
                    w--;
                }
            }
        }

        // 左
        for (int h = 0; h < H; h++) {
            for (int w = W - 1; w >= 0; w--) {
                if (A[h][w] != -1) {
                    w--;
                    while (w >= 0 && (A[h][w] == -1 || A[h][w] > A[h][w + 1])) {
                        A[h][w] = A[h][w + 1] + 1;
                        w--;
                    }
                    w++;
                }
            }
        }

        // 下
        for (int w = 0; w < W; w++) {
            for (int h = 0; h < H; h++) {
                if (A[h][w] != -1) {
                    h++;
                    while (h < H && (A[h][w] == -1 || A[h - 1][w] < A[h][w])) {
                        A[h][w] = A[h - 1][w] + 1;
                        h++;
                    }
                    h--;
                }
            }
        }

        // 上
        for (int w = 0; w < W; w++) {
            for (int h = H - 1; h >= 0; h--) {
                if (A[h][w] != -1) {
                    h--;
                    while (h >= 0 && (A[h][w] == -1 || A[h][w] > A[h + 1][w])) {
                        A[h][w] = A[h + 1][w] + 1;
                        h--;
                    }
                    h++;
                }
            }
        }
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

Measured memory_bytes: 33184