akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;

int main() {FIN

	int n, i;
	cin >> n;
	vi hs(n), dp(n);
	
	for (i = 0; i < n; i++)
		cin >> hs[i];

	for (i = 0; i < n; i++) {
		if (i > 0) {
			dp[i] = dp[i - 1] + abs(hs[i] - hs[i - 1]);
			if (i > 1)
				dp[i] = min(dp[i], dp[i - 2] + abs(hs[i] - hs[i - 2]));
		}
	}

	cout << dp[n - 1] << "\n";

	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll C[1000];
ll V[1000];

int main() {
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> V[i];
    }
    REP(i, N) {
        cin >> C[i];
    }

    ll max = 0;
    REP(p, pow(2LL, N )) {
        ll c = 0, v = 0;
        REP(i, N) {
            if (((p >> i) & 1) == 1) {
                c += C[i];
                v += V[i];
            }
        }
        max = std::max(max, v - c);
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);
  if (a * b % 2 == 0)
    printf("No\n");
  else 
    printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main(void){
    int x,y;
    while(true) {
        cin >> x;
        cin >> y;
        if(x == 0 && y == 0) {
            break;
        }
        if(x < y){
            cout << x << " " << y << endl;
        }
        else {
            cout << y << " " << x << endl;
        }
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	map<int, int> mp;
	vector<int> a(n);
	ll sum = 0;
	rep (i, n) {
	  cin >> a[i];
	  sum += mp[a[i]];
	  mp[a[i]]++;
	}
	rep (i, n) {
	  ll res = sum;
	  res -= (ll)mp[a[i]] * (mp[a[i]] - 1) / 2;
	  res += (ll)(mp[a[i]] - 1) * (mp[a[i]] - 2) / 2;
	  cout << res << endl;
	}
	
    return 0;
}



Measured memory_bytes: 10064
#include<stdio.h>
int main(){
	int i;
	char a[21];
	for(i=0;;i++){
		scanf("%c",&a[i]);
		if(a[i]=='\n'){
			break;
		}
	}
	i-=1;
	for(;i>=0;i--){
		printf("%c",a[i]);
	}
        printf("\n");
	return 0;
}

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

string a, b;
int main(){
	cin >> a;
	int sez=a.length();
	for(int i=0;i<sez;i++){
		if (a[i]=='A') b.push_back('T');
		else if (a[i]=='T') b.push_back('A');
		else if (a[i]=='G') b.push_back('C');
		else b.push_back('G');
	}
	cout << b << "\n";
}


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

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

  vector<pair<long long, int>> pairs(N);
  for (int i = 0; i < N; i++) {
    long long A;
    int B;
    cin >> A >> B;
    pairs[i] = make_pair(A, B);
  }

  sort(pairs.begin(), pairs.end());

  int buys = 0;
  int index = 0;
  int overbuys;
  long long ans = 0;

  while (buys < M) {
    buys += pairs[index].second;
    ans += (pairs[index].first * pairs[index].second);
    if (buys >= M) {
      break;
    }
    index += 1;
  }

  ans -= ((buys - M) * pairs[index].first);

  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main()
{
  int S;

  cin >> S;

  int h,m,s;
  int temp;

  h = S / 3600;
  temp = S % 3600;
  m = temp / 60;
  s= temp % 60;

  cout << h << ":" << m << ":" << s << "\n";
}

Measured memory_bytes: 3120
# -*- coding: utf-8 -*-
#D - Lazy Faith
import sys
from bisect import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
A, B, Q = map(int, readline().split())
INF = 10**31
S = [-INF]
for _ in range(A):
    s = int(readline())
    S.append(s)
S.append(INF)
T = [-INF]
for _ in range(B):
    t = int(readline())
    T.append(t)
T.append(INF)

for _ in range(Q):
    x = int(readline())
    ind_s = bisect(S,x)
    ind_t = bisect(T,x)
    s1,s2 = S[ind_s-1],S[ind_s]
    t1,t2 = T[ind_t-1],T[ind_t]
    d1 = (x-s1) + (t2-s1) if x-s1 < t2-x else (t2-x) + (t2-s1)
    d2 = (x-t1) + (s2-t1) if x-t1 < s2-x else (s2-x) + (s2-t1)
    d3 = x-s1 if s1 < t1 else x-t1
    d4 = t2-x if s2 < t2 else s2-x
    ans = min(d1,d2,d3,d4)
    print(ans)    

Measured memory_bytes: 109416
using System;

namespace ITP1_3_B {
    class Program {
        static void Main(string[] args) {
            int i = 0;
            while(true) {
                i++;
                int n = int.Parse(Console.ReadLine());
                if(n == 0)
                    break;
                Console.WriteLine("Case {0}: {1}", i, n);
            }
        }
    }
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;

ll pow(ll a, ll n, ll m) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a % m) {
		if (n % 2LL == 1LL) {
			ret = ret * a % m;
		}
	}
	return ret;
}


int main() {
  ll X, Y;
  cin >> X >> Y;
  ll ans;
  if((2*X-Y)%3LL != 0LL) ans = 0LL;
  else {
    ll a = (2LL*Y -X) /3LL;
    ll b = (2LL*X - Y)/3LL;
    if(a<0||b<0) ans=0LL;
    else{
      ans = 1LL;
      for(ll i = 0LL; i < a; i++) {
        ans *= a+b -i;
        ans %= mod;
        ans *= pow(i+1,mod-2,mod);
        ans%=mod;
      }
    }
  }
  cout<<ans<<endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <climits>
using namespace std;
int main(void){
    
    int N;
    int max_Num = 0; 
    string s;
    map<string, int> m;
    
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s;
        m[s]++;
    }
    
    for(auto b : m){
        auto value = b.second;
        max_Num = max(max_Num, value); 
    }    
    
    for(auto b : m){
        auto key = b.first;
        auto value = b.second;
        if(value == max_Num)
            cout << key << endl;
    }
}


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

A = [list(map(int,input().split())) for i in range(n)]
B= [int(input()) for i in range(m)]

for i in range(n):
    sum = 0
    for j in range(m):
        sum += A[i][j]*B[j]
    print(sum)


Measured memory_bytes: 6012
#include <bits/stdc++.h>
#define MAX 100

// トランプの絵柄・数字から
// 数字だけを取り出す
int SplitNumberFromTrump(std::string A)
{
    int num_trump = 0;
    num_trump = std::stoi(A.substr(1));
    return num_trump;
}

// 配列出力関数
void OutputArray(std::string A[], int N)
{
    for (int x=0; x<N-1; x++) {
        // 空白区切りで出力
        std::cout << A[x] << " ";
    }
    std::cout << A[N-1] << std::endl;
}

// ソートされた配列が
// 安定か調べる
// →バブルソートは安定なので
// それと比較
bool IsStableArray(std::string A[], std::string A_Origin[], int N)
{
    for (int i=0; i<N; i++) {
        if (A[i].compare(A_Origin[i])) return false;
    }
    return true;
}

// 結果出力
void DisplayResults(std::string A[], int N, std::string A_Origin[])
{
    OutputArray(A, N);
    std::string stable = (IsStableArray(A, A_Origin, N))?  "Stable" : "Not stable";
    std::cout << stable << std::endl;
}

// 選択ソート実行関数
void SelectionSort(std::string R[], int N)
{
    std::string R_Origin[MAX];
    std::copy(R, R + MAX, R_Origin);
    for (int i=0; i<N; i++) {
        // 初期化しないとRuntime Error
        int v = 0;
        int minVal = 100;
        for (int j=i; j<N; j++) {
            if (SplitNumberFromTrump(R[j]) < minVal) {
                minVal = SplitNumberFromTrump(R[j]);
                v = j;
            }
        }
        if (SplitNumberFromTrump(R[i]) != SplitNumberFromTrump(R[v])) {
            std::swap(R[i], R[v]);
        }
    }
}

// バブルソート実行関数
void BubbleSort(std::string R[], int N)
{
    std::string R_Origin[MAX];
    std::copy(R, R + MAX, R_Origin);

    // 隣接要素が存在するか
    bool bIsAnyNext = true;
    
    // 二重for文でも書ける
    while(bIsAnyNext) {
        bIsAnyNext = false;
        for (int i=N-1; 0<i; i--) {
            if(SplitNumberFromTrump(R[i]) < SplitNumberFromTrump(R[i-1])) {
                // 自前でswap関数を実装したら
                // TLEになったのでstdで
                std::swap(R[i], R[i-1]);
                bIsAnyNext = true;
            }
        }
    }
}

int main()
{
    int n;
    std::string R[MAX];
    std::cin >> n;
    
    for (int i=0; i<n; i++) std::cin >> R[i];

    // 配列のコピー
    int array_length = sizeof(R)/sizeof(R[0]);
    std::string R2[MAX];
    std::copy(R, R + MAX, R2);

    BubbleSort(R, n);
    OutputArray(R,n);
    //  バブルソートは安定ソート
    std::cout << "Stable" << std::endl;

    SelectionSort(R2, n);
    DisplayResults(R2, n ,R);
    return 0;
}


Measured memory_bytes: 3220
import java.util.*;
public class Main {
    public static void main(String [] args){
        Scanner input = new Scanner(System.in);
        
        int N = input.nextInt();
        int L = input.nextInt();
        
        String a[] = new String[N];
        String s;
        for(int i = 0; i <N; i++){
            s = input.next();
            //if(s.length()==L)
                a[i]=s;
        }
        Arrays.sort(a);
        for (String a1 : a) {
            System.out.print(a1);
        }
        
        System.out.println();
        
        /*
        for(int i = 0; i <a.length; i++)
             System.out.print(a[i]);
        */
    }
}


Measured memory_bytes: 29812
// B - An Odd Problem
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n; cin>>n;
	int c = 0, A[n];
	for(int i=0; i<n; i++) cin>>A[i];
	for(int i=0; i<n; i+=2) if(A[i]%2) c++;
	cout<< c <<endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = sc.nextInt();
		if(b<c || a>d) {
			System.out.println(0);
		}else if(c<=a) {
			System.out.println(Math.min(b,d)-a);
		}else if(b<=d) {
			System.out.println(b-Math.max(a, c));
		}else if(c<=b) {
			System.out.println(Math.min(b,d)-c);
		}else if(a<=d) {
			System.out.println(d-Math.max(a, c));
		}
	}
	public static int sample() {
		return 1;
	}

}


