akhauriyash/Code-Regression huggingface dataset:
S = int(input())
A = S//100
B = S-(A*100)
if B ==0 or B >= 13:
    if 1<= A <=12:    
        print("MMYY")
    else:
        print("NA")
elif 1<= B <=12:
    if 1<= A <=12:
        print("AMBIGUOUS")
    elif A >= 13:
        print("YYMM")
    elif A == 0:      
        print("YYMM")
    else:
        print("NA")
else:
    print("NA")

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

struct DSU {
    vector<int> p, sz;
    DSU (int n) {
        p.assign(n, -1);
        for (int i = 0; i < n; i++) p[i] = i;
        sz.assign(n, 1);
    }

    int find (int a) {
        if (p[a] == a) return a;
        return p[a] = find(p[a]);
    }

    void uni(int a, int b) {
        int sa = find(a), sb = find(b);
        if (sa == sb) return;
        if (sz[sa] < sz[sb]) swap(a, b), swap(sa, sb);
        sz[sa] += sz[sb];
        p[sb] = sa;
    }
};

int main () {
    int n;
    while (scanf("%d", &n) == 1) {
        vector<int> x(n), y(n);
        for (int i = 0; i < n; i++) scanf("%d %d", &x[i], &y[i]);

        vector<int> ids;
        for (int i= 0; i < n; i++) ids.push_back(i);
        sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });
        
        DSU dsu(n);
        set<pair<int, int>> s;
        for (auto &id : ids) {
            auto it = s.lower_bound({ y[id], -1 });
            if (it != s.begin()) dsu.uni(id, prev(it)->second);
            it = s.begin();
            if (it != s.end() && it->first < y[id]) dsu.uni(id, it->second);
            s.insert({ y[id], id });
        }
        
        s.clear();
        for (int i = n - 1; i >= 0; i--) {
            int id = ids[i];
            auto it = s.lower_bound({ y[id], -1 });
            if (it != s.end()) dsu.uni(id, it->second);
            it = s.end();
            if (it != s.begin() && prev(it)->first > y[id]) dsu.uni(id, prev(it)->second);
            s.insert({ y[id], id });
        }

        for (int id = 0; id < n; id++) printf("%d\n", dsu.sz[dsu.find(id)]);
        printf("\n");
    }
}




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

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

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

ll func(ll x)
{
	int res = 0;
	while (x % 2 == 0)
	{
		x /= 2;
		res++;
	}
	return res;
}

int main()
{
	ll n, m;
	cin >> n >> m;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] % 2 == 1)
		{
			cout << 0 << endl;
			return 0;
		}
		a[i] /= 2;
	}

	ll t = func(a[0]);
	for (int i = 0; i < n; i++)
	{
		if (t != func(a[i]))
		{
			cout << 0 << endl;
			return 0;
		}
		a[i] >>= t;
	}
	m >>= t;

	ll l = 1;
	for (int i = 0; i < n; i++)
	{
		l = lcm(l, a[i]);
		if (m < l)
		{
			cout << 0 << endl;
			return 0;
		}
	}

	m /= l;
	ll ans = (m + 1) / 2;
	cout << ans << endl;
}

Measured memory_bytes: 1024
import Data.List

main = do
    [n, m] <- map read . words <$> getLine
    abs <- map (map read . words) <$> sequence (replicate n getLine)
    print $ solve (sort abs) m

solve :: [[Int]] -> Int -> Int
solve _ 0 = 0
solve ([a, b]:abs) m = let k = min m b
                           in k * a + solve abs (m - k)

Measured memory_bytes: 140668
#include <stdio.h>
int main(void){
    int a, b, c, d, n, count;
    while(scanf("%d", &n)!=EOF){
        count = 0;
        for(a=0; a<=9; a++){
            for(b=0; b<=9; b++){
                for(c=0; c<=9; c++){
                    for(d=0; d<=9; d++){
                        if(a+b+c+d == n){
                            count++;
                        }
                    }
                }
            }
        }
        printf("%d\n", count);
    }
    return 0;
}



Measured memory_bytes: 2028
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
ll a[200005],b[200005],c[200005];
int main()
{
	ll m,n,i,j,s1,s2;
	cin>>n;
	double s=0,k=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		a[b[i]]++;
	}
	for(j=1;j<=n;j++)
		{
		
			k+=1.0*(a[b[j]]-1)/2;
		}
	for(i=1;i<=n;i++)
	{
		s=k;
		s-=a[b[i]]*(a[b[i]]-1)*1.0/2;
		a[b[i]]--;
		s+=a[b[i]]*(a[b[i]]-1)*1.0/2;
		
		 printf("%lld\n",(ll)s);
		
		a[b[i]]++;
	}
	 	
		 } 

Measured memory_bytes: 5760
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20
#define DIVISOR 1000000007

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}
#define NUM_MAX 1000
#define K_MAX 1000

static uint64_t factorial[NUM_MAX+K_MAX+1];
static uint64_t inv_factorial[NUM_MAX+K_MAX+1];

struct pair {
    int x;
    int y;
};

