akhauriyash/Code-Regression huggingface dataset:
import sys
import operator
N = int(input())
tasks = []
time = 0
ans = "Yes"

for cmd in sys.stdin:
  a,b = map(int, cmd.strip("\n").split())
  tasks.append([a,b])
tasks.sort(key=operator.itemgetter(1))

for task in tasks:
  time += task[0]
  deadline = task[1]
  if time > deadline:
    ans = "No"
    break

print(ans)

Measured memory_bytes: 38088
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    cnt_BA = cnt_A = cnt_B = cnt_AB = 0
    for _ in range(n):
        s = input().rstrip()
        cnt_AB += s.count("AB")

        if s[0] == "B" and s[-1] == "A":
            cnt_BA += 1
        elif s[0] == "B":
            cnt_B += 1
        elif s[-1] == "A":
            cnt_A += 1

    res = cnt_AB + max(0, (cnt_BA - 1)) + min(cnt_A, cnt_B)
    cnt_BA = 1 if cnt_BA >= 1 else 0
    cnt_A = cnt_A - min(cnt_A, cnt_B)
    cnt_B = cnt_B - min(cnt_A, cnt_B)
    if cnt_A != 0 and cnt_BA != 0:
        res += min(cnt_A, cnt_BA)
    elif cnt_B != 0 and cnt_BA != 0:
        res += min(cnt_B, cnt_BA)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		String[] s = new String[h];
		int i = 0;
		for(i = 0; i < h; i++) {
			s[i] = scan.next();
		}
		for(i = 0; i < w + 2; i++) {
			System.out.print("#");
		}
		System.out.println();
		for(i = 0; i < h; i++) {
			System.out.println("#" + s[i] + "#");
		}
		for(i = 0; i < w + 2; i++) {
			System.out.print("#");
		}
		System.out.println();
	}
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	string n;
	cin>>n;
	int len = n.size();
	int sum = 0;
	for(int i=0;i<len;i++){
		sum += (n[i] - '0');
	}
	if(sum % 9 == 0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}; 

Measured memory_bytes: 3772
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

bool f[60000];

int main(){
	for(int i=0; i<60000; ++i){
		f[i] = true;
	}
	for(int i=2; i*i<60000; ++i){
		if(f[i]){
			for(int j=2; j*i<60000; ++j){
				f[i*j]=false;
			}
		}
	}
	int n;
	while(cin >> n){
		int over,under;
		for(int i=n-1; i>=2; --i){
			if(f[i]){
				under=i;
				break;
			}
		}
		for(int i=n+1; i<60000; ++i){
			if(f[i]){
				over=i;
				break;
			}
		}
		cout << under << " " << over << "\n";
	}
	return 0;
}

Measured memory_bytes: 1216
#include<iostream>
using namespace std;
int main(){
  int a, b, c, d, e;
  cin >> a >> b;
  c = a + b;
  d = a - b;
  e = a * b;
  if(c >= d && c >= e){
    cout << c << "\n";
    return 0;
  }
  if(d >= c && d >= e){
    cout << d << "\n";
    return 0;
  }
  cout << e << "\n";
}

Measured memory_bytes: 3620
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
T = list(map(int, input().split()))
S = sum(T)

M = int(input())

for i in range(M):
    p, x = map(int, input().split())

    print(S - T[p - 1] + x)


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

int main()
{
  int t = 3;
  int a[t];
  for(int i = 0; i < t; i++) cin >> a[i];

  for(int i = 0; i < t-1; i++)
  {
    for(int j = 0; j < t-1; j++)
    {
      if(a[j] > a[j+1])
      {
        int tmp = a[j];
        a[j] = a[j+1];
        a[j+1] = tmp;
      }
    }
  }

  cout << a[0] << " " << a[1] << " " << a[2] << endl;

  return 0;
}