Measured memory_bytes: 23636
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r,g,b;
    cin>>r>>g>>b;
    int num=100*r+10*g+b;
    if(num%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

main() {
  int N, c, n;
  cin >> N;
  n = N;
  while(N>0){
    c += N%10;
    N /= 10;
  }
  if(n%c == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);


int main() {
  string a, b;
  cin >> a >> b;
  if(a.size()==b.size()){
    if(a>b) cout << "GREATER" << endl;
    else if(a<b) cout << "LESS" << endl;
    else cout << "EQUAL" << endl;
  }
  else if(a.size()>b.size()) cout << "GREATER" << endl;
  else cout << "LESS" << endl;
    
    return 0;
}

Measured memory_bytes: 256
fun main(arr:Array<String>) {
    val clockCount = readLine()!!.toInt()
    val clock = (1..clockCount).map { readLine()!!.toLong() }
    val ans = clock.reduce { acc, l -> getKoubai(acc,l) }
    println(ans)

}

fun getKouyaku(num1:Long, num2:Long):Long {
    if(num1 % num2 == 0L) {
        return num2
    }
    return getKouyaku(num2, num1%num2)
}

fun getKoubai(num1:Long, num2:Long):Long {
    val kouyaku = getKouyaku(num1, num2)
    return kouyaku * (num1/kouyaku) * (num2/kouyaku)
}

Measured memory_bytes: 33652
#include <cstdio>
#include <algorithm>
using namespace std;
int n, s, a[100005];
int main() {
	int i, j;
	scanf("%d", &n);
	for(i=0; i<n; i++) scanf("%d", &a[i]);
	sort(a, a+n);
	for(i=0; i<n; i=j) {
		for(j=i; j<n && a[j]==a[i]; j++);
		s += (j-i)%2;
	}
	printf("%d", s);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define vi vector<ll>
#define vivi vector<vector<ll>> 
#define vipa vector<pair<ll,ll>>
#define F first
#define S second
#define M 1000000007
#define kl endl

typedef long long ll;
void solve()
{
   string s;
   cin>>s;
   if(s[2]==s[3] && s[4]==s[5])
   {
       cout<<"Yes";
       return;
   }
   cout<<"No";
   
}
int  main() 
{ 
    ios;
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {   
        solve();
    }
	
	return 0; 
} 




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll ans = (n*(n-1))/2 + (m*(m-1))/2;
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ELEM(array)  (sizeof (array) / sizeof *(array))
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GCD(a,b) __gcd(a,b)
#define LCM(a,b) a/__gcd(a,b)*b
typedef long long ll;
typedef pair<int,int> Pii;


int main(){
    int n,k;cin>>n>>k;
    int ans=0;
    rep(i,n){
        int a;cin>>a;
        if(a>=k) ans++;
    }
    cout<<ans;
    return 0;
}

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

int main(){
  int N, cnt = 1;
  cin >> N;
  
  vector<int> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
  }
  
  sort(data.begin(), data.end());
  
  if (N != 1){
      for(int i = 0; i < N; i++){
        if(data.at(i) != data.at(i + 1)){
          cnt++;
        }
        if(i == N - 2){
          break;
        }
      }
  }
  
  cout << cnt << endl;
}
  

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0),cin.sync_with_stdio(0),cout.tie(0),cout.sync_with_stdio(0);
	int a, b;
	cin>>a>>b;
	if(abs(a-b)%2==1) return cout<<"IMPOSSIBLE", 0;
	if(a<b) swap(a,b);
	cout<<a+(b-a)/2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define lld long long int 
#define vint vector<int>
#define vlld vector<long long int>
#define vs vector<string>
#define ps push_back
#define pii pair<int,int>
#define vpii vector<pii>
#define vpll vector<pair<long long int , long long int>>
#define forl(i,a,b) for(int i = a ; i <= b ; i++)
#define forln(i,a,b) for(int i = a; i < b ; i++)
#define forb(i,b,a) for(int i = b ; i >= a ; i--)
#define forbn(i,b,a) for(int i = b ; i > a ; i--)
#define mk make_pair
#define le length
#define F first
#define S second
#define B begin
#define E end
#define in insert
#define len(str) lld len = str.length();
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define test()                  lld t; scanf("%d",&t); while(t--)
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)

