akhauriyash/Code-Regression huggingface dataset:
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
D = [tuple(map(int, input().split())) for _ in range(N)]

for i in range(N):
    for j in range(i, i + 3):
        if j >= N:
            break
        a, b = D[j]
        if a != b:
            break
    else:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 67196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <bitset>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

int main() {
	int N, M, X;
	cin >> N >> M >> X;
	vector <int>C(N);
	vector <vector<int>> A(N, vector<int>(M));
	for(int i = 0; i < N; i++) {
		cin >> C.at(i);
		for (int j = 0; j < M; j++) {
			cin >> A.at(i).at(j);
		}
	}

	int ans = 1001001001;
	for (int i = 0; i < (1 << N); i++){
		bitset<12> s(i);
		int money = 0;
		vector <int> u(M, 0);
		for (int i = 0; i < N; i++) {
			if (s.test(i)) {
				money += C.at(i);
				for(int j = 0; j < M; j++) {
					u.at(j) += A.at(i).at(j);
				}
			}
		}

		bool flag = true;
		for (int i = 0; i < M; i++) {
			if (u.at(i) < X) {
				flag = false;
			}
		}
		if (flag) {
			ans = min(ans, money);
		}
	}

	if (ans == 1001001001) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 3636
N=int(input())
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
s=[A,B,C,D,E]
a=[1,1,1,1,1]
a2=[0,0,0,0,0]
if(A<N):
    a[0]=-(-N // A)
mn=A
if(B<mn):
    mn=B
    a[1]=-(-N // B)
    if(a[0]>1):
        a[0]=1
if(C<mn):
    mn=C
    a[2]=-(-N // C)
    for i in range(0,2):
        if(a[i]>1):
            a[i]=1
if(D<mn):
    mn=D
    a[3]=-(-N // D)
    for i in range(0,3):
        if(a[i]>1):
            a[i]=1
if(E<mn):
    mn=E
    a[4]=-(-N // E)
    for i in range(0,4):
        if(a[i]>1):
            a[i]=1
time=a[0]+a[1]+a[2]+a[3]+a[4]
print(time)

Measured memory_bytes: 3064
/*
problem's name:
statue:
writer:Patrick_y
*/
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <cctype>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=20050208;
/*------------main part------------*/



char maze[100][100];
int main()
{
	int n,m;
	cin>>m>>n;
	n--,m--;
	for(int i=0;i<50;i++)
	{
		for(int j=0;j<100;j++)
		{
			maze[i][j]='.';
		}
	}
	for(int i=50;i<100;i++)
	{
		for(int j=0;j<100;j++)
		{
			maze[i][j]='#';
		}
	}
	for(int i=0;i<50;i++)
	{
		if(n==0)
			break; 
		for(int j=0;j<100;j++)
		{
			if(i>=2 and j>=1 and maze[i-2][j]=='#' and maze[i][j-1]!='#' or i==0 and j>=1 and maze[i][j-1]!='#')
			{
				maze[i][j]='#';
				n--;
				if(n==0)
					break;
			}
		}
		if(n==0)
			break;
	}
	for(int i=50;i<100;i++)
	{
		if(m==0)
			break;
		for(int j=0;j<100;j++)
		{
			if(maze[i-2][j]=='.' and maze[i][j-1]!='.'  and i>50)
			{
				maze[i][j]='.';
				m--;
				if(m==0)
					break;
			}
		}
		if(m==0)
			break;
	}
	cout<<100<<" "<<100<<endl;
	for(int i=0;i<100;i++)
	{
		for(int j=0;j<100;j++)
		{
			cout<<maze[i][j];
		}
		cout<<endl;
	}
	return 0;
}


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

using namespace std;

int main() {
    int n, p;

    for (;;) {
        cin >> n >> p;
        if (n == 0 && p == 0) break;

        vector<int> vi(n, 0);
        int i = 0;
        for (;;) {
            if (p > 0) {
                vi[i]++;
                p--;
            } else {
                bool win = true;
                for (int j = 0; j < n; j++) {
                    if (i == j) continue;
                    if (vi[j] > 0) win = false;
                }

                if (win) {
                    cout << i << endl;
                    break;
                } else {
                    p += vi[i];
                    vi[i] = 0;
                }
            }

            i = (i + 1) % n;
        }
    }
}

Measured memory_bytes: 1192
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}



int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a);
	int c=0;
	int x;
	vector<int> b;
	rep(i, n) {
		if (i == 0) {
			x = a[i];
			c++;
		}
		else {
			if (x == a[i]) {
				c++;
			}
			else {
				if (c > 1) {
					rep(j, c - 1) {
						b.push_back(x);
					}
				}

				c = 1;
				x = a[i];
			}
		}
	}
	if (c > 1) {
		rep(j, c - 1) {
			b.push_back(x);
		}
	}
	int bs = b.size();
	if (bs == 0) {
		cout << n << endl;
		return 0;
	}
	if (bs % 2 == 1) {
		cout << n - bs - 1 << endl;
	}
	else {
		cout << n - bs << endl;
	}
}




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

namespace ABC047A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            if (a + b == c || a + c == b || b + c == a)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

            Console.ReadKey();



        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>

const int nax = 5e5+5;
typedef unsigned long long ull; 
unsigned long long arr[nax];

void bfs(int start, int depth, int &idx) {
	std::queue<ull> Q;
	Q.push(start);
	ull pr;
	start = idx;
	while (idx-start<=depth) {
//		std::cout << "hello\n";
		pr = Q.front(); Q.pop();
//		std::cout << pr << " ";
		arr[idx++] = pr;
		if (pr%10!=0) { Q.push(10*pr+(pr)%10-1); }
		Q.push(10*pr+(pr%10));
		if (pr%10!=9) { Q.push(10*pr+(pr)%10+1); }	
	}
}

int main() {

	//std::cout << isConflict(1020) << "\n";

	int K;
	std::cin >> K;
	int idx = 0;
	std::fill(arr, arr+nax, (ull)1e17);
	for (int i=1; i<=9; i++) {
		bfs(i, 5e4, idx);
	}
	std::sort(arr, arr+nax);
	std::cout << arr[K-1] << "\n"; 

	return 0;
}


Measured memory_bytes: 4984
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program{
    static void Main(){
        string[] inputs = Console.ReadLine().Split(' ');
        int x = int.Parse(inputs[0]);
        int y = int.Parse(inputs[1]);
        Console.WriteLine(Gcd(x, y));
    }

    static int Gcd(int x, int y){
        int larger, smaller;
        if(x >= y){
            larger = x;
            smaller = y;
        }
        else{
            larger = y;
            smaller = x;
        }
        while(larger % smaller != 0){
            int tmp = smaller;
            smaller = larger % smaller;
            larger = tmp;
        }
        return smaller;
    }
}

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

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

		for (int i = 0; i < 3000; i++) {

			String line = sc.nextLine();
			String[] kazu = line.split(" ");
			int x = Integer.parseInt(kazu[0]);
			int y = Integer.parseInt(kazu[1]);
			if (x == y && x == 0) {
				break;
			} else if (x < y) {
				System.out.println(x + " " + y);

			} else {
				System.out.println(y + " " + x);

			}

		}

	}

}



Measured memory_bytes: 34908
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = rs()
count = 0
n = len(s)
t = s[::-1]
for i in range(n // 2):
    if s[i] != t[i]:
        count += 1
print(count)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n;
	scanf("%lld",&n);
	long long int arr[n],dp[n][n],i,j,k,l,temp,sum[n];
    for(i=0;i<n;i++)
    	scanf("%lld",&arr[i]);
    sum[0]=arr[0];
    for(i=1;i<n;i++)
    	sum[i]=sum[i-1]+arr[i];
	for(i=0;i<n;i++)
			dp[i][i]=0;
	for(l=2;l<=n;l++)
	{
		for(i=0;i<=n-l;i++)
		{
			j=i+l-1;
			dp[i][j]=100000000000000007;
          for(k=i;k<=j;k++)
          {
            if(i!=0)
            temp=dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1];
            else
            temp=dp[i][k]+dp[k+1][j]+sum[j];
            if(temp<dp[i][j])
            	dp[i][j]=temp;
          }

		}
	}
    printf("%lld\n",dp[0][n-1]);
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int total(int,int,int,int);
void nogo(int);
void call(int);
int a[100];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int k=n-1;k>0;k--){
		if(k!=0){
			cout<<a[k]<<" ";
		}
	}
	cout<<a[0]<<endl;
}
int total(int a,int b,int c,int d){
	int sum=a+b+c+d;
	return sum;
}
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}
void nogo(int n){
	int x;
	for(int i=1;i<=n;i++){
		x=i;
		if(x%3==0){
			cout<<" "<<i;
		}
		else{
			while(true){
				if(x%10==3){
					cout<<" "<<i;
					break;
				}
				x/=10;
				if(x==0){
					break;
				}
			}
		}
	}
	cout<<endl;
}