Measured memory_bytes: 3116
/*Program from Luvwgyx*/
#include<map>
#include<queue>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
#define fir first
#define sec second
#define pi pair<int ,int >
#define mp(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
using namespace std;
const int maxn=1e5+10;
struct node{int w,id;}v1[maxn],v2[maxn];
int n,a[maxn],b[maxn],c[maxn],d[maxn],f[maxn];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
bool cmp(node x,node y){return x.w<y.w;}
bool check(){
    for(int i=1;i<=n;i++)c[i]=a[i];
    for(int i=1;i<=n;i++)d[i]=b[i];
    sort(c+1,c+n+1);sort(d+1,d+n+1);
    for(int i=1;i<=n;i++)if(c[i]>d[i])return 0;
    return 1;
}
bool check1(){
    for(int i=1;i<=n;i++)c[i]=a[i];
    for(int i=1;i<=n;i++)d[i]=b[i];
    sort(c+1,c+n+1);sort(d+1,d+n+1);
    for(int i=2;i<=n;i++)if(c[i]<=d[i-1])return 1;
    return 0;
}
bool check2(){
    for(int i=1;i<=n;i++)v1[i]=(node){a[i],i};
    for(int i=1;i<=n;i++)v2[i]=(node){b[i],i};
    sort(v1+1,v1+n+1,cmp);sort(v2+1,v2+n+1,cmp);
    for(int i=1;i<=n;i++)f[v1[i].id]=v2[i].id;
    int now=1,cnt=0;do{now=f[now];cnt++;}while(now!=1);
    return cnt==n;
}
signed main(){
    n=read();
    for(int i=1;i<=n;i++)a[i]=read();
    for(int i=1;i<=n;i++)b[i]=read();
    if(check()){
        if(check1())puts("Yes");
        else {
            if(check2())puts("No");
            else puts("Yes");
        }
    }else puts("No");
    return 0;
}


Measured memory_bytes: 7168
#include<stdio.h>
#define N 4001
#define Total 1000000

int judge(int id,int j,int set_of_person[]){
  int i;
  for (i=0;i<j;i++)
    if (set_of_person[i]==id)
      return 1;
  return -1;
}

void initialize(double person[],int set_of_person[]){
  int i;
  for (i=0;i<N;i++){
    person[i]=0.0;
    set_of_person[i]=0;
  }
}

int main(){
  int i,n,id,price,num;
  double person[N];
  int set_of_person[N];
  while (scanf("%d",&n)){
    if (n==0)
      break;
    int na=0,j=0;
    initialize(person,set_of_person);
    for (i=0;i<n;i++){
      scanf("%d %d %d",&id,&price,&num);
      person[id]+=(double)price*num;
      if (judge(id,j,set_of_person)==-1)
        set_of_person[j++]=id;
    }
    for (i=0;i<j;i++)
      if (person[set_of_person[i]]>=Total){
        printf("%d\n",set_of_person[i]);
        na=1;
      }
    if (na==0)
      printf("NA\n");
  }

  return 0;
}

Measured memory_bytes: 656
#include<iostream>
#include<iomanip>

using namespace std;

int main(){

double x, y, a, b, c, d, e, f;

while(cin >> a >> b >> c >> d >> e >> f){

x = (double) (c*e-f*b)/(a*e-b*d);
y = (double) (c*d-a*f)/(b*d-a*e);
if(x==0) x = 0;
if(y==0) y = 0;

cout << setiosflags(ios::fixed) << setprecision(3) << x << " " << y << endl;
}
}

Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  if(n%2==0) cout << 0.5 << "\n";
  else{
    int m = (n+1)/2;
    double res = (double)m/n;
    printf("%.6f\n", res);
  }
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
from string import ascii_lowercase
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations, product
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

chs = ascii_lowercase