lld power(lld x, lld y) 
{ lld temp; if( y == 0) return 1; temp = power((x%mod), (y%mod)/2); if (y%2 == 0) return ((temp%mod)*(temp%mod))%mod;else return (((x%mod)*(temp%mod))%mod*(temp%mod))%mod;} 

int main()
{ 
    int n,b ;
    cin>>n>>b;
    cout<<n*b<<endl;
  
 return 0;   
}

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

using namespace std;
constexpr double PI=3.14159265359;

int main(){
    double a,b,x;
    cin>>a>>b>>x;
    x/=a;
    cout<<fixed;
    cout<<setprecision(12);
    if(x*2<a*b){
        double c=(x*2)/b;
        double rad=atan2(c,b);
        cout<<90-(rad/PI*180)<<endl;
    }
    else{
        double c=(2*x)/a-b;
        c=b-c;
        double rad=atan2(a,c);
        cout<<90-(rad/PI*180)<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
import numpy as np
N = int(input())
d = int(np.sqrt(N))
d_max = 0
for i in range(1,d+1):
  if N % i == 0:
    d_max = i
if d_max > 9:
  print('No')
elif N / d_max > 9:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
template<typename T>void operator<<(vector<T>&vt,const T t){vt.push_back(t);}
template<typename T,typename U>istream&operator>>(istream&s,pair<T,U>&p){return s>>p.first>>p.second;}
template<typename T,typename U>ostream&operator<<(ostream&s,const pair<T,U>p){return s<<p.first<<" "<<p.second;}
#define all(x) x.begin(),x.end()
typedef pair<int,int>pii;

int p[100000];
int uni(int i){
	return p[i]!=i?p[i]=uni(p[i]):i;
}

pair<int,pii>dist(pii v,pii u){
	return {abs(v.first-u.first),{v.second,u.second}};
}

int N;
vector<pii>xi,yi;
vector<pair<int,pii>>E;

main(){
	cin>>N;
	for(int i=0;i<N;++i){
		int x,y;
		cin>>x>>y;
		xi<<(pii){x,i};
		yi<<(pii){y,i};
		p[i]=i;
	}
	sort(all(xi));
	sort(all(yi));
	for(int i=0;i<N-1;++i){
		E<<dist(xi[i],xi[i+1]);
		E<<dist(yi[i],yi[i+1]);
	}
	sort(all(E));
	long long a=0;
	for(auto e:E){
		int x=uni(e.second.first);
		int y=uni(e.second.second);
		if(x!=y){
			p[x]=y;
			a+=e.first;
		}
	}
	cout<<a;
}


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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


signed main(){
    string s;
    cin >> s;
    int n = s.size() + 1;
    vector<int> a(n, 0);
    vector<int> v(n, -1);
    queue<int> que;
    if(s.front() == '<'){
        v[0] = 0;
        que.push(0);
    }
    for(int i = 0; i < n - 1; ++i){
        if(s[i] == '>' && s[i + 1] == '<'){
            v[i + 1] = 0;
            que.push(i + 1);
        }
    }
    if(s.back() == '>'){
        v[n - 1] = 0;
        que.push(n - 1);
    }
    assert(!que.empty());
    while(!que.empty()){
        int to = que.front();
        que.pop();
        if(to != 0 && s[to - 1] == '>'){
            v[to - 1] = v[to] + 1;
            que.push(to - 1);
        }
        if(to != n - 1 && s[to] == '<'){
            v[to + 1] = v[to] + 1;
            que.push(to + 1);
        }
    }
    cout << accumulate(v.begin(), v.end(), 0LL) << endl;
}



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

int main(){
  int N;
  cin >> N;
  vector <int> st(3*N);
  for(int i=0;i < 3*N;i++){
    cin >> st[i];
  }
  sort(st.begin(),st.end());
  int64_t sum=0;
  for(int i=0;i<N;i++){
    sum +=st[N+2*i];
  }
  cout << sum;
}
  

Measured memory_bytes: 1408
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq

a,b,c,k=list(map(int,input().split()))

if a>=k:
    print(k)
    exit()
k-=a
ans=a

if b>=k:
    print(a)
    exit()

k-=b
print(a-k)

Measured memory_bytes: 27144
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] number = Console.ReadLine().Split(' ');
        string[] li = Console.ReadLine().Split(' ');
        List<int> l = new List<int>();
        int N = int.Parse(number[0]);
        int K = int.Parse(number[1]);
        int Length = 0;
        li.Cast<int>();
         foreach(string i in li)
        {
            l.Add(int.Parse(i));
        }
        l.Sort();
        l.Reverse();
        for(int i = 0;i <= K-1; i++)
        {
            Length += l[i];
        }
        Console.WriteLine(Length);
        
        
    }
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S, T; cin >> S >> T;
	if (S.size() + 1 == T.size() && S == T.substr(0, S.size())) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
    int data[5];
    for(int i=0; i<5; i++){
        cin >> data[i];
    }

    int count = 0;
    bool flag = false;
    int min = 100;
    for(int i=1; i<=9; i++){
        for(int j=0; j<5; j++){
            if(data[j]%10 == i){
                count += data[j];
                min = j;
                flag = true;
                break;
            }
        }
        if(flag) break;
    }

    for(int i=0; i<5; i++){
        if(i!=min){
            if(data[i]%10 == 0){
                count += data[i];
            }else{
                count += (data[i] + 10 -(data[i]%10));
            }
        }
    }

    cout << count << endl;
    return 0;
}

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