Measured memory_bytes: 3100
//Drawing Lots ?
#include<bits/stdc++.h>
using namespace std;

vector<int> mv(string s){
  vector<int> tmp;
  for(int i=0; i<s.length(); i++)
    tmp.push_back(s[i]);
  return tmp;
}

int main(){
  int n, m, g, d;
  vector<vector<int> > input;
  while(cin>>n){
    if(n==0)break;
    cin>>m>>g>>d;
    input.clear();
    for(int i=0; i<d; i++){
      string s;
      cin>>s;
      input.push_back(mv(s));
    }
    vector<int> content;
    for(int i=0; i<d; i++){content.push_back(i+1);}
    for(int i=0; i<d; i++){
      for(int j=0; j<input[i].size(); j++){
        if(input[i][j]=='1')swap(content[j], content[j+1]);
      }
    }
    if(m==content[g-1]){cout<<"0"<<endl; continue;}

    int gg=content[g-1];
    content.clear();
    for(int i=0; i<d; i++){content.push_back(i+1);}
    for(int i=0; i<d; i++){
      for(int j=0; j<n-1; j++){
        if(input[i][j]=='1')swap(content[j], content[j+1]);
        else if((0<=j-1 ? input[i][j-1]=='0' : true)&&(j+1<n-1 ? input[i][j+1]=='0' : true)){
          if((content[j]==m&&content[j+1]==gg)||(content[j]==gg&&content[j+1]==m)){
            cout<<i+1<<" "<<j+1<<endl;
            goto CONTINUE;
          }
        }
      }
    }
    cout<<"1"<<endl;
  CONTINUE:
    ;
  }
  return 0;
}