struct pair gcdext(int a, int b) {
    if(a == 0) { return (struct pair){0, 1}; }
    struct pair p = gcdext(b%a, a);
    return (struct pair){p.y - (b/a)*p.x, p.x};
}

void prep_combi(int n) {
    // prep
    int i;
    factorial[0] = factorial[1] = 1;
    for(i = 2; i <= n; i++) {
        factorial[i] = (factorial[i-1] * i)%DIVISOR;
    }

    inv_factorial[0] = inv_factorial[1] = 1;
    for(i = 2; i <= n; i++) {
        struct pair p = gcdext(i, DIVISOR);
        int inv = (p.x + DIVISOR)%DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1]*inv)%DIVISOR;
    }
}

uint64_t calc_combi(int n, int k) {
    uint64_t ans = 1;
    ans = (ans * factorial[n])%DIVISOR;
    ans = (ans * inv_factorial[k])%DIVISOR;
    ans = (ans * inv_factorial[n-k])%DIVISOR;
    return ans;
}

uint64_t calc_homo(int kinds, int num) {
    return calc_combi(kinds+num-1, num);
}

void init() {
    prep_combi(NUM_MAX+K_MAX);
}

int main(void) {
    int n, k;
    init();
    get_int2(&n, &k);
    uint64_t ans = calc_homo(k, n);
    printf("%d\n", (int)ans);
    return 0;
}


Measured memory_bytes: 2084
#include <stdio.h>
 
int find_max(int n,int a[]){
	int max = a[0];
	int i = 0;
	int cnt = 0;
 
	for(i=1; i<n; i++){
		if(max < a[i]){
			max = a[i];
			cnt = i;
		}
	}
 
	a[cnt] = 0;
	return(max);
}
 
int main(void) {
	int n;
	scanf("%d", &n);
 
	int a[n+1];
	int i,sub = 0;
	for(i=0; i<n; i++)
		scanf("%d", &a[i]);
 
	for(i=0; i<(n/2+n%2); i++){
		sub = sub + find_max(n,a);
		sub = sub - find_max(n,a);
	}
 
	printf("%d", sub);
 
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/ruby
n,k=gets.split.map(&:to_i)
s=gets.chomp.chars.map{|c|c==?A ? 0 : 1}
f=0
i=0
while i<n&&k>0
	if (1-s[i]+f)%2>0
		s[i]=[1,0][f]
	else
		f^=1
		s[n+i]=[0,1][f]
		i+=1
	end
	k-=1
end
if 0<k
	if n%2>0
		print [?B,?A][(1-s[i]+f+k)%2]
	end
	puts 'BA'*(n/2)
else
	puts s[i,n].map{|c|(1-c+f)%2>0 ? ?A : ?B}*''
end


Measured memory_bytes: 25084
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int  s;
		while(true){
	int	 a = scan.nextInt();
	int b=scan.nextInt();
	int c=scan.nextInt();
if(a==-1&&b==-1&&c==-1)
	break;
	s=a+b;
	if(a!=-1&&b!=-1){
		if(s>=80)
			System.out.println("A");
		else if(s>=65)
			System.out.println("B");
		
		else if(s>=50)
			System.out.println("C");
			
		else if(s>=30&&c>=50)
			System.out.println("C");
			
		else if(s>=30)
			System.out.println("D");
			
		else 
			System.out.println("F");
		
	}
	else
		System.out.println("F");
	
		}
	}
}

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