int main() {
  int N, H, W;
  cin >> N >> H >> W;
  int a, b, ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    if (H <= a && W <= b) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int find(string& S, char& c, int begin){
    for(int i = begin; i < S.size(); i++){
        if(S[i] == c) return i;
    }
    return S.size();
}

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

    int ans = 0;
    for(char a = '0'; a <= '9'; a++){
        int i = find(S, a, 0);
        for(char b = '0'; b <= '9'; b++){
            int j = find(S, b, i+1);
            for(char c = '0';c <= '9'; c++){
                int k = find(S, c, j+1);
                if(i != N && j != N && k != N) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
}

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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll solve(ll a, ll b, ll z) {
    ll ret = 0, num = 0;
    
    // cout << "HI " << "\n" << bitset<10>(a) << "\n" << bitset<10>(b) << "\n";
    ll cur = 0;
    F0Rd(i,z) {
        if (!(a&(1LL<<i))) { // 0 or 1
            // let it be 1
            ret += (1LL<<i);
            // what about 0?
        } else { // 1
            // has to be 1
            if (cur <= b) ret += min(1LL<<i,b+1);
            cur += 1LL<<i;
            // cout << "TT " << min(1LL<<i,b+1) << "\n";
        }
    }
    ret ++;
    return ret;
    /*// 3 to 5
    // [4,5] to [7,7]
    if (a+(1LL<<z) <= b) cout << 2*(1LL<<z)-a;
    else cout << b-a+1+(1LL<<z)-a;
    // [a,b]
    // [a+(1LL<<i),2*(1LL<<i)-1]*/
}

ll smart(ll a, ll b) {
    
    // cin >> a >> b;
    ll z = -1;
    F0Rd(i,60) {
        ll A = a&(1LL<<i), B = b&(1LL<<i);
        if (A == B) {
            if (A) a ^= (1LL<<i), b ^= (1LL<<i);
        } else {
            z = i;
            break;
        }
    }
    if (z == -1) {
        cout << 1;
        exit(0);
    }
    ll cans = (1LL<<z)-a;
    b -= (1LL<<z);
    F0Rd(i,60) if (b&(1LL<<i)) {
        b = (1LL<<(i+1))-1;
        break;
    }
    // cout << "OH " << solve(a,b,z) << "\n";
    return solve(a,b,z)+cans;
}

ll naive(ll a, ll b) {
    set<ll> cur;
    FOR(i,a,b+1) {
        vl v; for (auto x: cur) v.pb(x|i);
        for (auto x: v) cur.insert(x);
        cur.insert(i);
    }
    return sz(cur);
}

void test() {
    F0R(i,100) {
        ll a = rand() % 100, b = rand() % 100; if (a > b) swap(a,b);
        if (smart(a,b) != naive(a,b)) cout << a << " " << b << "\n" << smart(a,b) << "\n" << naive(a,b) << "\n-----\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*F0R(i,100) {
        test();
    }*/
    ll a,b; cin >> a >> b;
    cout << smart(a,b);
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
   // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, h;
    cin >> a >> b >>h;
    cout << (a + b) * h / 2 << endl;
}

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

using namespace std;

#define FOR(i, a, b) for(int i = a; i <= b; i++)

const int MAX = 1e2 + 10;

int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		int s[MAX] = {0};
		int cnt= 0;
		FOR(i, 0, n - 1)
			scanf("%d", &s[i]);
		FOR(i, 1, n - 1)
		{
			for(int j = n - 1; j >= i; j--)
			{
				if(s[j] < s[j - 1])
				{
					cnt++;
					swap(s[j], s[j - 1]);
				}
			}
		}
		FOR(i, 0, n - 1)
		{
			printf("%d", s[i]);
			if(i != n - 1)
				printf(" ");
			else
				printf("\n");
		}
		printf("%d\n", cnt);
	}
	return 0;
}



Measured memory_bytes: 2748
#include <stdio.h>
#include <math.h>

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

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

int f[15][1000] = {};

int main() {
	int d, g;

	int p[15], c[15];



	scanf("%d%d", &d, &g);

	g /= 100;

	int i;
	for (i = 0; i < d; i++) {
		scanf("%d%d", &p[i], &c[i]);
		c[i] /= 100;
	}

	int j;
	int m = 1000000;
	for (i = 0; i < (1 << d); i++) {
		int num = 0, nmax = -1, sum = 0;
		for (j = 0; j < d; j++) {
			if ((i >> j) & 1) {
				num += p[j];
				sum += p[j] * (j+1) + c[j];
			}
			else {
				nmax = j;
			}
		}

		if (g > sum&&nmax == -1) continue;

		if (g > sum) {
			int need = ceil((double)(g - sum) / (double)(nmax+1));

			if (need > p[nmax] && (sum + p[nmax] * nmax + c[nmax]) < g) continue; else if (need >p[nmax]) need = p[nmax];

			num += need;
		}

		m = min(m, num);
	}

	printf("%d", m);
	getchar(); getchar();
}

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

int main() {
  int odds=0,cnt=0;
  vector<int> is(3);
  for(int i=0;i<3;i++){
    cin>>is.at(i);
    if(is.at(i)%2!=0){odds++;}
  }
  if(odds==2){
    for(int i=0;i<3;i++){if(is.at(i)%2!=0){is.at(i)++;}}
    cnt++;
  }else if(odds==1){
    for(int i=0;i<3;i++){if(is.at(i)%2==0){is.at(i)++;}}
    cnt++;
  }
  int m=*max_element(is.begin(),is.end());
  int s=accumulate(is.begin(),is.end(),0);
  cout<<cnt+(3*m-s)/2<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;
        
/* 
const ll MAX_MEM = 25e7;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

signed main()
{
    Start();
    int n;
    cin >> n;
    vector <int> a(n);
    cin >> a;
    vector <pii> b;
    for (int i = 0; i < n; ++i)
        b.pb(a[i], i);
    sort(all(b));
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if (i % 2 != b[i].second % 2)
            ++ans;
    }
    cout << (ans + 1) / 2;
    return 0;
}
 


Measured memory_bytes: 3188
//default
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

bool seen[55][55];
int h,w,ans=0;
char field[55][55];
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

void dfs(int x,int y) {
	seen[x][y] = true; // v を訪問済にする
	// v から行ける各頂点 next_v について
	rep(i,8){
		int nx=x+dx[i];
		int ny=y+dy[i];
		if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
		if(seen[nx][ny]==true) continue;
		if(field[nx][ny]=='0') continue;
		dfs(nx,ny);
	}
}

signed main(){
	while(cin >> w >> h && (w!=0 || h!=0)){
		ans=0;
		rep(y,h)rep(x,w){
			cin >> field[x][y];
		}
		memset(seen,false,sizeof(seen));
		rep(y,h)rep(x,w){
			if(seen[x][y]==true) continue;
			if(field[x][y]=='0') continue;
			ans++;
			dfs(x,y);
		}
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

long xors(long p, long q){
  //pは偶数
  if(p>q) return q;
  if((q-p+1)%4==0) return 0;
  else if((q-p+1)%4==2) return 1;
  else if((q-p+1)%4==1) return q;
  else return 1^q;
}


void solve(){
  long a,b;
  cin >> a >> b;
  long ans=a;
  if(a==b) ans = a;
  else if(a%2==0) ans = xors(a,b);
  else {
    ans = a^xors((a+1), b);
  }
  cout << ans << endl;
  
}

int main(){
  solve();
  return 0;
}
  


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

int n;

int main()
{
    cin >> n;
    map<int, int> mp;
    rep(i, n)
    {
        int a;
        cin >> a;
        mp[a]++;
    }
    int sum = 0;
    for(auto x : mp)
    {
        sum = abs(sum - x.second + 1);
    }
    cout << (int)mp.size() - (sum % 2) << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int a,b;
   cin >> a >> b;
   vector<int> H(999,1);
   for(int i = 1; i < 999; i++){
       H[i] = i+1 + H[i-1];
   }
   for(int i = 0; i < 998; i++){
       if(b - a == H[i+1] - H[i]){
           cout << H[i] - a << endl;
           return 0;
       }
   }
}


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

using namespace std;
int main(void){
    int N;
    cin >> N;
    int A[2][N];
    for(int i=0;i<2;i++){
        for(int j=0;j<N;j++){
            cin >> A[i][j];
            //cout << A[i][j] << endl;
        }
    }
    
    int max=0;
    for(int bend=0;bend<N;bend++){
        int sum=0,x=0,y=0;
        for(x;x<N;x++) {
            sum += A[y][x];
            //cout << A << endl;
            //cout << x << y << endl;
            if(x == bend && y == 0) { y=1; x--; }
        }
        if(max < sum) {max = sum;}
        //cout << sum << endl;
    }
    cout << max;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << x << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep (i, n) cin >> a[i];
  int maxi = 0, maxi2, cnt;
  rep (i, n) {
    if (a[i] > maxi) {
      maxi2 = maxi;
      maxi  = a[i];
      cnt   = 1;
    } else if (a[i] > maxi2) {
      maxi2 = a[i];
    } else if (a[i] == maxi) ++cnt;
  }
  rep (i, n) cout << (cnt > 1 || a[i] != maxi ? maxi : maxi2) << "\n";
  return 0;
}

Measured memory_bytes: 2432
package main
 
import (
  "fmt"
)
 
func main() {
  var N int
  fmt.Scan(&N)
  
  ans := 1
  for i := 1; i <= N; i++ {
    ans *= i
    ans = ans % 1000000007
  }
  fmt.Printf("%d\n", ans)
}

Measured memory_bytes: 1832
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    int ans = 1;
    for(int i=2; i * i < N; ++i) {
        int b = i;
        while(b <= N) {
            ans = max(ans, b);
            b *= i;
        }
    }

    print(ans);
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

#define ll long long


/*
int main(void){
    double min_ = 1000000000000000;

    for(ll k = 10000; k > 0; k--){
        ll i = k * 10000000000 + 9999999999;

        ll s = 0;
        ll t = i % 100000;
        s += (t/100000)%10 + (t/10000)%10 + (t/1000)%10 + (t/100)%10 + (t/10)%10 + t%10;
        t = (i/100000) % 100000;
        s += (t/100000)%10 + (t/10000)%10 + (t/1000)%10 + (t/100)%10 + (t/10)%10 + t%10;
        t = (i/10000000000) % 100000;
        s += (t/100000)%10 + (t/10000)%10 + (t/1000)%10 + (t/100)%10 + (t/10)%10 + t%10;
        t = (i/1000000000000000) % 100000;
        s += (t/100000)%10 + (t/10000)%10 + (t/1000)%10 + (t/100)%10 + (t/10)%10 + t%10;

        if(i/(double)s <= min_){
            min_ = i/(double)s;
            printf("n/s:%f\t n: %lld\t s: %lld\n", min_, k, s);
        }
    }
}

*/

vector<long long> v;

int main(void){
    for(int i = 1; i <= 9; i++){
        v.push_back(i);
    }

    for(int i = 1; i <= 9; i++){
        v.push_back(i*10 + 9);
    }

    for(int i = 1; i <= 9; i++){
        for(int j = i + 1; j <= (i + 1) * 10; j++){
            v.push_back(j * pow(10, i + 1) - 1);
        }
    }

    for(int i = 11; i <= 100; i++){
        v.push_back(i * pow(10, 11) - 1);
    }

    for(int i = 11; i <= 110; i++){
        v.push_back(i * pow(10, 12) - 1);
    }

    for(int i = 12; i <= 101; i++){
        v.push_back(i * pow(10, 13) - 1);
    }


    int K;
    scanf("%d", &K);

    for(int i = 0; i < K; i++){
        printf("%lld\n", v[i]);
    }
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {

        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };


    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(usize1, usize1); m],
    }
    let mut ab = ab;
    ab.sort_by_key(|i| i.0);
    let ab = ab;

    let ans = ab
        .iter()
        .fold((1, n - 1), |s, r| {
            if r.0 < s.1 {
                (s.0, std::cmp::min(s.1, r.1))
            } else {
                (s.0 + 1, r.1)
            }
        })
        .0;
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b) return gcd(b, a);
	long long r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