def main():
    from builtins import int, map

    n = int(input())
    ans = ''
    while n > 0:
        n -= 1
        ans += chr(ord('a') + n % 26)
        n //= 26
    print(ans[::-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 72172
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

long long int N;

long long int A[200005];
vector<long long int> S;


long long int min4(long long int p, long long int q, long long int r, long long int s) {

	long long int ret = p;
	if (ret > q) { ret = q; }
	if (ret > r) { ret = r; }
	if (ret > s) { ret = s; }

	return ret;
}

long long int max4(long long int p, long long int q, long long int r, long long int s) {

	long long int ret = p;
	if (ret < q) { ret = q; }
	if (ret < r) { ret = r; }
	if (ret < s) { ret = s; }

	return ret;
}

int main(void) {

	cin >> N;

	long long int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp;
		A[i] = tmp;
	}

	S.push_back(0);
	for (int i = 1; i <= N; i++) {
		S.push_back(A[i] + S[i - 1]);
	}
	S.push_back(999999999999999);

	long long int ans = 9999999999999999;

	long long int value;

	long long int P, Q, R, T;

	int J1, J2;
	J1 = 1; J2 = 3;
	for (int M = 2; M <= N - 2; M++) {
		while (J1 <= M - 1 && abs(S[M] - 2 * S[J1 + 1]) < abs(S[M] - 2 * S[J1])) { J1++; }

		while (J2 <= N - 2 && abs(S[N] - 2 * S[J2 + 1] + S[M]) < abs(S[N] - 2 * S[J2] + S[M])) { J2++; }

		//cout << "J1= " << J1 << " M= " << M << " J2= " << J2 << endl;

		P = S[J1] - S[0];
		Q = S[M] - S[J1];
		R = S[J2] - S[M];
		T = S[N] - S[J2];
		
		value = max4(P, Q, R, T) - min4(P, Q, R, T);

		if (ans > value) { ans = value; }

	}//M-loop fin
		
	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 3956
(defun card-game (n)
	(let* ((mylist (make-array n))
          (alice 0)
        (bob 0))
          (dotimes (i n) 
            (setf (aref mylist i) (read))
           )
     (sort mylist #'>)
          
	(dotimes (i n)
      (if (zerop (rem i 2))
      	(setf alice (+ alice (aref mylist i)))
      	(setf bob (+ bob (aref mylist i))))
 
      )
          (- alice bob)
     )
)

(format t "~A~%" (card-game (read)))

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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

struct HL {
	int h;
	int p;
	int q;
};

int main() {
	while( 1 ) {
		int n, m, a; cin >> n >> m >> a;
		if( n == 0 && m == 0 && a == 0 ) break;

		int h, p, q;
		HL hl[1002] = {};

		REP( i, m ) {
			cin >> h >> p >> q;
			hl[i].h = h; hl[i].p = p; hl[i].q = q;
		}

		for( int i = 1001; i > 0; i-- ) {
			REP( j, m ) {
				if( hl[j].h == i ) {
					if( hl[j].p == a ) {
						a = hl[j].q;
						break;
					} else if( hl[j].q == a ) {
						a = hl[j].p;
						break;
					}
				}
			}
		}

		cout << a << endl;

	}
}


Measured memory_bytes: 3028
#include <iostream>
int N;
struct station {
	int num;
	int C;
	int S;
	int F;
}sta[505];
void check(struct station * sta, int num);
int main() {
	std::cin >> N;
	for (int i = 1;i <= N;i++) {
		if (i == N) { sta[i].num = 0;break; }
		std::cin >> sta[i].C >> sta[i].S >> sta[i].F;
		sta[i].num = i;
	}
	for (int i = 1;i <= N;i++) {
		check(sta, i);
	}
	return 0;
}

void check(struct station * sta, int num) {
	if (sta[num].num == 0) { std::cout << 0 << '\n';return; }
	int all = 0;
	for (int i = num;i<N;i++) {
		if (i == num) {
			all += (sta[i].C + sta[i].S);
		}
		else {
			if (all < sta[i].S) 
				{ all += sta[i].S - all + sta[i].C; 
			}else {
				while ((all - sta[i].S) % sta[i].F != 0) { all++; }
				all += sta[i].C;
			}
		}
		
	}
	std::cout << all << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
signed main(void)
{
    int H, W;
    cin >> H >> W;
    int a, b, c;
    int H_mod_3 = H % 3;
    int W_mod_3 = W % 3;
    int max = 0;
    int Min = 100000000000000000;
    int ans = 100000000000000000;
    int ans2 = 100000000000000000;
    if( H_mod_3 == 0 || W_mod_3 == 0){
        cout << 0;
        return 0;
    }
    for( int i = W/2-1; i <= W/2+1; i++){
        for( int j = H/3-1; j <= H/3+1; j++){
            if( H-j < 1 || W-i < 1 || j < 1 || i < 1)continue;
            max = 0;
            Min = 100000000000000000;
            if( Min > i * W) Min = j * W;
            if( max < i * W) max = j * W;
            if( Min > (H-j) * i) Min = (H-j) * i;
            if( max < (H-j) * i) max = (H-j) * i;
            if( Min > (H-j) * (W-i)) Min = (H-j) * (W-i);
            if( max < (H-j) * (W-i)) max = (H-j) * (W-i);
            if( ans > max-Min) ans = max-Min;
            //printf("a:%lld*%lld=%lld, b:%lld*%lld=%lld, c:%lld*%lld=%lld\n", j, W, j * W, H-j, i, (H-j) * i, H-j, W-i,(H-j) * (W-i));
            //printf("max:%lld,Min:%lld, %lld\n", max, Min, ans);
        }
    }
    W += H;
    H = W - H;
    W -= H;
    for( int i = W/2-1; i <= W/2+1; i++){
        for( int j = H/3-1; j <= H/3+1; j++){
            if( H-j < 1 || W-i < 1 || j < 1 || i < 1)continue;
            max = 0;
            Min = 100000000000000000;
            if( Min > i * W) Min = j * W;
            if( max < i * W) max = j * W;
            if( Min > (H-j) * i) Min = (H-j) * i;
            if( max < (H-j) * i) max = (H-j) * i;
            if( Min > (H-j) * (W-i)) Min = (H-j) * (W-i);
            if( max < (H-j) * (W-i)) max = (H-j) * (W-i);
            if( ans2 > max-Min) ans2 = max-Min;
            //printf("a:%lld*%lld=%lld, b:%lld*%lld=%lld, c:%lld*%lld=%lld\n", j, W, j * W, H-j, i, (H-j) * i, H-j, W-i,(H-j) * (W-i));
            //printf("max:%lld,Min:%lld, %lld\n", max, Min, ans);
        }
    }
    cout << min(min(ans,W), min(ans2,H));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void)
{

	int N, X;
	cin >> N >> X;
	int m[100] = {};

	FOR(i, N)
		cin >> m[i];

	cout << (X - accumulate(m, m + 100, 0)) / *min_element(m, m + N) + N << endl;

	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import math
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
    
N=int(input())
A=list(map(int,input().split()))

l=lcm_list(A)-1
ans=0
for i in range(N):
    ans+=l%A[i]
print(ans)

Measured memory_bytes: 66792
#include <bits/stdc++.h>
#define INF 1e+9
using namespace std;

signed main(){
	int n,t,ans = INF;
	cin >> n >> t;
	for(int i = 0;i < n;i++){
		int a,b;
		cin >> a >> b;
		if(b <= t) ans = min(ans,a);
	}
	if(ans != INF) cout << ans << endl;
  else cout << "TLE" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(10);
	int n;
	cin >> n;
	double x[100] = { 0 }, y[100] = { 0 }, p1 = 0, p2 = 0, p3 = 0, pinf = 0;
	for (int i = 0; i < n; i++) cin >> x[i];
	for (int i = 0; i < n; i++) cin >> y[i];
	for (int i = 0; i < n; i++) {
		p1 += abs(x[i] - y[i]);
		p2 += (x[i] - y[i]) * (x[i] - y[i]);
		p3 += abs((x[i] - y[i]) * (x[i] - y[i]) * (x[i] - y[i]));
		pinf = max(pinf, abs(x[i] - y[i]));
	}
	cout << p1 << endl;
	cout << sqrt(p2) << endl;
	cout << cbrt(p3) << endl;
	cout << pinf << endl;
	return 0;
}


Measured memory_bytes: 3460
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v; ll w; };

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

int main() {
	ll x; cin >> x; x++;
	vector<int> v;
	int k = 0;
	vector<int> unko;
	while (x > 1) {
		if (x % 2 == 0) x /= 2, unko.pb(+1);
		else x--, unko.pb(-1);
	}
	reverse(unko.begin(), unko.end());
	for (int z: unko) {
		if (z == +1) v.pb(k);
		if (z == -1) v.insert(v.begin(), k);
		k++;
	}
	cout << v.size() * 2 << endl;
	rep(k, v.size()) cout << k + 1 << ' ';
	for (int k: v) cout << k + 1 << ' ';
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

struct str {
    string s;
    int last = 0;
    str(string s) : s(s) {
        rep(i,SZ(s)) chmax(last, s[i]-'a');
    }
};

int main() {
    int N; cin >> N;
    queue<str> que;
    que.push(str("a"));
    while(1) {
        str s = que.front();
        if(SZ(s.s) >= N) break;
        que.pop();
        rep(i,min(s.last+2, 26)) {
            string nw = s.s;
            nw += (char)(i + 'a');
            que.push(str(nw));
        }
    }
    vector<string> v;
    while(!que.empty()) {
        str s = que.front(); que.pop();
        v.push_back(s.s);
    }
    sort(ALL(v));
    for(auto e : v) {
        cout << e << endl;
    }
    return 0;
}


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

using namespace std;

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

	if(n == 2) {
		cout << 1 << '\n';
		return 0;
	}
	
	long long ans = 0;

	long long m = n - 1;

	long long t = 1;

	for(long long i = 2; i * i <= (n - 1) * 2; ++i) {
		if(m % i == 0) {
			long long c = 0;

			while(m % i == 0) {
				m /= i;
				++c;
			}

			t *= (c + 1);
		}
	}

	if(m > 1) {
		t *= 2;
	}

	ans += t;

	for(long long i = 2; i * i <= n * 2; ++i) {
		if(n % i == 0) {
			long long t = n;
			
			while(t % i == 0) {
				t /= i;
			}

			if(t % i == 1) {
				++ans;
			}
		}
	}

	cout << ans << '\n';

	return 0;
}


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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

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

	cout << N - K + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
from sys import stdin,stdout
n = int(stdin.readline())
v = list(map(int, stdin.readline().split()))
flag = True
if 0 in v:
	print(0)
else:
	ans = 1
	for i in v:
		ans *= i
		if ans > 10 ** 18:
			flag = False
			break
	if flag == False:
		ans = -1
	stdout.write(str(ans) + '\n')

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

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

using namespace std;
using P = pair<int, int>;
using ll = long long;
const ll INF = LLONG_MAX/3;

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; }

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    if(abs(a-b)%2==0){
        cout<<abs((a+b)/2-a)<<endl;
    }else{
        int x=max(a,b);
        int y=min(a,b);
        cout<<min(y-1+(x-(y-1)-1-1)/2+1,n-x+(n-(y+n-x+1))/2+1)<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=998244353;
#define N 200020
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,t[N],ans,a[N],ok[N];
char s[N];
bool check(int x){
	for(int i=0,p=0;i<n;i+=x,p^=1){
		for(int j=1;j<=x;++j){
			if(a[i+j]>(a[j]^p))return true;
			if(a[i+j]<(a[j]^p))return false;
		}
	}
	return true;
}
void Solve(int x){
	int tot=0;
	for(int i=1;i<=x;++i){
		tot=((tot<<1)+a[i])%mod;
	}
	++tot;
	if(!check(x))--tot;
	t[x]=(t[x]+tot)%mod;
	for(int i=x+x;i<=n;i+=x){
		if(ok[i])t[i]=(t[i]-t[x]+mod)%mod;
	}
}
int main(){
	n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n;++i){
		a[i]=s[i]-'0';
	}
	for(int d=1;d<=n;++d){
		if(n%d==0&&(n/d)&1){
			ok[d]=1;
		}
	}
	for(int d=1;d<=n;++d){
		if(ok[d])Solve(d);
	}
	for(int i=1;i<=n;++i){
		ans=(ans+2LL*i%mod*t[i])%mod;
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 4816
#include <stdio.h>

#define MAX 200000

int max(int a,int b) 
{ return a>b ? a: b;}
int min(int a,int b) 
{ return a<b ? a: b;}

int main(void) {
    int R[MAX], i, n;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    printf("%d\n",maxv);

    return 0;
}



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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,x; cin>>n;
	set<int> st;
	for (int i=0; i<n; i++)
		cin>>x, st.insert(x);
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    string S;
    cin >> K >> S;

    if(S.size() > K){
        rep(i,K){
            cout << S[i];
        }
        cout << "...";
    }
    else{
        cout << S;
    }
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		String st = scan.nextLine();
		sb.append(st);

		int l = st.length();
		for (int i = 0; i < l; i++) {
			char cha = sb.charAt(i);
			if ( Character.isUpperCase(cha) ) {
				char lchar = Character.toLowerCase(cha);
				sb.setCharAt(i, lchar);
			}else if ( Character.isLowerCase(cha) ) {
				char uchar = Character.toUpperCase(cha);
				sb.setCharAt(i, uchar);
			}
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 26368
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] a = sc.next().split("");
        String[] b = sc.next().split("");
        String[] c = sc.next().split("");

        sc.close();

        int cnt = 0;

        for (int i = 0; i < n; i++) {
            if (a[i].equals(b[i])) {
                if (!a[i].equals(c[i])) {
                    cnt++;
                }
            } else {
                if (a[i].equals(c[i])) {
                    cnt++;
                } else if (b[i].equals(c[i])) {
                    cnt++;
                } else {
                    cnt += 2;
                }
            }
        }

        System.out.println(cnt);
    }
}

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

int main(void)
{
    int n, m;
    cin >> n >> m;
    int ans = 0;
    if (n >= 2)
    {
        ans += (n * (n - 1)) / 2;
    }
    if (m >= 2)
    {
        ans += (m * (m - 1)) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  
  rep(i, N) {
    cin >> h[i];
  }
  int ans = 0, tmp=0;
  for(int i = N-1; i > 0; i--) {
    if (h[i-1] >= h[i]){
      tmp++;
    } else {
      ans = max(ans, tmp);
      tmp = 0;
    }
  }
  ans = max(ans, tmp);
  
  cout << ans << endl;

}


Measured memory_bytes: 640
#-*- using:utf-8 -*-
 
X, N = map(int, input().split())
p = list(map(int, input().split()))
min = X
max = X
while True:
    if (min not in p):
        print(min)
        break
    if (max not in p):
        print(max)
        break
    min = min-1
    max = max+1


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	int cont4=0,cont2=0;
	for(int i=0;i<n;i++){
	  int a;cin>>a;
	  if(a%4==0)cont4++;
	  else if(a%2==0)cont2++;
	}
	int contodd=n-cont4-cont2;
	if(contodd<=cont4){
		cout<<"Yes"<<endl;
	}else if(contodd==cont4+1){
		cout<<(cont2?"No":"Yes")<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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


int main(void){
	int A, B, C;
	int D, ans;

	scanf("%d %d %d", &A, &B, &C);

	D = A - B;
	if(C-D<=0){
		printf("0");
	}else{
		ans = C - D;
		printf("%d", ans);
	}



	return 0;
}

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

int main() {
  string S;
  cin>>S;
  char a=S.at(0);
  char b=S.at(1);
  char c=S.at(2);
  
  if(a==b&&b==c){
    cout<<"No"<< endl;
  }
  else{
    cout<<"Yes"<< endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

    string s; cin>>s;
    deque<char> deq;
    for(auto i : s) deq.emplace_back(i);

    int q; cin>>q;
    bool rev = false;
    while(q--){
        int x; cin>>x;
        if(x == 1){
            rev ^= 1;
        }
        else{
            int f; cin>>f;
            char c; cin>>c;
            bool front = (f == 1 && !rev) || (f == 2 && rev);
            
            if(front) deq.emplace_front(c);
            else deq.emplace_back(c);
        }
    }
    
    if(rev) reverse(deq.begin(), deq.end());

    for(auto i:deq) cout << i;
    cout << endl;

    return 0;
}

Measured memory_bytes: 976
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void *x, const void *y) {
	return *(int *)x - *(int *)y;
}
int a[200000], b[200000];
int x[200000];
typedef long long ll;
int main() {
	int n;
	ll ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
	}
	for (int i = 0; i < n; i++) {
		x[i] = a[i];
	}
	qsort(x, n, sizeof(int), cmpint);
	if (n % 2 == 0) {
		ans = x[n / 2 - 1] + x[n / 2];
	} else {
		ans = x[(n + 1) / 2 - 1];
	}
	for (int i = 0; i < n; i++) {
		x[i] = b[i];
	}
	qsort(x, n, sizeof(int), cmpint);
	if (n % 2 == 0) {
		ans = x[n / 2 - 1] + x[n / 2] - ans;
	} else {
		ans = (x[(n + 1) / 2 - 1] - ans);
	}
	printf("%lld\n", ans + 1);
	return 0;
}

Measured memory_bytes: 4800
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;


void solve() {
	int n; 
	string s;
	cin >> n; 
	cin >> s;
	ll cnt = 1, ans = 0;
	for(int i = 0; i < n - 1; ++i) {
		if(s[i] == s[i + 1]) cnt++;
		else {
			ans++;
			cnt = 1;
			}
		}
		ans++;
		cout << ans << endl;
}


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



Measured memory_bytes: 3728
/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const ll N = 305;
ld p[N][N][N],ev[N][N][N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		ll n,x;cin>>n;
		vector<ll> cnt(4,0);
		for(ll i=0;i<n;i++)
		{
			cin>>x;
			cnt[x]++;
		}
		p[cnt[1]][cnt[2]][cnt[3]] = 1.0;
		ld temp,waste;
		for(ll c=cnt[3];c>=0;c--)
		{
			for(ll b=n;b>=0;b--)
			{
				for(ll a=n;a>=0;a--)
				{
					if(a==0 and b==0 and c==0)
						continue;
					if(a+b+c>n)
						continue;
					waste = (ld)(n - (a+b+c))/n;
					ev[a][b][c] += ((waste/(1.0-waste))+1.0)*p[a][b][c];
					// cout<<p[a][b][c]<<endl;
					if(a!=0)
					{
						temp = (ld)a/(ld)(a+b+c);
						p[a-1][b][c] += p[a][b][c] * temp;
						ev[a-1][b][c] += ev[a][b][c] * temp ;
					}
					if(b!=0)
					{
						temp = (ld)b/(ld)(a+b+c);
						// cout<<temp<<endl;
						p[a+1][b-1][c] += p[a][b][c] * temp;
						ev[a+1][b-1][c] += ev[a][b][c] * temp ;
					}
					if(c!=0)
					{
						temp = (ld)c/(ld)(a+b+c);
						p[a][b+1][c-1] += p[a][b][c] * temp;
						ev[a][b+1][c-1] += ev[a][b][c] * temp ;
					}
				}
			}
		}
		cout<<setprecision(100)<<ev[0][0][0];

	}

	
	time
	return 0;
}

Measured memory_bytes: 427144
#include<iostream>
#include<cmath>

using namespace std; 

int k;
int ans;
int visit[100100];

void dfs(int a,int b)
{
//cout<<a<<" "<<b<<endl;
	if(visit[a]<=b) return;
	else visit[a]=b;
	
	if(a==0)
	{
//		cout<<a<<" ";
		ans=min(ans,b);
		return;
	}
	
	if(b+1<ans)dfs((a+1)%k,b+1);
	dfs((a*10)%k,b); 
} 

int main()
{
	cin>>k;
	
	int t=k;
	while(t)
	{
		ans+=t%10;
		t/=10;
	}
	
	for(int i=0;i<=k;i++) visit[i]=1e9;
	
	dfs(1,1);
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
/**
 *  author:   TakeruOkuyama
 *  created:  2020-04-09 14:53:46
**/
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    ll sum = 0;
    rep(i, N){
        if((i+1)%3!=0&&(i+1)%5!=0){
            sum += i+1;
        }
    }
    cout << sum << endl;
return 0;}

/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 
vector<ll>a;
//ll a[100];
int main()
{
	int n;
	ll t,ts,s=1000;
	cin>>n>>ts;
	a.push_back(ts);
	for(int i=1;i<n;i++)
	{
		cin>>t;
		if(t!=ts)a.push_back(t);
		ts=t;
	}
	for(int i=0;i<a.size()-1;i++)
	{
		if(a[i]<a[i+1])
		{
			ll num=s/a[i];
			s+=num*(a[i+1]-a[i]);
		}
	}
	printf("%lld\n",s);
//	int n;
//	cin>>n;
//	for(int i=0;i<n;i++)
//	{
//		cin>>a[i];
//	}
//	for(int i)
	return 0;
}

Measured memory_bytes: 3768
import java.io.*;

class Main{
    public static void main(String[] a)throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        String str = null;        
        int orderNum;
        int sum = 1;
        
        // 各指示の移動パターン(数字はサンプルの初期位置の目に対応)
        int[] defaultDice = {1,2,3,4,5,6};
        int[] north = {5,1,3,4,6,2}; 
        int[] east  = {3,2,6,1,5,4}; 
        int[] west  = {4,2,1,6,5,3};
        int[] south = {2,6,3,4,1,5}; 
        int[] Left  = {1,3,5,2,4,6};
        int[] Right = {1,4,2,5,3,6};

        int[] beforeDice = new int[6];
        int[] afterDice = new int[6];
        
        beforeDice = defaultDice.clone();
        while((str = in.readLine()) != null){
            if(str.equals("0")){
                // 0：処理終了
                System.exit(0);
            }else{
                // 命令回数の読み込み
                orderNum = Integer.parseInt(str);
                // 初期化
                beforeDice = defaultDice.clone();
                sum = beforeDice[0];      
                
                for(int i=0; i<orderNum; i++){
                    str = in.readLine();
                    
                    if(str.equals("North")){
                        for(int j=0; j<6; j++){
                            afterDice[north[j] - 1] = beforeDice[j];
                        }
                    }
                    else if(str.equals("East")){
                        for(int j=0; j<6; j++){
                            afterDice[east[j] - 1] = beforeDice[j];
                        }
                    }
                    else if(str.equals("West")){
                        for(int j=0; j<6; j++){
                            afterDice[west[j] - 1] = beforeDice[j];
                        }
                    }
                    else if(str.equals("South")){
                        for(int j=0; j<6; j++){
                            afterDice[south[j] -1] = beforeDice[j];
                        }
                    }
                    else if(str.equals("Left")){
                        for(int j=0; j<6; j++){
                            afterDice[Left[j] -1] = beforeDice[j];
                        }
                    }
                    else if(str.equals("Right")){
                        for(int j=0; j<6; j++){
                                    afterDice[Right[j] -1] = beforeDice[j];
                        }
                    }
                    else{
                        System.out.println("Input Error");
                    }
                    beforeDice = afterDice.clone();
                    sum += afterDice[0];
                }
                System.out.println(sum);
          
            }
        }
    }
}

Measured memory_bytes: 21980
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
static const int MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;

void dfs(int u){
    V[u] = true;
    for(int i=0; i < G[u].size(); i++){
        int v = G[u][i];
        if( !V[v] ) dfs(v);
    }
    out.push_front(u);
}

int main(){
    int s,t,M;
    
    cin >> N >> M;
    for(int i=0; i<N; i++) V[i] = false;
    for(int i=0; i<M; i++){
        cin >> s >> t;
        G[s].push_back(t);
    }
    
    for(int i=0; i<N; i++){
        if( !V[i] ) dfs(i);
    }
    
    for(list<int>::iterator it=out.begin(); it!=out.end(); it++){
        cout << *it << endl;
    }
    
    return 0;
}

Measured memory_bytes: 6084
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int v[N], c[N];
    int sum = 0;
    
    for(int i = 0; i < N; i++){
    	cin >> v[i];
    }
    for(int i = 0; i < N; i++){
    	cin >> c[i];
    }
    for(int i = 0; i < N; i++){
        if(v[i] > c[i]){
            sum += v [i]- c[i];
        }
    }
    cout << sum << endl;

    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 < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A[5] = {};
	rep(i, 3) {
		int a, b;
		cin >> a >> b;
		A[a]++;
		A[b]++;
	}

	int OK = 1;
	rep1(i, 4) if (A[i] > 2) OK = 0;

	if (OK) co("YES");
	else co("NO");

	Would you please return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#define maxn 100009
using namespace std;
vector<int>G[maxn];
int n;
int d[maxn];
bool ok = 0;
void dfs(int u, int fa){
	int cnt = 0;
	d[u] = 1;
	for(auto v : G[u]){
		if(v == fa)
			continue;
		dfs(v, u);
		d[u] += d[v];
		if(d[v] & 1)
			cnt++;
	}
	if((n - d[u]) & 1)
		cnt++;
	if(cnt >= 2)
		ok = 1;
}

int main(){
	scanf("%d", &n);
	for(int i =1 ; i < n ;i++){
		int x, y;
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	if(n & 1){
		puts("First");
		return 0;
	}
	dfs(1, -1);
	if(ok)
		puts("First");
	else
		puts("Second");
	return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
int main() {
 int m1,m2,d1,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1==1&&d1==31){
  cout << "1" << endl;
}
  else if(m1==2&&d1==28){
  cout << "1" << endl;
}
  else if(m1==3&&d1==31){
  cout << "1" << endl;
}
   else if(m1==4&&d1==30){
  cout << "1" << endl;
}
   else if(m1==5&&d1==31){
  cout << "1" << endl;
}
  else if(m1==6&&d1==30){
  cout << "1" << endl;
} 
   else if(m1==7&&d1==31){
  cout << "1" << endl;
}
   else if(m1==8&&d1==31){
  cout << "1" << endl;
}
   else if(m1==9&&d1==30){
  cout << "1" << endl;
}
   else if(m1==10&&d1==31){
  cout << "1" << endl;
}
   else if(m1==11&&d1==30){
  cout << "1" << endl;
}
   else if(m1==12&&d1==31){
  cout << "1" << endl;
}
   else{
  cout << "0" << endl;
}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
vector<ll> v[300010];
int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    if(a*b>=n&&a+b-1<=n){
	ll t=n-(a+b-1);
	ll now=n-b;
	ll pnt=0;
	while(t>0){
	    if(pnt==0){
		v[pnt].push_back(now);
		pnt++;
		now--;
	    }
	    else{
		v[pnt].push_back(now);
		pnt++;
		now--;
		t--;
	    }
	    if(pnt==b)pnt=0;
	}
	while(now>0){
	    v[0].push_back(now);
	    now--;
	}
	
	bool first=true;
	lol(i,b){
	    for(int j=v[i].size()-1;j>=0;j--){
		if(!first)cout<<" ";
		first=false;
		cout<<v[i][j];
	    }
	    if(!first)cout<<" ";first=false;
	    cout<<n-i;
	}
	cout<<endl;
    }
    else cout<<"-1"<<endl;
    return 0;
}


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

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

	int N;
	int i,j;
	int tmp;
	int answer;
	int counter=0;
	bool flag=true;
	double ave;
	vector<int> given;

	cin >> N;

	for(i=0;i<N;i++){
		cin >> tmp;
		given.push_back(tmp);
	}

	for(i=0;i<N;i++){
		if(!(given[i]%2) && !(given[i]%3==0 || given[i]%5==0)){
			flag=false;
			break;
		}
	}

	if(flag) cout << "APPROVED" << endl;
	if(!flag) cout << "DENIED" << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

template<typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int A, B, C;
    cin >> A >> B >> C;

    ll ans = 0;
    int num = min(B, C);
    B -= num;
    C -= num;
    ans += (ll)num * 2;
    if (C > 0) {
        num = min(A, C);
        ans += num;
        A -= num;
        C -= num;
        if (C > 0)ans++;
    }
    if (B > 0)ans += B;

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

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_Nikkei_2019
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] dataArr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            
            int max = 0;
            if(dataArr[1] < dataArr[2])max = dataArr[1];
            else max = dataArr[2];
            
            int min = dataArr[1] + dataArr[2] - dataArr[0];
            if (min < 0) min = 0;

            Console.WriteLine(max.ToString() + " " + min.ToString());
        }
    }
}


Measured memory_bytes: 11092
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    r, s, p = ns()
    dic_s = {"r": r, "s": s, "p": p}
    t = list(input())
    res = [0] * n
    dic = {"r": "p", "s": "r", "p": "s"}

    total = 0
    for i in range(n):
        if i - k > -1:
            if res[i - k] == dic[t[i]]:
                if i + k < n:
                    tmp = {dic[t[i]], dic[t[i + k]]}
                    for v in {"r","s","p"}:
                        if v not in tmp:
                            res[i] = v
                            break
                else:
                    continue

            else:
                res[i] = dic[t[i]]
                total += dic_s[res[i]]

        else:
            res[i] = dic[t[i]]
            total += dic_s[res[i]]

    print(total)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6868
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int, A: "List[int]"):
    summation = sum(A)
    count = 0
    for n in range(N):
        if A[n] >= summation * 1 / (4 * M):
            count += 1
    if count >= M:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064