int main(void){

    int N;

    scanf("%d", &N);

    long long ans = 0;

    for(int A = 1; A < N; A++){
        if(N % A == 0){
            ans += N / A - 1;
        }else{
            ans += N / A;
        }
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>
#include <stdlib.h>
int num(){
    char s[11];
    int i, n;
    for(i=0; i<sizeof(s); i++){
        s[i] = getchar();
        if(s[i] == ' ' || s[i] == '\n'){
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}
int main(void){
    int n, t, a, c=0;
    float x, y, z=100000;
    int i, h[1000];
    n = num();
    t = num();
    a = num();
    for(i=0; i<n; i++){
        h[i] = num();
    }
    
        for(i=0; i<n; i++){
            x = t-h[i]*0.006;
            y = a-x;
            if(y < 0)
                y = y*-1;
            if(y <= z){
                z = y;
                c = i;
            }
        }
    c++;
    printf("%d\n", c);
    
    return 0;
    
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static Scanner scan = new Scanner(System.in);
	static long H = scan.nextLong();
	static long min = 0;
	//static long []memo = new long[H+1];
	//static boolean []check = new boolean[H+1];
	static Set<Long> memo = new HashSet<Long>();
	static Map<Long,Long> me = new HashMap<Long,Long>();
	static ArrayList<Long> meno = new ArrayList<Long>();
	static Set<Boolean> cheak = new HashSet<Boolean>();
	
	public static void main(String[]args) {
		
			
			
			
			
			System.out.println(monster(H));
			
			
			
			
		
		
		
	}

	private static long monster(long h) {
		
		
		if(h==1) {
			
			return 1;	
		}else {
			long k = h/2;
			return 1+2*monster(k);
			
			
		}
		}
}

Measured memory_bytes: 23124
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >> s;
  int counter = 0;
  if(s[0] == '9') {
    counter = 1;
  }if(s[1] == '9') {
    counter = 1;
  }
  
  if(counter == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
 
 long int a,b;
  int i,k;
  scanf("%ld %ld %d",&a,&b,&k);
  
  for(i=0;i<k;i++){
    if(i%2==0){
      if(a%2==1){
        a=a-1;
      }
      a=a/2;
      b=b+a;
    }
    
    else {
      if(b%2==1){
        b=b-1;
      }
      b=b/2;
      a=b+a;
    }
  }
    
      
      printf("%ld %ld",a,b);
    
  
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#define N (100+5)
using namespace std;

short n,m,line[N][N],list[N][N],f[N][N][N][N],sx,sy,ans;
char a[N][N];

int main()
{
	cin>>n>>m;
	for (short i=1; i<=n; ++i)
		scanf("%s",a[i]+1);
	for (short i=1; i<=n; ++i)
		for (short j=1; j<=m; ++j)
		{
			line[i][j]=line[i][j-1]+(a[i][j]=='o');
			list[i][j]=list[i-1][j]+(a[i][j]=='o');
			if (a[i][j]=='E') sx=i,sy=j;
		}
	for (short i=sx; i>=1; --i)
		for (short j=sy; j>=1; --j)
			for (short k=sx; k<=n; ++k)
				for (short l=sy; l<=m; ++l)
				{
					if (i>1 && k-sx<i-1)
						f[i-1][j][k][l]=max((int)f[i-1][j][k][l],f[i][j][k][l]+line[i-1][min((int)l,m-sy+j)]-line[i-1][max(j-1,l-sy)]);                  
					if (k<n && sx+k<n+i)
						f[i][j][k+1][l]=max((int)f[i][j][k+1][l],f[i][j][k][l]+line[k+1][min((int)l,m-sy+j)]-line[k+1][max(j-1,l-sy)]);
					if (j>1 && l-sy<j-1)
						f[i][j-1][k][l]=max((int)f[i][j-1][k][l],f[i][j][k][l]+list[min((int)k,n-sx+i)][j-1]-list[max(i-1,k-sx)][j-1]);
					if (l<m && sy+l<m+j)
						f[i][j][k][l+1]=max((int)f[i][j][k][l+1],f[i][j][k][l]+list[min((int)k,n-sx+i)][l+1]-list[max(i-1,k-sx)][l+1]);
					short now=max(max(f[i-1][j][k][l],f[i][j][k+1][l]),max(f[i][j-1][k][l],f[i][j][k][l+1]));
					ans=max(ans,now);
				}
	cout<<ans;
}

Measured memory_bytes: 227584
import java.util.Scanner;

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

        int count = 0;
        String key = sc.next();
        key = key.toLowerCase();

        String read = sc.next();
        while(!(read.equals("END_OF_TEXT"))){
            read = read.toLowerCase();
            if(read.equals(key))
                count++;
            read = sc.next();
        }
        System.out.println(count);

        sc.close();
    }
}


Measured memory_bytes: 26104
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;




int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    ll pre[n];
    pre[0] = a[0] % k;
    for (int i = 1; i < n; i++) pre[i] = (pre[i - 1] + a[i]) % k;
    ll ans = 0;

    map<ll, int> d;
    for (int i = 0; i < n; i++) {
        ll here = (((pre[i] - i) % k) + k) % k;
        ans += (pre[i] == i + 1) + d[here];
        d[here]++;
        if (i - k + 1 >= 0) {
            ll prev = (((pre[i - k + 1] - (i - k + 1)) % k) + k) % k;
            d[prev]--;
        }

    }

    cout << ans;

}


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

void makeVec(priority_queue<long long> &que, long long len){
    for(long long i = 0; i < len; i++){
        long long tmp;
        cin >> tmp;
        que.push(tmp);
    }
    return;
}

int main(){
    long long x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    priority_queue<long long> p, q, r;
    makeVec(p, a);
    makeVec(q, b);
    makeVec(r, c);

    long long ans = 0;
    for(int i = 0; i < x; i++){
        r.push(p.top());
        p.pop();
    }
    for(int i = 0; i < y; i++){
        r.push(q.top());
        q.pop();
    }
    for(int i = 0; i < x + y; i++){
        ans += r.top();
        r.pop();
    }
    // long long ateRed = 0, ateGreen = 0;
    // for(long long i = 0; i < x + y; i++){
    //     long long red, green, white;
    //     if(ateRed != x){
    //         red = p.top();
    //     }
    //     else{
    //         red = 0;
    //     }
    //     if(ateGreen != y){
    //         green = q.top();
    //     }
    //     else{
    //         green = 0;
    //     }
    //     if(!r.empty()){
    //         white = r.top();
    //     }
    //     else{
    //         white = 0;
    //     }
    //     // when red is the greatest.
    //     // eat red apple.
    //     if(red >= green && red >= white){
    //         ateRed++;
    //         ans += red;
    //         p.pop();
    //     }
    //     //when green is the greatest.
    //     //eat green apple.
    //     else if(green > red && green >= white){
    //         ateGreen++;
    //         ans += green;
    //         q.pop();
    //     }
    //     //when white is the greatest.
    //     //eat white apple.
    //     else if(white > red && white > green){
    //         ans += white;
    //         r.pop();
    //         long long rw, gw;
    //         rw = white - red;
    //         gw = white - green;
    //         if(rw >= gw){
    //             ateRed++;

    //         }
    //         else{
    //             ateGreen++;
    //         }
    //     }
    // }
    // for(long long i = 0; i < x; i++){
    //     long long red, white;
    //     red = p.top();
    //     white = r.top();
    //     if(red >= white){
    //         ans += red;
    //         p.pop();
    //     }
    //     else{
    //         ans += white;
    //         r.pop();
    //     }
    // }
    // for(long long i = 0; i < y; i++){
    //     long long green, white;
    //     green = q.top();
    //     white = r.top();
    //     if(green >= white){
    //         ans += green;
    //         q.pop();
    //     }
    //     else{
    //         ans += white;
    //         r.pop();
    //     }
    // }

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

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

int main(){
    unsigned long long N;
    cin >> N;
    vector<unsigned long long> v;
    for(unsigned long long i = 0, a; i < N; ++i){
        cin >> a;
        --a;
        if(i < a)return 0 & puts("-1");
        v.insert(v.begin() + a, a + 1);
    }
    for(const auto& i : v)cout << i << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a = new int[N];
		for( int i=0; i<N; i++ ){
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		long ans = 0;      
		if( N%2==1 ){
			if( N==1 && a[0]==0 ){
				ans = 1;              
            }           
			for( int i=1; i<N; i+=2 ){
				if( a[i]!=a[i+1] && a[i]!=i+1 ){
					ans = 0;		
					break;
				}      
				if( i==N-2 && a[0]==0 ){
					ans = 2;
					for( int j=0; j<N/2-1; j++ ){
						ans = 2*ans;
						if(ans>1000000007L){
							ans = ans%1000000007L; 
						}
					}             
				}
			}  
		}
		if( N%2==0 ){
			for( int i=0; i<N; i+=2 ){
				if( !( a[i]==a[i+1] && a[i]==i+1 ) ){
					ans = 0;
					break;
				}
				if( i==N-2 ){
					ans = 2;
					for( int j=0; j<N/2-1; j++ ){
						ans = 2*ans;
						if(ans>1000000007L){
							ans = ans%1000000007L;
						}
					}                 
				}
			}
		}  
		System.out.println(ans);
	}
}


Measured memory_bytes: 51664
N = int(input())

if 0 <= N <= 9:
    print(N)
else:
    ans = 9
    for i in range(11, N+1):
        if i % 10 == 0:
            continue
        if i < 100:
            if int(str(i)[0]) == i % 10:
                ans += 3  # その1桁、1桁の逆パターン、そのもの
            elif (i % 10)*10+(i//10) <= N:
                ans += 1
            continue
        if int(str(i)[0]) == i % 10:
            ans += 5  # その1桁、1桁の逆パターン、その2桁、2桁の逆パターン、そのもの
            ans += ((i - (int(str(i)[0]) *
                          (10 ** (len(str(i)) - 1)))) // 10) * 2
            # print(
            #    i, ((i - (int(str(i)[0]) * (10 ** (len(str(i)) - 1)))) // 10) * 2)
            for j in range(1, len(str(i)) - 2):
                ans += (10 ** j) * 2

        elif int(str(i)[0]) > i % 10:
            for k in range(len(str(i)) - 1):
                ans += (10 ** k) * 2
        else:
            for h in range(len(str(i)) - 2):
                ans += (10**h)*2
    print(ans)


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

int main() {
    int n,m,i,j,p,t,x,r;
    cin >> n >> m;
    vector<int> c(m),dp(n+1,1e6+10);
    for(i=0; i<m; i++)
        cin >> c.at(i);
    
    dp.at(0) = 0;
    for(i=0; i<n; i++)
        for(j=0; j<m; j++)
            if(i+c.at(j) <= n)
                dp.at(i+c.at(j)) = min(dp.at(i+c.at(j)), dp.at(i)+1);

    cout << dp.at(n) << endl;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string s, t;
  cin >> s ;
  t = s;
  reverse(ALL(s));
  if (s == t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
    int n;
    ll ans = 0;
    cin >> n;
    vector<int> a(n+1), b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];

    rep(i,n) {
        if (a[i] >= b[i]) ans += b[i];
        else {
            ans += a[i];
            if (a[i+1] > b[i] - a[i]) {
                ans += b[i] - a[i];
                a[i+1] -= (b[i] - a[i]);
            } else {
                ans += a[i+1];
                a[i+1] = 0;
            }
            
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4024
#include <stdio.h>

int main(void){
	int n,m,l,i,j,k;
	long long a[102][102]={0};
	long long b[102][102]={0};
	long long c[102][102]={0};
	scanf("%d %d %d",&n,&m,&l);
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%d",&b[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			for(k=0;k<m;k++){
				c[i][j]+=a[i][k]*b[k][j];
			}	
		}
	}
		
		
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
		if(j==l-1){
			printf("%lld",c[i][j]);
		}else{
			printf("%lld ",c[i][j]);
		}
		
	}printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using l = long;
using ul = unsigned long;
#define re(i,n) for (ll i = 0; i < (n); ++i)
#define itn int
#define ocut cout
#define ouct cout
#define outc cout
int main(){
    char s;
    cin >> s;
    s++;
    cout << s;
}

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

int N, X, M = INT_MAX;

int main() {
  cin >> N >> X;
  for(int i = 0; i < N; ++i) {
    int m; cin >> m; X -= m; if(m < M) M = m;
  }
  cout << N + X / M << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int cnt[1000];
int main()
{
	int n,k; cin>>n>>k;
	while(k--){
		int t; cin>>t;
		for(int i=1;i<=t;i++){
			int m; cin>>m;
			cnt[m]++; 
		}
	}
	int ans=0;
	for(int i=1;i<=200;i++) ans+=cnt[i]>0;
	cout<<n-ans<<endl; 
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
int n, d, x[11][11], p, q, res;
int main() {
    DAU
    cin >> n >> d;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= d; ++j)
            cin >> x[i][j];
    for (int i = 1; i < n; ++i)
        for (int j = i + 1; j <= n; ++j) {
            p = 0;
            for (int k = 1; k <= d; ++k)
                p += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            q = sqrt(p);
            res += (q * q == p);
        }
    cout << res;
    PLEC
}


Measured memory_bytes: 3632
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

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

  int N, M;
  long long int temp;
  cin >> N >> M;
  priority_queue<long long int> q;
  for (int i = 0; i < N; i++) {
    cin >> temp;
    q.push(temp);
  }
  for (int i = 0; i < M; i++) {
    temp = q.top() / 2;
    q.pop();
    q.push(temp);
  }

  temp = 0;
  while (!q.empty()) {
    temp += q.top();
    q.pop();
  }

  cout << temp << endl;

  return 0;
}


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

const int mod = 10000;
string x;
int m,memo[510][510][10][2][3];

int dp(int keta,int d,int bef,bool sml,int zig){
    
    if(keta == x.size()) return d==0;
    if(memo[keta][d][bef][sml][zig] != -1) return memo[keta][d][bef][sml][zig];
    
    int n = sml?9:(x[keta]-'0');
    int res = 0;
    for(int i=0;i<=n;i++){
        
        if(zig == 2){
            if(i == 0) res = ( res+dp(keta+1,(d*10+i)%m,i,sml|(i<n),2) )%mod;
            else{
                res = ( res+dp(keta+1,(d*10+i)%m,i,sml|(i<n),bef<i) )%mod;
                if(keta < x.size()-1) res = ( res+dp(keta+1,(d*10+i)%m,i,sml|(i<n),bef>i) )%mod;   
            }
            continue;
        }
        if(zig == 0 && i <= bef) continue;
        if(zig == 1 && bef <= i) continue;
        res = ( res+dp(keta+1,(d*10+i)%m,i,sml|(i<n),!zig) )%mod;
        
    }
    
    return memo[keta][d][bef][sml][zig] = res;
}

int main()
{
    string a,b;
    int ans;
    
    cin >> a >> b;
    cin >> m;
    
    x = b;
    fill_n(****memo,510*510*10*2*3,-1);
    ans = dp(0,0,0,0,2)+mod;
    
    for(int i=a.size()-1;i>=0;i--){
        if(a[i] == '0') a[i] = '9';
        else {
            a[i]--;
            break;
        }
    }
    
    x = a;
    fill_n(****memo,510*510*10*2*3,-1);
    ans -= dp(0,0,0,0,2);
    
    cout << ans%mod << endl;
    return 0;
}



Measured memory_bytes: 64164
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int R;
    cin >> R;
    printf("%f\n", 2 * R * 3.14159265359);
    return 0;
}


Measured memory_bytes: 3700
fn to_index(x: i64, y: i64, r: i64, c: i64) -> i64 {
    if x == 0 {
        return y;
    } else if y == c {
        return c + x;
    } else if x == r {
        return c + r + (c - y);
    } else if y == 0 {
        return c + r + c + (r - x);
    }
    unreachable!();
}

fn main() {
    let v = read_vec::<i64>();
    let (r, c, n) = (v[0], v[1], v[2] as usize);
    let mut pairs = vec![];
    for _ in 0..n {
        let v = read_vec::<i64>();
        let (x1, y1, x2, y2) = (v[0], v[1], v[2], v[3]);
        if (x1 == 0 || x1 == r || y1 == 0 || y1 == c) && (x2 == 0 || x2 == r || y2 == 0 || y2 == c)
        {
            pairs.push((x1, y1, x2, y2));
        }
    }

    let mut indexes = vec![];
    for (i, (x1, y1, x2, y2)) in pairs.into_iter().enumerate() {
        indexes.push((to_index(x1, y1, r, c), i));
        indexes.push((to_index(x2, y2, r, c), i));
    }
    indexes.sort();

    let mut found_stack = vec![];
    for (_, idx) in indexes {
        if found_stack.is_empty() || found_stack[found_stack.len() - 1] != idx {
            found_stack.push(idx);
        } else {
            found_stack.pop();
        }
    }
    if found_stack.is_empty() {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 13376
#include<bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using vl=vector<ll>;
using vp=vector<pll>;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll a[n+5];
    FOR(i,1,n) cin>>a[i];
    ll s=1,e=0;
    FOR(i,1,n) e=max(e,a[i]);
    ll ans=e;
    while(s<=e){
        ll m=s+e>>1;
        ll cnt=0;
        FOR(i,1,n) cnt+=(a[i]+m-1)/m-1;
        if(k>=cnt){
            ans=m;
            e=m-1;
        }
        else s=m+1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5128
import numpy as np
N,K = map(int,input().split())
a = list(int(i) for i in input().split())
res = [0]*(K+1)
for i in range(K):
  for k in a:
    if res[i] == 0:
      if i+k > K:
        break
      else:
        res[i+k] =1
if res[-1] == 1:
  print('First')
else:
  print('Second')

Measured memory_bytes: 13816
/* Hello darkness my old friend, I've come to visit you again! */

#include<bits/stdc++.h>
#define lli long long int
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORB(i,b,a) for(i=b;i>=a;i--)
#define mod 1000000007
#define PI 2*acos(0.0)
#define gs getline(cin,s)
#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pb push_back
#define eb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 1000000005
#define INF 1000000000000000005
#define io ios_base::sync_with_stdio(0);
#define ff first
#define ss second
using namespace std;
vector <int> v1[35],v2[35],v3[35];
int d[35][35],a[505][505],c;
int val(int c1,int c2,int c3)
{
    int s1,s2,s3,i;
    s1=s2=s3=0;
    FOR(i,1,c+1)
    {
        s1+=v1[i].size()*d[i][c1];
        s2+=v2[i].size()*d[i][c2];
        s3+=v3[i].size()*d[i][c3];
    }
    return s1+s2+s3;
}
int main()
{
    io;
    cin.tie(0);
    cout.tie(0);
    int n,i,j,k;
    cin>>n>>c;
    FOR(i,1,c+1)
    {
        FOR(j,1,c+1)
        cin>>d[i][j];
    }
    FOR(i,1,n+1)
    {
        FOR(j,1,n+1)
        {
            cin>>a[i][j];
            if((i+j)%3==0)
                v1[a[i][j]].pb(1);
            else if((i+j)%3==1)
                v2[a[i][j]].pb(1);
            else
                v3[a[i][j]].pb(1);
        }
    }
    int mn=INT_MAX;
    FOR(i,1,c-1)
    {
        FOR(j,i+1,c)
        {
            FOR(k,j+1,c+1)
            {
                int sum=val(i,j,k);
                sum=min(sum,val(i,k,j));
                sum=min(sum,val(j,i,k));
                sum=min(sum,val(j,k,i));
                sum=min(sum,val(k,i,j));
                sum=min(sum,val(k,j,i));
                mn=min(mn,sum);
            }
        }
    }
    cout<<mn;
    return 0;
}

/* This is the end, beautiful friend! */


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long int> arr1(n), arr2(n);
    for(int i = 0; i < n; i++){
        long long int x, y;
        cin >> x >> y;
        arr1[i] = x + y;
        arr2[i] = x - y;
    }
    sort(arr1.begin(), arr1.end());
    sort(arr2.begin(), arr2.end());
    long long int maybe = abs(arr1.back() - arr1[0]);
    maybe = max(maybe, abs(arr2.back() - arr2[0]));
    cout << maybe << "\n";
    return 0;
}

Measured memory_bytes: 6420
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  char q;
  cin>>q;
  if(q=='A') COUT('T');
  else if(q=='T') COUT('A');
  else if(q=='G') COUT('C');
  else if(q=='C') COUT('G');
}


Measured memory_bytes: 256
if __name__ =="__main__":
    S = input()
    N = len(S)
    ans=0

    for i in range(N):
        for j in range(i,N):
            if all('ACGT'.count(c)==1 for c in S[i:j+1]):
                ans = max(ans,j-i+1)
    print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>

using namespace std;

int main(){

    int N, L;
    cin >> N >> L;
    string S[N];
    for(int i=0; i<N; ++i){
        cin >> S[i];
    }
    sort(S, S+N);
    for(int i=0; i<N; ++i){
        cout << S[i];
    }
    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string C[2];

int main()
{
  rep( i, 2 )
    std::cin >> C[i];

  bool fl = true;

  rep( i, 2 ) rep( j, 3 )
    fl &= C[i][j] == C[1-i][2-j];

  puts( fl ? "YES" : "NO" );

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

 ll n,k=0;
  cin >> n;
  vll x(n);
  
  rep(i,0,n) {
    cin >> x[i];
    k+=x[i]; 
  }
    
  
 ll res=0; 
 ll ave=k/n;
  rep(i,0,n) res+=(x[i]-ave)*(x[i]-ave);
  
 ll ans=0;
 ave++;
  rep(i,0,n) ans+=(x[i]-ave)*(x[i]-ave);
  
  cout << min(res,ans) << endl;
  
  
  
}


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

using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
ll MOD = 1000000007;

int A[100000];
int B[100000];
int C[100000];

int main() {
	ll N; cin >> N;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) cin >> B[i];
	rep(i, 0, N) cin >> C[i];

	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);
	ll cnt = 0;
	rep(i, 0, N) {
		cnt += (lower_bound(A, A + N, B[i]) - A) *
			(N - (upper_bound(C, C + N, B[i]) - C));
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1408
/* AtCoder Beginner Contest abc128
 * Problem C
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main(void) {
	int n, m;
	cin >> n >> m;
	vector <vector <int>> s(m);
	vector <int> p(m);
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		while (k--) {
			int cn;
			cin >> cn;
			s[i].push_back(cn - 1);
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	int ans = 0;
	vector <int> sta(10);
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j <= 9; j++) {
			sta[j] = i & (1 << j);
		}
		bool all = true;
		for (int j = 0; j < m; j++) {
			int l = 0;
			for (auto e: s[j]) {
				if (sta[e]) {
					l++;
				}
			}
			if (l % 2 != p[j]) {
				all = false;
				break;
			}
		}
		if (all) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

bool check(int N,string W[]){
    for(int i=1;i<N;i++){
        if(W[i-1].back()!=W[i].front()){
            return false;
        }
        for(int j=0;j<N;j++){
            if(W[i]==W[j]){
                if(i==j) continue;
                return false;
            }
        }
    }
    return true;
}

int main(){
    int N;
    string W[200];
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>W[i];
    }
    if(check(N,W)){
         cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
    

}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
// #include <string>
// #include <algorithm>
// #include <numeric>
// #include <queue>
// #include <cmath>
// #include <set>
// #include <map>
// #include <iomanip>

// #define MOD 1000000007
// #define INF 1000000001

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

void p_() {
    cout << "\n";
}
template<class Head, class... Body>
void p_(Head head, Body... body) {
    cout << head << ",";
    p_(body...);
}


int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    list<int> b;
    bool flipped = false;
    for (int i = 0; i < n; ++i) {
        if (!flipped) {
            b.push_back(a[i]);
        } else {
            b.push_front(a[i]);
        }
        flipped = !flipped;
    }

    if (!flipped) {
        for (auto itr = b.begin(); itr != b.end(); ++itr) {
            if (itr != b.begin()) cout << " ";
            cout << *itr;
        }
    } else {
        for (auto itr = b.rbegin(); itr != b.rend(); ++itr) {
            if (itr != b.rbegin()) cout << " ";
            cout << *itr;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 9216
# coding: utf-8
S = gets.chomp!

def pal?(word)
  word = word.to_s
  size = word.length / 2
  return ( word[0..size] == word.reverse[0..size] )
end  

midp1 = ((S.size-1)/2)-1
midp2 = ((S.size+3)/2)-1

if pal?(S)
  if pal?(S[0..midp1]) and pal?(S[midp2..S.size-1])
    puts 'Yes'
  else
    puts 'No'
  end
else
  puts 'No'
end


Measured memory_bytes: 1788
import sys
input = sys.stdin.readline

def main():
    s = input().strip()

    for i in range(len(s) - 1):
        if s[i] == s[i+1]:
            print(i+1, i+2)
            return
        if i < len(s) - 2:
            if s[i] == s[i+2]:
                print(i+1, i+3)
                return
    
    print(-1, -1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<bool, bool> pbb;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define fill(x, k) memset(x, k, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y , true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y , true) : false; }
void __init()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(16);
    srand(time(0) ^ ui(ul(new char)));
}
/* default code ends here */
#define maxn 100100
int n, m;
vi h[maxn];
int du[maxn];
void no()
{
	cout << "No\n";
	exit(0);
}
void yes()
{
	cout << "Yes\n";
	exit(0);
}
bool vis[maxn];
int dfs(int x, int y)
{
	if(x == y)
		return 1;
	vis[x] = true;
	int ret = 0;
	for(int v : h[x])
		if(!vis[v])
			ret += dfs(v, y);
	return ret;
}
int main()
{
	__init();
	cin >> n >> m;
	if(m <= n + 1)
		no();
	int u, v;
	enum(i, 1, m)
	{
		cin >> u >> v;
		h[u].pb(v);
		h[v].pb(u);
		du[u] ++;
		du[v] ++;
	}
	enum(i, 1, n)
		if(du[i] & 1)
			no();
	pii m1 = pii(0, 0), m2 = m1, m3 = m2;
	enum(i, 1, n)
	{
		pii p = pii(du[i], i);
		if(p > m1)
		{
			m3 = m2;
			m2 = m1;
			m1 = p;
		}
		else if(p > m2)
		{
			m3 = m2;
			m2 = p;
		}
		else if(p > m3)
			m3 = p;
	}
	if(m1.fi >= 6 || m3.fi == 4)
		yes();
	if(m2.fi < 4)
		no();
	if(dfs(m1.se, m2.se) == 2)
		yes();
	no();
	return 0;
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
//#define int long long
#define f(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define mi map<int,int>
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define fv(i,v) for(auto i=v.begin();i!=v.end();++i)
#define fdv(i,v) for(auto i=v.rbegin();i!=v.rend();--i)
#define print(a,n) f(i,1,n) cout<<a[i]<<" "; cout<<endl;
#define printv(v) for(auto i: v) cout<<i<<" "; cout<<endl;
#define r(a,n) int a[n+1]; f(i,1,n) cin>>a[i];
#define pi 3.141592653589793238
const int mod=1e9+7;
const int inf=1e18;
int vis[1000][1000]={};

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
    if(a.se==b.se)
        return a.fi<b.fi;
}

int power(int x, unsigned int y)
{
    int res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

int Remainder(string str, int R)
{
    // len is variable to store the
    // length of Number string.
    int len = str.length();

    int Num, Rem = 0;

    // loop that find Remainder
    for (int i = 0; i < len; i++) {

        Num = Rem * 10 + (str[i] - '0');
        Rem = Num % R;
    }

    // Return the remainder
    return Rem;
}

signed main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        int sum=0;
        if(a>0&&k>0)
        {if(a<=k)
            {
                k-=a;
                sum+=a;
            }
        else
            {
                sum+=k;
                k=0;
            }
        }
        if(b>0&&k>0)
        {if(b<=k)
            {
                k-=b;
            }
        else
            {
                k=0;
            }
        }
        if(c>0&&k>0)
        {if(c<=k)
            {
                sum-=c;
            }
        else
            {
                sum-=k;
            }
        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 3592
s = input()
k = int(input())
lis = ['z'*(5001+i) for i in range(k)]
for i in range(len(s)):
  c = s[i]
  if lis[-1] > c:
    lis.append(c)
    lis = set(lis)
    lis = sorted(lis)[:k]
  else:
    continue
  for j in range(i+1,len(s)):
    if lis[-1] > c:
      c += s[j]
      lis.append(c)
      lis = set(lis)
      lis = sorted(lis)[:k]
    else:
      break
print(lis[-1])

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

int main() {
  vector <int> a(4);
  for(int i=0;i<4;i++){
    cin>>a.at(i);
  }
  sort(a.rbegin(),a.rend());
  if(a.at(0)==9&&a.at(1)==7&&a.at(2)==4&&a.at(3)==1){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
def main():
    N, H = map(int, input().split())
    a = [0 for _ in range(N)]
    b = [0 for _ in range(N)]
    for i in range(N):
        a[i], b[i] = map(int, input().split())

    b.sort()
    b = b[::-1]
    A = max(a)
    count = 0
    for i in range(N):
        if b[i]>A:
            count += 1
            H = H - b[i]
            if H <= 0:
                return count
    
    if H%A==0:
        return count + H//A
    else:
        return count + H//A + 1

if __name__ == "__main__":
    print(main())


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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0)break;
        int sum = 0, num;
        for(int i = 0; i < n / 4; i++){
            cin >> num;
            sum += num;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
N = int(input())

T = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

kakutei = [-1]* N
for i,a in enumerate(A):
    if i==N-1:
        kakutei[i]= a
        continue
    if a > A[i+1]:
        kakutei[i]=a

for i,t in enumerate(T):
    if i==0:
        kakutei[i]=t
        continue
    if t > T[i-1]:
        if kakutei[i]==-1 or kakutei[i]==t:
            kakutei[i] = t
        else:
            print(0)
            exit(0)

ans = 1
for i in range(N):
    if not(kakutei[i] <= A[i] and kakutei[i] <= T[i]):
        print(0)
        exit(0)
    if kakutei[i]==-1:
        ans*= min(A[i],T[i])
        ans= ans%(10**9 +7)

print(ans)



Measured memory_bytes: 18924
import sys; readline = sys.stdin.readline
from collections import deque

t1, t2 = map(int, readline().split())
a1, a2 = map(int, readline().split())
b1, b2 = map(int, readline().split())

T = t1 + t2

avgA = t1 * a1 + t2 * a2
avgB = t1 * b1 + t2 * b2
if avgA == avgB:
    print('infinity')
    exit(0)

if avgA < avgB:
    a1, a2, b1, b2 = b1, b2, a1, a2
    avgA, avgB = avgB, avgA

d1 = a1 - b1
d2 = a2 - b2

if d1 > 0:
    print(0)
    exit(0)

y0 =  -d1 * t1
dy = (avgA - avgB)

n = y0 // dy

if y0 % dy == 0:
    print((n + 1) * 2 - 2)
else:
    print((n + 1) * 2 - 1)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

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

  priority_queue <ll> que;

  for (int i = 0; i < N; i++){
    ll A; cin >> A;
    que.push(A);
  }
  
  for (int i = 0; i < M; i++){
    ll A = que.top(); que.pop();
    que.push(A / 2);
  }
  
  ll ans = 0;
  for (int i = 0; i < N; i++){
    ll A = que.top(); que.pop();
    ans += A;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int dp[100005];
//int mx=INT_MIN;
int solve(int i){
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    return dp[n-1];
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<solve(0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>A>>B;
    cout<<max(0LL, A - B*2)<<endl;
}

Measured memory_bytes: 256