int main() {
	int N,M,a,b;
	cin >> N>>M;
	vector<vector<int>>way(N);
	for (size_t i = 0; i < M; i++)
	{
		cin >> a >> b;
		a--;
		b--;
		way.at(a).push_back(b);
		way.at(b).push_back(a);
	}
	for (size_t i = 0; i < N; i++)
	{
		sort(way.at(i).begin(), way.at(i).end());
		if (way.at(i).size()!=0&&way.at(i).at(0) == 0 && way.at(i).at(way.at(i).size()-1) == N - 1) {
			cout<<"POSSIBLE";
			return 0;
		}
	}
	cout << "IMPOSSIBLE";
}

Measured memory_bytes: 12016
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<string> a(n), b(n);
		for(int i=0; i<n; i++){
			cin >> a[i] >> b[i];
		}
		string ini, fin;
		cin >> ini >> fin;
		
		queue<pair<int, string> > q;
		q.push(make_pair(0, ini));
		bool success = false;
		while(!q.empty()){
			int step = q.front().first;
			string str = q.front().second;
			q.pop();
			if(str == fin){
				cout << step << endl;
				success = true;
				break;
			}
			for(int i=0; i<n; i++){
				string newstr = "";
				bool nochange = true;
				for(int j=0; j<(int)str.length(); j++){
					bool failed = true;
					for(int k=0; k<(int)a[i].length() && j+k<(int)str.length(); k++){
						if(str[j+k] != a[i][k]){
							break;
						}else if(k == (int)a[i].length()-1){
							newstr += b[i];
							j += a[i].length()-1;
							nochange = false;
							failed = false;
						}
					}
					if(failed){
						newstr += str[j];
					}
				}
				if(!nochange && newstr.length()<=10){
					q.push(make_pair(step+1, newstr));
				}
			}
		}
		
		if(!success){
			cout << -1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3324
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define rn return
#define fi first
#define se second
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    int N,M; cin >> N >> M;
    if (M%2 == 1){cout << "-1"; rn 0;}
    vector<vector<int>> g(N);
    rep(i,M){
        int x,y;
        cin >> x >> y; x--;y--;
        g[y].push_back(x);
        g[x].push_back(y);
    }
    
    vector<pair<int,int>> ans;
    vector<int> degree(N,0);
    vector<int> depth(N,-1);
    
    function<void(int,int)> DFS=[&](int v, int pr){
        for(int u:g[v]){
            if (depth[u] == -1){
                depth[u] = depth[v] + 1;
                DFS(u,v);
            }
            else if(depth[u]>depth[v]) {
                degree[v]++;
                ans.emplace_back(v,u);
            }
        }
        if (degree[v]%2 == 1){
            assert(pr!=-1);
            ans.emplace_back(v,pr);
            degree[v]++;
        }
        else{
            if(pr!=-1){
                ans.emplace_back(pr,v);
                degree[pr]++;
            }
        }
    };
    

    
    depth[0] = 0;
    DFS(0,-1);
    
    for (auto& p:ans){
        cout << p.first + 1 << " " << p.second + 1 << endl;
    }
    rn 0;
}

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