Measured memory_bytes: 1236
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)1000000007

int main(void)
{
	char s[2000], t[2000];
	int ans = 1e9;
	scanf("%s %s", s + 1, t + 1);
	int ss = strlen(s + 1), ts = strlen(t + 1);

	for (int i = 1; i <= ss - ts + 1; i++)
	{
		int temp = 0;
		char cmp[2000];
		strncpy(cmp + 1, s + i, ts);
		cmp[ts + 1] = 0;
		for (int i = 1; i <= ts; i++)
			if (cmp[i] != t[i])
				temp++;
		ans = min(ans, temp);
	}

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

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

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

    struct Sushi {
        ll t, d;
    };
    vector<Sushi> sushis(N);
    for (ll i = 0; i < N; i++) {
        cin >> sushis[i].t >> sushis[i].d;
        sushis[i].t--;
    }

    sort(sushis.begin(), sushis.end(), [&](Sushi& lhs, Sushi& rhs){
       return lhs.d > rhs.d;
    });

    vector<bool> appear(N, false);
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    ll base = 0;
    ll type_num = 0;
    for (ll i = 0; i < K; i++) {
        base += sushis[i].d;
        if (appear[sushis[i].t]) {
            pq.push(sushis[i].d);
        } else {
            appear[sushis[i].t] = true;
            type_num++;
        }
    }
    ll ans = base + type_num * type_num;

    for (ll i = K; i < N && !pq.empty(); i++) {
        if (appear[sushis[i].t]) {
            continue;
        }

        ll t = pq.top();
        pq.pop();
        base += sushis[i].d - t;
        type_num++;
        ans = max(ans, base + type_num * type_num);
        appear[sushis[i].t] = true;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2432
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
#include<math.h>
using namespace std;

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

typedef long long ll;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;

const ll INF = ll(1e18) + 1;

//--------------------------------------------------

ulli gcd(ulli a, ulli b) {
	return (b <= 0) ? a : gcd(b, a % b);
}

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

bool isPrime(int n)
{
	if (n <= 3)return n > 1;
	if (n % 2 == 0)return false;
	if (n % 3 == 0)return false;
	for (int i = 5; i * i < n; i += 6) {
		if (n % i == 0 || n % (i + 2) == 0) { return false; }
	}
	return true;
}
//---------------------------------------------------


void Main()
{
	int n, r;
	cin >> n >> r;
	int ans = (n >= 10) ? r : r + (100 * (10 - n));
	cout << ans << endl;

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

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

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	ll n, m;
	cin >> n >> m;
	cout << abs(n - 2)*abs(m - 2) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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



int N, M;
int p[110000];
ll y[110000];
vector<ll> v[110000];

int main () {
  cin >> N >> M;
  rep(i, M) {
    cin >> p[i] >> y[i];

    v[p[i]].push_back(y[i]);
  }

  Rep(i, 110000) {
    sort(All(v[i]));
  }

  rep(i, M) {
    auto itr = upper_bound(All(v[p[i]]), y[i]);

    int n = itr - v[p[i]].begin();

    printf("%06d%06d\n", p[i], n);
  }
}

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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

#define SLEN 10
char S[SLEN+1];
int slen{};
bool P[SLEN];

int main() {
  scanf("%s", S);
  for (; slen < SLEN && S[slen]; ++slen);

  long total{};
  for (int i{0}; i < (1 << (MIN(slen, SLEN)-1)); ++i) {
    long temp = S[0] & 0xF;
    for (int j{0}; j < MIN(slen, SLEN)-1; ++j) {
      if (i & (1 << j)) {
        total += temp;
        temp = 0;
      }
      temp *= 10;
      temp += S[j+1] &0xF;
    }
    total += temp;
  }

  printf("%ld\n", total);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define inf 1000000007
using namespace	std;
int main(){

  long long m,n,result=1;

  cin>>m>>n;

  while(n!=1){
    if(n%2) result=(result*m)%inf;
    m=(m*m)%inf;
    n/=2;
  }

  cout<<(result*m)%inf<<endl;

  return 0;

}

Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 20

int w, h;
char field[MAX_SIZE][MAX_SIZE + 1];

int out(int x, int y) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

int dfs(int x, int y) {
	static const int dx[] = {1, 0, -1, 0};
	static const int dy[] = {0, 1, 0, -1};

	int count = 1;
	int dir;

	field[y][x] = '#';

	for(dir = 0; dir < 4; ++dir) {
		const int nx = x + dx[dir];
		const int ny = y + dy[dir];

		if(out(nx, ny) || field[ny][nx] == '#') continue;
		count += dfs(nx, ny);
	}

	return count;
}

int main() {
	while(scanf("%d %d", &w, &h) == 2 && w) {
		int x, y;
		int sx, sy;

		for(y = 0; y < h; ++y) {
			scanf("%s", field[y]);

			for(x = 0; x < w; ++x) {
				if(field[y][x] == '@') {
					sx = x;
					sy = y;
					break;
				}
			}
		}

		printf("%d\n", dfs(sx, sy));
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 620
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

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

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}

int main() {
	ll x,y,z;
	cin >> x >> y >> z;
	
	swap(x,y);
	swap(x,z);

	cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
/*
ID:xmydada1
LANG:C++
TASK:
*/
#include<bits/stdc++.h>
#define reg register

using namespace std;
const int N=2e5+7;
int m,n,ans=0,sum=0,p,q;
int a[N],b[N];
inline int read() {
reg int s = 0, t = 0; reg char ch = getchar();
while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return t ? -s : s;
}

inline void print(reg long long x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
int main()
{
//	freopen("triangle.in","r",stdin);
//	freopen("triangle.out","w",stdout);
	n=read();n=n*2-1;
	for(int i=1;i<=n;i++)a[i]=read();
	int l=0,r=1e9+7;
	while(l<=r)
	{
		int mid=l+r>>1;
		for(int i=1;i<=n;i++)
		{  
			if(a[i]>mid)b[i]=1;
			else b[i]=0;
		}
		b[n+1]=b[n];
		b[0]=b[1];
		p=0;
		for(int i=1;i<=n+1;i++)
		{
			if(b[i-1]!=b[i]){p++;}
			if(b[i-1]==b[i]&&p)
			{
				if(p%2==0)for(int j=i-p;j<=i-1;j++)b[j]=b[i];
				else 
				{
					q=p>>1;
					for(int j=i-p;j<=i-q-2;j++)b[j]=b[i-p-1];
					for(int j=i-q-1;j<=i-1;j++)b[j]=b[i];	
				}
				p=0;
			}
		}
		
		if(b[n/2+1]){l=mid+1;}
		else {r=mid-1;ans=mid;}
		memset(b,0,sizeof(b));
	}
	printf("%d",ans);

return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
int dp[100000][3];
int rec(int mat[][3],int n,int p,int r)
{
	if(r>=n)
		return 0;
	
	int mx=0;
	for(int i=0;i<3;i++)
	{
		if(dp[r][i]==-1)
			dp[r][i]=rec(mat,n,i,r+1)+mat[r][i];
		if(i!=p)
			mx=max(mx,dp[r][i]);
	}
	return mx;
	
}
int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	ll T=1;
//	cin>>T;
	while(T--)
	{
		int a,b,c,d,e;
		cin>>a>>b>>c>>d>>e;
		if(a==0)
			cout<<1<<endl;
		else if(b==0)
			cout<<2<<endl;
		else if(c==0)
			cout<<3<<endl;
		else if(d==0)
			cout<<4<<endl;
		else cout<<5<<endl;
		
		
		
	
	}
	return 0;
}





Measured memory_bytes: 3608
use proconio::{fastout, input};
use std::cmp::min;

#[fastout]
fn main() {
    input! {in_n: usize, in_a: [u64; in_n + 1]};
    let mut leaves = vec![0 as u64; in_n + 1];
    let depth = in_n + 1;

    if in_a[0] == 1 && in_n == 0 {
        println!("1");
        return;
    }

    if in_a[0] != 0 {
        println!("-1");
        return;
    }

    for i in (1..depth).rev() {
        leaves[i - 1] = leaves[i] + in_a[i];
    }

    let mut node = 1;
    let mut total = 1;

    for i in 1..depth {
        let n = node * 2;

        if in_a[i] > n {
            println!("-1");
            return;
        }

        let r = min(n - in_a[i], leaves[i]);
        total += in_a[i] + r;
        node = r;
    }

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


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  // vector<vector<int>> v(n, vector<int> (n-1));
  int v[1010][1010];
  rep(i, n) rep(j, n-1){
    cin >> v[i][j];
    v[i][j]--;
  }
  // vector<int> index(n, 0);
  int index[1010];

  for (int i = 1; i <= ((n-1) * n) / 2; i++) {
    vector<bool> battled(n, false);
    // bool battled[1010];
    // rep(j, 1010) battled[j] = false;
    // cout << "===" << endl;
    // cout << i << endl;
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if(index[j] >= n-1) continue;
      int enemy = v[j][index[j]];
      if(index[j] >= n-1 || index[enemy] >= n-1) continue;
      if(v[enemy][index[enemy]] == j && !battled[j] && !battled[enemy]){
        flag = false;
        battled[j] = true;
        battled[enemy] = true;
        index[enemy]++;
        index[j]++;
      }
    }
    if(flag) break;

    flag = true;
    rep(j, n){
      if(index[j] < n-1) {
        flag = false;
        break;
      }
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define WA cout<<"char134217728";exit(0)
#define RE throw
#define TLE sleep(1000)
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2e5+1;
int n, c, p, s[N], t=1;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> c;
    if(p==c) continue;
    p = c;
    t = s[c] = (s[c]+t) % MOD;
  }
  cout << t << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int r;
  cin >> r;
  if (r<1200) {
    cout << "ABC" << endl;
  } else if(r<2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
#define ll long long int
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define make_pair
#define rep(i,l,r) for(i=l;i<r;i++)
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
int main()
{
    io;
    int i,j,l,n,k;
    cin>>n>>k;
    vector<int>v(n);
    vector<int>pos;
    vector<int>pre(n);
    rep(i,0,n)
    cin>>v[i];
    pre[0]=v[0];
    rep(i,1,n)
    pre[i]=pre[i-1]+v[i];
    int maxi=0;
    int sum;
    rep(i,1,min(k+1,n+1))
    {
       for(j=i-1;j>=-1;j--)
       {
           vector<int>neg;
           if(j==i-1)
            sum=pre[j];
           else if(j>=0)
           sum=pre[j]+pre[n-1]-pre[n-i+j+1]+v[n-i+j+1];
           else
            sum=pre[n-1]-pre[n-i]+v[n-i];
           for(l=0;l<=j;l++)
            if(v[l]<0)
            neg.pb(v[l]);
           for(l=n-1;l>=n-i+j+1;l--)
            if(v[l]<0)
            neg.pb(v[l]);
            sort(neg.begin(),neg.end());
            for(l=0;l<min(k-i,int(neg.size()));l++)
                sum-=neg[l];
                //cout<<sum<<"\n";
            maxi=max(maxi,sum);
       }
    }
    cout<<maxi;
    return 0;
}


Measured memory_bytes: 256
fun main(args:Array<String>) {
    val num = readLine()!!.split(" ").map { it.toInt() }
    val vote = readLine()!!.split(" ").map { it.toInt() }
    var Bool = true
    val n = vote.sortedDescending()
    for (i in 1..num[1]) {
        if (n[i-1]*(4*num[1]) < n.sum()) {
            Bool = false
        }
    }
    if (Bool) {
        "Yes"
    } else {
        "No"
    }.let { println(it) }
}

Measured memory_bytes: 38008
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


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

int main(){
    int n;
    ll d, a;
    cin >> n >> d >> a;
    vector<P> p(n);
    rep(i, n) {
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    d = d*2;
    ll tot = 0;
    queue<pair<ll, ll>> q;
    ll ans = 0;
    rep(i, n) {
        ll x = p[i].first;
        ll h = p[i].second;
        while(q.size() && q.front().first < x) {
            tot -= q.front().second;
            q.pop();
        }
        h -= tot;
        if (h > 0) {
            ll num = (h+a-1)/a;
            ans += num;
            ll damage = num*a;
            tot += damage;
            q.emplace(x+d, damage);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long A, B, C, D;
    cin >> A >> B >> C >> D;

    long long CD = (C * D) / __gcd(C, D);
    long long AmodC = (A - 1) / C;
    long long AmodD = (A - 1) / D;
    long long AmodDC = (A - 1) / CD;
    long long BmodC = B / C;
    long long BmodD = B / D;
    long long BmodDC = B / CD;
    cout << (B - A + 1) - ((BmodC + BmodD - BmodDC) - (AmodC + AmodD - AmodDC)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 922337203685477580
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll c=power(a,b/2);
	if(b%2==0)
		return ((c%mod)*(c%mod))%mod;
	else
		return ((((c%mod)*(c%mod))%mod)*a)%mod;
}
ll dp[100005][2];
ll a[105];
ll n,k;
ll func(ll i,ll ch)
{
	if(dp[i][ch]!=-1)
		return dp[i][ch];
	ll ans=1-ch;
	for(ll j=0; j<n; j++)
	{
		if(i-a[j]>=0 && func(i-a[j],1-ch)==ch)
		{
			ans=ch;
		}
	}
	return dp[i][ch]=ans;
}
int main()
{
	boost
	cin>>n>>k;
	ll i;
	for(i=0; i<100005; i++)
	{
		dp[i][0]=-1;
		dp[i][1]=-1;
	}
	for(i=0; i<n; i++)
		cin>>a[i];
	ll ans=func(k,0);
	if(ans==0)
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  string S1, S2; cin >> S1 >> S2;
  vector<int> t;
  char last = '0';
  int cnt = 1;
  ll ans = 1;
  rep(i,N){
    if(last != S1[i]){
      cnt = 1;
      t.pb(cnt);
      last = S1[i];
    }
    else{
      t.back()++;
    }
  }
  // for(auto x:t) cout << x << endl;
  rep(i,(int)t.size()){
    if(i==0){
      if(t[i] == 2) ans *= 2;
      continue;
    }
    if(t[i] == 1 && t[i-1] == 1){
      ans *= 2;
    }
    else if(t[i] == 1 && t[i-1] == 2){
      ans *= 1;
    }
    else if(t[i] == 2 && t[i-1] == 1){
      ans *= 2;
    }
    else {
      ans *= 3;
    }
    ans %= mod;
  }
  cout << (ans * 3) % mod << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
typedef pair<int, int> P;

char c[1010][1010];
int d[1010][1010];
int n,m;

int bfs(){
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    int gx,gy;

    queue<P> que;

    for(int i = 0 ; i < n ; i++){
        for(int j = 0; j < m ; j++){
            
            if(c[i][j] == '#'){
                que.push(P(i,j));
                d[i][j] = 0;
            }else{
                d[i][j] = INF;
            }
        }
    }


    while(!que.empty()){
        P p = que.front();
        que.pop();

        for(int i = 0 ; i < 4 ; i++){
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];

            if(nx>=0&&ny>=0&&nx<n&&ny<m&&c[nx][ny] != '#'&&d[nx][ny] == INF){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
                gx = nx;gy = ny;
            }
        }
    }
    return d[gx][gy];
}



int main(){

    cin >> n >> m;
    
    for(int i = 0; i < n ; i++){
        for(int j = 0; j < m ; j++){
            cin >> c[i][j];
        }
    }

    int ans = bfs();

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

Measured memory_bytes: 13456
MOD=10**9+7
n,k=gets.split.map(&:to_i)
sum=0

k.upto(n+1) do |i|
    max=(n+n-i+1)*i/2
    min=(i-1)*i/2
    sum+=max-min+1 
    #p max,min,sum,""
end

p sum%MOD

Measured memory_bytes: 14332
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>   
#include <functional>

#define lnd '\n'
#define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mkp make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

void solution();

template <class T>
T GCD (T a, T b) {
  if(b == 0) return a;
  return GCD(b, a%b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
    int n;
    cin >> n;
    int mn = 0;
    int count = 0;
    from(i, n){
        int p;
        cin >> p;
        if(i == 0){
            mn = p;
            count++;
        }else{
            if(p <= mn) count++;
            mn = min(mn, p);
        }
        
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring> 
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main() {
  string S;
  cin >> S;

  string T;
  cin >> T;

  int q;
  cin >> q;
  
  int score1=0;
  vector<int> count1;
  count1.push_back(score1);
  for ( int I=0 ; I<S.length(); ++I ) {
    score1 += (S[I]=='A')? 1 : 2;
    count1.push_back(score1);
  }

  int score2=0;
  vector<int> count2;
  count2.push_back(score2);
  for ( int I=0 ; I<T.length(); ++I ) {
    score2 += (T[I]=='A')? 1 : 2;
    count2.push_back(score2);
  }

  for ( int I=0 ; I<q; ++I ) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int s1 = count1[a-1];
    int e1 = count1[b];
    int s2 = count2[c-1];
    int e2 = count2[d];
    int score1 = e1 - s1; 
    int score2 = e2 - s2;
    cout<< ( ( score1 % 3 == score2 % 3 )? "YES" : "NO") << endl; 
  }


} 

Measured memory_bytes: 1788
#include <cstdio>
typedef long long lld;
const int BASE = 5;
const int LOGN = 26;
lld N;

lld solve() {
  if (N & 1) return 0;
  lld mul = 2;
  lld ret = 0LL;
  for (int i = 1; i <= LOGN; ++i) {
    mul *= BASE;
    ret += N / mul;
  }
  return ret;
}

int main() {
  scanf("%lld", &N);
  printf("%lld\n", solve());
  return 0;
}

Measured memory_bytes: 256
def main():
    n=int(input())
    slp=[list(map(int,input().split())) for _ in [0]*n]
    m=int(input())
    W=[int(input()) for _ in [0]*m]
    ans=[]
    
    point=[0]*393
    for s,l,p in slp:
        for i in range(s,l+1):
            point[i-1]=max(point[i-1],p)
    
    memo=[0]*(394)
    for i in range(393):
        for l,p in enumerate(point[:393-i]):
            memo[i+l+1]=max(memo[i+l+1],memo[i]+p)
    
    for w in W:
        ans.append(memo[w])
    if 0 in ans:
        print(-1)
    else:
        for i in ans:
            print(i)
if __name__ == '__main__':
    main()


Measured memory_bytes: 5672
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;

int main(void){
	int n;
	cin>>n;
	int num=0;
	rep(i,n){
		int tmp;
		cin>>tmp;
		if(i+1 != tmp)num++;
	}
	if(num==0 || num==2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

const int N = 1e5; 

int a[N + 5], b[N + 5]; 
int n, m, p; 

int main() {

    scanf("%d%d%d", &n, &m, &p); 
    for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
    for (int i = 1; i <= m; i ++) scanf("%d", &b[i]); 

    int mi, sum = 0; 
    mi = a[1]; 
    for (int i = 1; i <= n; i ++) mi = std::min(mi, a[i]);
    sum += mi; mi = b[1]; 
    for (int i = 1; i <= m; i ++) mi = std::min(mi, b[i]);
    sum += mi; 

    for (int i = 1; i <= p; i ++) {
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z); 
        sum = std::min(sum, a[x] + b[y] - z); 
    }

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

    return 0;
}

Measured memory_bytes: 896
n, m = map(int, input().split())

p, s = [], []
result = [0] * (n + 1)
wa = [0] * (n + 1)

for _ in range(m):
    tmpp, tmps = map(str, input().split())
    p.append(int(tmpp)), s.append(tmps)

for i in range(m):
    if result[p[i]] == 0:
        if s[i] == "AC":
            result[p[i]] = 1

        else:
            wa[p[i]] += 1

ac = sum(result)
wa = sum(wa[i] for i in range(n + 1) if result[i] == 1)

print(ac, wa)


Measured memory_bytes: 14972
#include <iostream>
using namespace std;
int n,m;
int r[100005];
int l[100005];
int main(){
	cin>>n>>m;
	int maxl=0,minr=99999999;
	for(int i=1;i<=m;i++){
		cin>>l[i]>>r[i];
		maxl=max(maxl,l[i]);
		minr=min(minr,r[i]);
	}
	cout<<max(minr-maxl+1,0);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
string A[105],B[105];
int n,m;
int main(){
	cin>>n>>m;
	int xb,x2,x3,x4;
	for(xb=0;xb<n;xb++) cin>>A[xb];
	for(xb=0;xb<m;xb++) cin>>B[xb];
	for(xb=0;xb<n;xb++){
		for(x2=0;x2<n;x2++){
			if(xb+m-1<n && x2+m-1<n){
				bool fail=0;
				for(x3=xb;!fail && x3<=xb+m-1;x3++){
					for(x4=x2;!fail && x4<=x2+m-1;x4++){
						if(A[x3][x4]!=B[x3-xb][x4-x2]) fail=1;
					}
				}
				if(!fail){
					cout<<"Yes\n";
					return 0;
				}
			}
		}
	}
	cout<<"No\n";
	return 0;
}

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

using namespace std;

bitset<1000000> b;
vector<int> primes;

void sieve(long long upto)
{
    b.set();
    b[0] = 0;
    b[1] = 0;
    primes.push_back(2);
	for (long long i = 3; i <= upto + 1; i += 2) {
        if (b[i]) {
            for (long long j = i * i; j <= upto + 1; j += i) {
                b[j] = 0;
            }
            primes.push_back(i);
        }
	}
}

int main()
{
	sieve(1000000);
    int n;
	cin >> n;
	auto it = lower_bound(primes.begin(), primes.end(), n);
	cout << *it << endl;
	return 0;
}



Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)

int main(){
    char str[4];
    bool a,b,c;
    a = false;
    b = false;
    c = false;

    scanf("%s",str);
    
    REPI(3){
        if(str[i]=='a')
            a = true;
        if(str[i]=='b')
            b = true;
        if(str[i]=='c')
            c = true;
    }
    
    if(a&b&c == true)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    string s;
    cin >> s;
    int n = s.length() + 1;
    int ans = 0;
    int A[n] = {};
    if(s[0] == '<'){
        int tmp = 1;
        REP(i,n-1){
            if(s[i] == '>') break;
            A[i] = tmp;
            tmp ++;
            A[i + 1] = tmp;
        }
    }
    REP(i,n-2){
        if(s[i] == '>' and s[i + 1] == '<'){
            A[i + 1] = 1;
            int tmp = 2;
            int id = i;
            while(id >= 0 and s[id] == '>'){
                chmax(A[id], tmp);
                id --;
                tmp ++;
            }
            // if(id == 0 and s[0] == '>') A[0] = tmp;

            tmp = 2;
            id = i + 1;
            while(id <= n- 1 and s[id] == '<'){
                chmax(A[id + 1], tmp);
                tmp ++;
                id ++;
            } 

        }
    }
    int tmp = 1;
    REPR(i,n-1){
        if( s[i-1] == '<'){
            chmax(A[i],tmp);
            break;
        }
        chmax(A[i ],tmp);
        tmp ++;
    }

    ans = 0;
    REP(i,n) ans += A[i];
    cout << ans - n<< endl;


}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll N,X;
ll a[51],p[51]; // a: 層の総数, p: パティの総数

ll solve(ll n, ll x) {
  if (n==0) return x>0 ? 1 : 0;

  if (x <= 1 + a[n-1]) return solve(n-1,x-1);

  return p[n-1] + 1 + solve(n-1,x-2-a[n-1]);
}

int main() {
  cin >> N >> X;
  a[0] = 1; p[0] = 1;
  for(int i = 1; i < N; i++) {
    a[i] = a[i-1]*2+3;
    p[i] = p[i-1]*2+1;
  }
  COUT(solve(N,X));
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

class UnionFind(object):
    def __init__(self, n):
        self._par = list(range(n))
        self.size = [1] * n
 
    def root(self, v):
        if self._par[v] == v:
            return v
        self._par[v] = self.root(self._par[v])
        return self._par[v]
 
    def unite(self, u, v):
        u, v = self.root(u), self.root(v)
        if u == v:
            return False
        if self.size[u] > self.size[v]:
            u, v = v, u # size[u] <= size[v]
        self.size[v] += self.size[u]
        self._par[u] = v
 
    def same(self, u, v):
        return self.root(u) == self.root(v)

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

ans = 0
for i in range(n):
    ans = max(ans, uf.size[uf.root(i)])

print(ans)

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

int main(){
  int N,A,B,num = 0,total = 0;
  cin >> N >> A >> B;
  
  for(int i = 1;i <= N;i++){
    
    num = 0;
    int a = i;
    
    while(a > 0){
      num += a % 10;
      a = a / 10;
    }
    
    if(num >= A && num <= B){
      total += i;
    }
  }
  
  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priotity_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
int n,k,pos=1;

int main(){
	cin >> n >> k;
	REP(i,0,n) pos=min(2*pos,pos+k);
	cout << pos << endl;
	return 0;
}


Measured memory_bytes: 256
a = [list(map(int, input().split())) for _ in range(3)]
a = a[0] + a[1] + a[2]
c = [
        a[0:3], a[3:6], a[6:9], a[::3], a[1::3], a[2::3],
        [a[0], a[4], a[8]], [a[2], a[4], a[6]]
    ]
n = int(input())
b = [int(input()) for _ in range(n)]


same = set(a) & set(b)

for d in c:
    cnt = 0
    for n in same:
        if n in d:
            cnt += 1
    if cnt == 3:
        print("Yes")
        exit()
else:
    print("No")


Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    int n;
    cin >> n;
    int x[n], y[n];
    rep (i, n) cin >> x[i] >> y[i];

    vector<int> nums;
    rep (i, n) nums.pb(i);

    int kaijo = 1;
    rrep (i, n) kaijo *= i;

    double ans = 0;
    do {
        for (int i = 1; i < n; i++) {
            int tmpX = x[nums[i]] - x[nums[i - 1]];
            int tmpY = y[nums[i]] - y[nums[i - 1]];
            ans += sqrt(tmpX * tmpX + tmpY * tmpY);
        }
    } while (next_permutation(rng(nums)));

    ans /= kaijo;

    printd(ans);
    return 0;
}

Measured memory_bytes: 256