int main(){
	int S;
	cin >> S;
	int S_0 = S/1000;
	int S_1 = (S-(S_0*1000))/100;
	int S_2 = (S-(S_0*1000 + S_1*100))/10;
	int S_3 = (S-(S_0*1000 + S_1*100 + S_2*10));
	int m,u;
	m = 10*S_0 + S_1;
	u = 10*S_2 + S_3;
	int checkM = 0,checkU = 0;
	if(m == 0 || m > 12){
		checkM = 1;
	}
	if(u == 0 || u > 12){
		checkU = 1;
	}
	if(checkM == 1 && checkU == 1){
		cout << "NA";
	}else if(checkM == 0 && checkU == 1){
		cout << "MMYY";
	}else if(checkM == 1 && checkU == 0){
		cout << "YYMM";
	}else{
		cout << "AMBIGUOUS";
	}
	return 0;
}


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

#define INF 1000000000;
#define MOD 1000000007;
typedef long long ll;
using namespace std;

int main()
{
    int a, b; cin >> a >> b;
    cout << max(a + b, max(a - b, a*b)) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<int> ch[110000];
int zz[110000];
set<pair<int,int> > s;
int depth[110000];

#define MAXA 20
int par[MAXA][110000];

void dfs(int a, int c){
	depth[a] = c;
	s.insert(make_pair(-c,a));
	for(int i = 0; i < ch[a].size(); i++){
		dfs(ch[a][i], c+1);
	}
}

void clear(int a, int d){ // clear down from a of depth d
	if(s.find(make_pair(-depth[a],a)) == s.end()){
		return;
	}
	s.erase(make_pair(-depth[a],a));
	if(d == 0) return;
	for(int i = 0; i < ch[a].size(); i++){
		clear(ch[a][i],d-1);
	}
}
int main(){
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> zz[i];
		zz[i]--;
	}
	int ans = 0;
	if(zz[0] != 0){
		zz[0] = 0;
		ans++;
	}
	for(int i = 1; i < n; i++){
		ch[zz[i]].push_back(i);
	}
	for(int i = 1; i < n; i++){
		par[0][i] = zz[i];
	}
	par[0][0] = 0;
	for(int j = 1; j < MAXA; j++){
		for(int i = 0; i < n; i++){
			par[j][i] = par[j-1][par[j-1][i]];
		}
	}
	dfs(0,0);

	if(k > n) k = n;

	while(!s.empty()){
		pair<int,int> c = *s.begin();

		int r = c.second;
		if(c.first == 0) break;
		int z = k-1;
		for(int i = 0; i < MAXA; i++){
			if(z % 2) r = par[i][r];
			z /= 2;
		}
		if(r != 0 && zz[r] != 0) ans++;
		//cout << r << endl;
		clear(r,k-1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 25600
n=int(input())
A=[]
for i in range(n):
  A.append(int(input()))
ans=0
chk=True
cur=0
for i in reversed(range(n)):
  if A[i]==cur:
    cur-=1
    continue
  else:
    if A[i]>i or A[i]<cur:
      chk=False
    else:
      ans+=A[i]
      cur=A[i]-1
print(ans if chk else -1)

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

int main(void){
    ll a, b;
    cin >> a >> b;
    if (a >= 1) cout << "Positive" << endl;
    else if (b <= -1) cout << ((b-a)%2==0 ? "Negative" : "Positive") << endl;
    else cout << "Zero" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 100 + 5;
char mp[maxn][maxn];
int vis[maxn][maxn];
int h,w;

void dfs(int x,int y,int cnt)
{
    vis[x][y] = cnt;
    if(x - 1 >= 0 && !vis[x - 1][y] && mp[x - 1][y] == mp[x][y]) dfs(x - 1, y, cnt);
    if(x + 1 < h && !vis[x + 1][y] && mp[x + 1][y] == mp[x][y]) dfs(x + 1, y, cnt);
    if(y - 1 >= 0 && !vis[x][y - 1] && mp[x][y - 1] == mp[x][y]) dfs(x, y - 1, cnt);
    if(y + 1 < w && !vis[x][y + 1] && mp[x][y + 1] == mp[x][y]) dfs(x,y + 1, cnt);
}
int main()
{
    while (scanf("%d%d",&h,&w) != EOF) {//有可能是反的
        if(h == 0 && w == 0) break;
        getchar();
        for (int i = 0; i < h; i ++) {
            scanf("%s",mp[i]);
        }
        memset(vis, 0, sizeof(vis));
        int cnt = 0;
        for (int i = 0; i < h; i ++) {
            for (int j = 0; j < w; j ++) {
                if(!vis[i][j]) dfs(i,j,++cnt);
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 3968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

class Main {

	static int n;

	static int[] v;

	static int[][] graph;

	static int time;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		n = Integer.parseInt(br.readLine());

		graph = new int[n][n];

		v = new int[n];

		Arrays.fill(v, Integer.MAX_VALUE);

		for (int i = 0; i < n; i++) {
			String[] u_k_v = br.readLine().split(" ");

			int u = Integer.parseInt(u_k_v[0]);

			for (int k = 0; k < Integer.parseInt(u_k_v[1]); k++) {

				graph[u - 1][Integer.parseInt(u_k_v[2 + k]) - 1] = 1;

			}
		}

		Deque<Integer> q = new ArrayDeque<>();

		q.offer(0);

		v[0] = 0;

		while (!(q.isEmpty())) {
			int node = q.poll();

			for (int j = 0; j < n; j++) {

				if (graph[node][j] == 1 && v[j] > v[node] + 1) {

					v[j] = v[node] + 1;

					q.offer(j);

				}

			}

		}
		for (int i = 0; i < n; i++) {
			if (!(i == 0)) {
				System.out.println((i + 1) + " " + (v[i] == Integer.MAX_VALUE ? "-1" : v[i]));
			} else {
				System.out.println((i + 1) + " " + v[i]);
			}
		}

	}

}

Measured memory_bytes: 24768