akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
#define BLACK 0
#define WHITE 1
int dp[100010][2];
vector<int> G[100010];
int calc(int x, int p, int color) {
    if(dp[x][color] != -1) return dp[x][color];
    int ret1 = 1, ret2 = 1;
    if(color == BLACK) ret2 = 0;
    for(auto to: G[x]) {
        if(to == p) continue;
        ret1 *= calc(to, x, WHITE);
        ret2 *= calc(to, x, BLACK);
        ret1 %= mod;
        ret2 %= mod;
    }
    return dp[x][color] = (ret1 + ret2) % mod;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    rep(i, n - 1) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    rep(i, 100010) rep(j, 2) dp[i][j] = -1;
    cout << calc(0, -1, WHITE) << endl;

    return 0;
}


Measured memory_bytes: 15616
#include <bits/stdc++.h>
using namespace std;
int N;
int m[1111111];
int s(int x){
    int r=0;
    while(x){r+=x%10;x/=10;}
    return r;
}
int f(int x){
    if(m[x]==0){
        int r=m[x]=1e9;
        int sx=s(x);
        if(x<N){
            for(int i=0;i<10;i++)r=min(r,f(x*10+i));
        }
        else if(x%N==0)r=sx;
        else{
            r=min(r,sx-s(x%N)+f(x%N));
        }
        m[x]=r;
    }
    return m[x];
}
int main(){
    cin>>N;
    while(N%2==0)N/=2;
    while(N%5==0)N/=5;
    cout<<f(0);
    return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int A, B, C;
  ci(A, B, C);
  if(A + B >= C){
    co("Yes");
  }
  else{
    co("No");
  }
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            bool Ans = true;

            string[] Inp1 = Console.ReadLine().Split(' ');
            int A11 = int.Parse(Inp1[0]);
            int A12 = int.Parse(Inp1[1]);
            int A13 = int.Parse(Inp1[2]);

            string[] Inp2 = Console.ReadLine().Split(' ');
            int A21 = int.Parse(Inp2[0]);
            int A22 = int.Parse(Inp2[1]);
            int A23 = int.Parse(Inp2[2]);

            string[] Inp3 = Console.ReadLine().Split(' ');
            int A31 = int.Parse(Inp3[0]);
            int A32 = int.Parse(Inp3[1]);
            int A33 = int.Parse(Inp3[2]);


            if (A11 - A12 == A21 - A22 && A21 - A22 == A31 - A32 && A12 - A13 == A22 - A23 && A22 - A23 == A32 - A33)
            {
                if (A11 - A21 == A12 - A22 && A12 - A22 == A13 - A23 && A21 - A31 == A22 - A31 && A22 - A32 == A23 - A33)
                {
                    Ans = true;
                }
            }
            else
            {
                Ans = false;
            }
            
            if (Ans == true)
            {

                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            //Console.WriteLine("Hello World!");
        }
    }
}


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

int main() {
  int N, T;
  cin >> N >> T;
  int t[200100];
  for (int i = 0; i < N; i++) cin >> t[i];

  long long ans = T;
  for (int i = 0; i + 1 < N; i++) {
    ans += min(T, t[i + 1] - t[i]);
  }

  cout << ans << endl;
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

const int MAX_N = 1e5 + 7;


void solve()
{
        int n; cin >> n;
        vector<int> a(n);
        forn(i, n) cin >> a[i];
        int cnt = 0;
        bool ok = true;
        while (true)
        {
                for(int i = 0; i < n; ++i)
                {
                        if (a[i] % 2 != 0)
                        {
                                ok = false;
                        }
                        else
                        {
                                a[i] /= 2;
                        }
                        
                }
                if (!ok)
                {
                        break;
                }
                cnt++;
        }
        cout << cnt;
}

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


Measured memory_bytes: 3564
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String s = br.readLine();
        
        int count = 0;
        int max = -1;
        Set<Character> set = new HashSet<>();
        char[] exist = new char[100];
        for (int i = 1; i < n; i ++) {
            String sub1 = s.substring(0, i);
            String sub2 = s.substring(i);
            for (int j = 0; j < sub1.length(); j++){
                if (sub2.contains(String.valueOf(sub1.charAt(j))) && !set.contains(sub1.charAt(j))) count++;
                set.add(sub1.charAt(j));
            }
            max = Math.max(max, count);
            count = 0;
            set.clear();
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long long int mod=1000000007;
int main(void){
  long long int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin>>a.at(i);
  }
  vector<long long int> hoge(n,0);
  vector<long long int> all(n,0);
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(a.at(i)>a.at(j)){
        all.at(i)++;
        if(j>i){
          hoge.at(i)++;
        }
      }
    }
  }
  long long int souwa;
  if((k-1)%2==0){
    souwa=k*((k-1)/2);
  }else{
    souwa=k*((k-1)/2)+((k-1)/2+1);
  }
  souwa%=mod;
  long long int ans=0;
  for(int i=0; i<n; i++){
    ans+=hoge.at(i)*k;
    ans%=mod;
    ans+=all.at(i)*souwa;
    ans%=mod;
  }
  cout<<ans<<endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s;
	bool ans = false;
	string keyword = "keyence";
	cin >> s;
	if (s == keyword)ans = true;
	else {
		if (s.substr(0, 7) == keyword)ans = true;
		else if (s.substr(s.length() - 7, 7) == keyword)ans = true;
		else {
			REP(i, 7) {
				if (s.substr(0, i) == keyword.substr(0, i)) {
					if (s.substr(s.length() - 7 + i, 7 - i) == keyword.substr(i, 7 - i)) {
						ans = true;
						break;
					}
				}
			}
		}
	}
	if (ans) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
typedef pair<int,int> ipair;
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
 
ll mod = 1000000007;


//cout<<fixed<<setprecision(2)<<d;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	int n;
	cin>>n;
	string ss;
	cin>>ss;
	ll mod = 998244353;
	ll ans = 1;

	ll arr[7];
	memset(arr,0,sizeof(arr));

	for(int i=0;i<(3*n);i++){
		if(ss[i]=='R'){
			if(arr[4]>0){
				ans = (ans*arr[4])%mod;
				arr[4]--;
			}
			else if(arr[2]>0){
				ans = (ans*arr[2])%mod;
				arr[2]--;
				arr[6]++;
			}
			else if(arr[1]>0){
				ans = (ans*arr[1])%mod;
				arr[1]--;
				arr[5]++;
			}
			else{
				arr[3]++;
			}
		}
		else if(ss[i]=='G'){
			if(arr[5]>0){
				ans = (ans*arr[5])%mod;
				arr[5]--;
			}
			else if(arr[3]>0){
				ans = (ans*arr[3])%mod;
				arr[3]--;
				arr[6]++;
			}
			else if(arr[1]>0){
				ans = (ans*arr[1])%mod;
				arr[1]--;
				arr[4]++;
			}
			else{
				arr[2]++;
			}
		}
		else if(ss[i]=='B'){
			if(arr[6]>0){
				ans = (ans*arr[6])%mod;
				arr[6]--;
			}
			else if(arr[3]>0){
				ans = (ans*arr[3])%mod;
				arr[3]--;
				arr[5]++;
			}
			else if(arr[2]>0){
				ans = (ans*arr[2])%mod;
				arr[2]--;
				arr[4]++;
			}
			else{
				arr[1]++;
			}
		}
		// for(int j=1;j<=6;j++){
		// 	cout<<arr[j]<<" ";
		// }
		// cout<<endl;
	}
	ll fac = 1;
	for(ll i=1;i<=n;i++){
		fac = (fac*i)%mod;
	}

	ans = (ans*fac)%mod;
	cout<<ans<<endl;
	return 0;
}
 
//-------------------------//


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    FOR(i,1,n+1) {
        int x = i;
        int y = 0;
        while(x != 0) {
            y += x % 10;
            x /= 10;
        }
        if (y >=a && y <= b) ans += i;
    } 

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

i32 main(void){
    i64 *x=(i64 *)calloc(3LL,sizeof(i64));
    i64 *y=(i64 *)calloc(3LL,sizeof(i64));
    for(i64 i=0LL;i<3LL;++i){
        for(i64 j=0LL;j<3LL;++j) scanf("%lli",&x[j]);
        for(i64 j=0LL;j<3LL;++j) scanf("%lli",&y[j]);
        for(i64 j=2LL;j>=0LL;--j){
            if(y[j]<x[j]){
                y[j]+=60LL;
                --y[j-1LL];
            }
            y[j]-=x[j];
        }
        for(i64 j=0LL;j<2LL;++j) printf("%lli ",y[j]);
        printf("%lli\n",y[2LL]);
    }
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i > 0; i--)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
void solve() {
  ll a, b;
  cin >> a >> b;
  cout << max({a + b, a - b, a * b}) << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  cout << 48 - n << endl;
}

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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {        
            string A = Console.ReadLine();
            string B = Console.ReadLine();
            if (A.Length > B.Length)
            {
                Console.WriteLine("GREATER");
            }else if(A.Length < B.Length)
            {
                Console.WriteLine("LESS");
            }else
            {
                int i = 0;
                while(i < A.Length)
                {
                    if(int.Parse(A[i].ToString())> int.Parse(B[i].ToString()))
                    {
                        Console.WriteLine("GREATER");
                        break;
                    }
                    else if(int.Parse(A[i].ToString()) < int.Parse(B[i].ToString()))
                    {
                        Console.WriteLine("LESS");
                        break;
                    }
                    i++;
                }
                if (i == A.Length)
                {
                    Console.WriteLine("EQUAL");
                }
            }
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(void){
    double r,x,y,pi=3.141592653589;
    scanf("%lf",&r);

    if(0<r<10000){  
    x=1.0*r*r*pi;
    y=2.0*r*pi;
    printf("%8lf %8lf\n",x,y);
    }    
    return 0;
}


Measured memory_bytes: 2084
#include<iostream>
#include <list>
#include <cstdlib>
#include <algorithm>
using namespace std;

int m,n;

int main(void){
	 while(cin >> m >> n,m|n){
		list <int> sur;
		for(int i=1;i<=m;i++)
			sur.push_back(i);
		typeof(sur.begin()) itr;
		itr=sur.begin();
		for(int i=1;i<=n;i++){
			string S;
			bool ok=false;
			cin >> S;
			if(itr==sur.end())
				itr=sur.begin();
			if(sur.size()==1)
				continue;
			if(!(i%15)&& (S =="FizzBuzz"))
				ok=true;
			else if(!(i%5)&& (S =="Buzz"))
				ok=true;
			else if(!(i%3)&& (S =="Fizz"))
				ok=true;
			else if(i==atoi(S.c_str())&&(i%3&&i%5))
				ok=true;
			if(ok){
				itr++;
			}else{
				itr=sur.erase(itr);
			}
		}
		cout << *(sur.begin() );
		if(sur.size()!=1)
			for(typeof(sur.begin()) it=++sur.begin(); it!=sur.end();it++)
				cout << " " << *it;
		cout << endl;
	}
}

Measured memory_bytes: 1252
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int N, K;
// 1 <= K <= 1000
// 1 <= N <= 1000000000

// O(N/2)
int solve(int x, int y) {
  return min(min(x-1, N-x), min(y-1, N-y)) % 3 + 1;
  /*
  for (int k=0; k<(N+1)/2; k++) {
    if (x == k || x == N-1-k || y == k || y == N-1-k) {
      return (k % 3) + 1;
    }
  }
  return -1;
  */
}

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

  rep(i, K) {
    int x, y;
    cin >> x >> y;
    //  red: 1 , blue : 2 , yellow : 3
    cout << solve(x, y) << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		k = scanner.nextInt();
		plan = new int[n + 1];
		for (int i = 0; i < k; i++) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			plan[a] = b;
		}
		dp = new int[n + 1][4][4];
		for (int i = 0; i <= n; i++)
			for (int j = 0; j < 4; j++)
				Arrays.fill(dp[i][j], -1);
		System.out.println(slove(1, 0, 0));
	}

	private int slove(int day, int pre1, int pre2) {
		if (day == n + 1)
			return 1;
		if (dp[day][pre1][pre2] != -1)
			return dp[day][pre1][pre2];
		if (plan[day] != 0)
			if (pre1 == pre2 && pre1 == plan[day])
				return 0;
			else
				return slove(day + 1, plan[day], pre1) % mod;
		int t = 0;
		for (int i = 1; i < 4; i++) {
			if (pre1 == pre2 && pre1 == i)
				continue;
			t += slove(day + 1, i, pre1) % mod;
		}
		return dp[day][pre1][pre2] = t % mod;

	}

	int n, k, d, s;
	int[] plan;
	int[][][] dp;
	int mod = 10000;
}

Measured memory_bytes: 19672
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<cstring>
#include<vector>

using namespace std;
int main (){
int h,x, n;
bool flag=true;
cin >> h;
int sum =0;
cin >> n;
while(n--){
    cin >> x;
    sum+= x;

}
 if(sum < h) {
       cout<< "No" << endl;
    }

else cout<< "Yes" << endl;



return 0;
}


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

int main() {
	int a,b;
	cin>>a>>b;
	int digit=1;
	while(digit<=b){
		if(digit){
		digit*=10;
		}else{
			digit=10;
		}
	}

	a=a*digit+b;
	bool flag=0;
	for(int i=0;i<a;i++){
		if(i*i==a){
			flag=1;
			break;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        d: usize,
        cc: [usize; 26],
        ss: [[usize; 26]; d],
    }

    for s in ss {
        let mut max = 0;
        let mut index = 0;
        for (i, x) in s.into_iter().enumerate() {
            if max < x {
                max = x;
                index = i;
            }
        }
        println!("{}", index+1);
    }
}

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

using namespace std;

const int mod = 1'000'000'007;
const int size_max = 2010;

long long fac[size_max], finv[size_max];

long long mpow(long long a, long long b);
void com_init();
long long com(long long n, long long k);

int main()
{
	int n, b;
	cin >> n >> b;
	int r = n - b;

	com_init();
	for (int i = 1; i <= min(b, r + 1); i++) {
		cout << (com(r + 1, i) * com(b - 1, i - 1)) % mod << endl;
	}
	for (int i = min(b, r + 1) + 1; i <= b; i++) {
		cout << 0 << endl;
	}

	return 0;
}

long long mpow(long long a, long long b)
{
	long long t = a;
	long long ans = 1;
	for (int i = 0; b != 0; i++) {
		if ((b & 1) == 1) {
			ans *= t;
			ans %= mod;
		}
		t *= t;
		t %= mod;
		b >>= 1;
	}

	return ans;
}

void com_init()
{
	fac[0] = fac[1] = 1;

	for (int i = 2; i < size_max; i++) {
		fac[i] = fac[i - 1] * i;
		fac[i] %= mod;
	}

	finv[size_max - 1] = mpow(fac[size_max - 1], mod - 2);

	for (int i = size_max - 2; i >= 2; i--) {
		finv[i] = finv[i + 1] * (i + 1) % mod;
	}
	finv[0] = finv[1] = 1;
}

long long com(long long n, long long k)
{
	if (n < k) {
		return 0;
	}

	if (n < 0 || k < 0) {
		return 0;
	}

	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main(){
	int n,ans=0;
	string s;
	cin>>n>>s;
	for(int i=2;i<n;i++){
		if(s[i-2]=='A'&&s[i-1]=='B'&&s[i]=='C'){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define filein(t) freopen(t, "r", stdin)
#define fileout(t) freopen(t, "w", stdout)
#define f first
#define s second
#define cs 137
#define ll long long
#define mp make_pair
#define N 5025
#define ln 1e9
#define oo 111539786
#define Pa pair < int, int >
#define Pi pair < int, Pa >

using namespace std;

int n, m, P[N][N], Q[N][N], Val[N][N];
int ans = 0;

int main()
{
    //filein("NAILS.inp");    fileout("NAILS.out");
    int u, v, x;
    cin >> n >> m;
    for(int i=1; i<=m; i++)
    {
        cin >> u >> v >> x;
        P[u+x][v]++;    P[u+x][v+x+1]--;
        Q[u+x-1][v+x]--;
        if(u - 2 >= 0)  Q[u-2][v-1]++;
    }
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            P[i][j] += P[i][j-1];
    for(int i=n; i>=1; i--)
        for(int j=n; j>=1; j--)
            Q[i][j] += Q[i+1][j+1];
    for(int j=1; j<=n; j++)
        for(int i=n; i>=1; i--)
            Val[i][j] = Val[i+1][j] + P[i][j] + Q[i][j];
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            ans += Val[i][j] != 0;
    cout << ans << endl;
}

Measured memory_bytes: 296580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll MAX_N=100010;

ll a,b,k;

int main(){
  cin>>a>>b>>k;
  for(ll i=a;i<=b;i++){
    if(i<a+k||i>b-k) cout<<i<<endl;
  }


  return 0;
}


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

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
	int n, cnt = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
/* ITP1_6_D: Mtrix Vector Multiplication */

#include <iostream>

int main() {
    int row, col;
    std::cin >> row >> col;

    int matrix[row][col];
    int cvector[row];

    // Read the matrix.
    for (int i_r = 0; i_r < row; i_r++) {
        for (int i_c = 0; i_c < col; i_c++) {
            std::cin >> matrix[i_r][i_c];
        }
    }

    // Read the column vector.
    for (int i_c = 0; i_c < col; i_c++) {
        std::cin >> cvector[i_c];
    }

    // Output results.
    for (int i_r = 0; i_r < row; i_r++) {
        int ans_row = 0;
        for (int i_c = 0; i_c < col; i_c++) {
            ans_row += matrix[i_r][i_c] * cvector[i_c];
        }
        std::cout << ans_row << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin >> d.at(i);
    }

    int cnt=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            cnt+=d.at(i)*d.at(j);
        }
    }
    cout << cnt;
}

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


ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}


int main(){
	int n;
	cin >> n;
	int table[n],cnt = 0,num = 1,memo = n;
	
	rep(i,0,n){
		cnt++;
		table[i] = num;
		
		if(num == cnt){
			cnt = 0;
			num++;
		}
	}
	
	while(memo){
		cout << table[memo-1] << endl;
		
		memo -= table[memo-1];
		
	}
	return 0;
}

Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n+1);
  for(ll i=1;i<=n;i++) {
    ll tmp;
    cin >> tmp;
    a[tmp]=i;
  }
  set<ll> al;
  al.insert(0);
  al.insert(n+1);
  ll ans=0;
  for(ll i=1;i<=n;i++) {
    auto it=al.upper_bound(a[i]);
    ans+=i*(*it-a[i])*(a[i]-*--it);
    al.insert(a[i]);
  }
  cout << ans << endl;
}

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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

int main() {
    ll n, m, x, ans = INF;
    cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));

    rep(i, n) {
        cin >> c[i];
        rep(j, m) {
            cin >> a[i][j];
        }
    }

    rep(i, (1<<n)) {
        vector<ll> us(m, 0);
        ll cost = 0;
        rep(j, n) {
            if(i & (1<<j)) {
                rep(k, m) {
                    us[k] += a[j][k];
                }
                cost += c[j];
            }
        }
        bool ok = true;
        rep(j, m) {
            if(us[j] < x) ok = false;
        }
        if(ok) {
            if(ans > cost) ans = cost;
        }
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}



Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    VI l(c);
    REP(i,c) l[i] = in();

    VVI v(c);
    REP(i,n){
        int x = in(), y = in();
        v[x-1].push_back(y);
    }

    VI cand;
    REP(i,c){
        sort(ALL(v[i]));
        reverse(ALL(v[i]));
        REP(j,min((int)v[i].size(), l[i])){
            cand.push_back(v[i][j]);
        }
    }

    sort(ALL(cand));
    reverse(ALL(cand));

    int ans = 0;
    REP(i,min((int)cand.size(), m)) ans += cand[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7868
x,y = map(int,input().split())
a = [1,3,5,7,8,10,12]
if(x==2 and y ==2):
    print("Yes")
elif(x==2 or y==2):
    print("No")
elif(x in a and y in a):
    print("Yes")
elif(x in a or y in a):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{int A,B,C,D,N;
scanf("%d",&N);


if(N/1000==(N/100)%10 &&(N/100)%10==(N/10)%10){
	printf("Yes");}else if(N%10==(N/100)%10 && (N/100)%10==(N/10)%10){
		printf("Yes");}else{
			printf("No");}
 
 
  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if ((int)s[i] + n > 90) {
			int index = (int)s[i] + n - 90 + 64;
			cout << (char)index;
		}
		else {
			int index = (int)s[i] + n;
			cout << (char)index;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

char in[8][7],pat[192][7];
int d[8];
bool use[8];

void rot(int nm,int xyz)
{
	char *s=in[nm],t;
	if(xyz==0)
	{
		t=s[1]; s[1]=s[2]; s[2]=s[4];
		s[4]=s[3]; s[3]=t; return;
	}
	if(xyz==1)
	{
		t=s[0]; s[0]=s[1]; s[1]=s[5];
		s[5]=s[4]; s[4]=t; return;
	}
	t=s[0]; s[0]=s[2]; s[2]=s[5];
	s[5]=s[3]; s[3]=t;
}
bool ok(int d1,int f1,int d2,int f2)
{
	d1=d[d1]; d2=d[d2];
	if(d1<0||d2<0)return 1;
	char c1=pat[d1][f1],c2=pat[d2][f2];
	return tolower(c1)==tolower(c2)&&c1!=c2;
}
bool ck()
{
	if(!ok(0,2,1,3)||!ok(0,4,2,1)||//1ツ階ツ督ッツ士
		!ok(2,2,3,3)||!ok(1,4,3,1)||
		!ok(0,0,4,5)||!ok(1,0,5,5)||//1-2ツ階
		!ok(2,0,6,5)||!ok(3,0,7,5)||
		!ok(4,2,5,3)||!ok(4,4,6,1)||//2ツ階ツ督ッツ士
		!ok(6,2,7,3)||!ok(5,4,7,1)
	)return 0;
	return 1;
}
bool dfs(int c)
{
	if(c==8)return 1;
	rep(i,8)if(!use[i])rep(j,24)
	{
		d[c]=i*24+j; use[i]=1;
		if(ck()&&dfs(c+1))return 1;
		d[c]=-1; use[i]=0;
	}
	return 0;
}
int main()
{
	while(scanf("%s",in[0]),in[0][0]!='0')
	{
		rep(i,7)scanf("%s",in+i+1);
		rep(i,8)use[i]=0,d[i]=-1;
		use[0]=1;
		
		int m=0;
		rep(i,8)
		{
			set<string> S;
			rep(x,4)
			{
				rep(y,4)
				{
					rep(z,4)
					{
						S.insert(in[i]);
						rot(i,0);
					}
					rot(i,1);
				}
				rot(i,2);
			}
			fr(it,S)strcpy(pat[m++],it->c_str());
		}
		rep(i,24)
		{
			d[0]=i;
			if(dfs(1))
			{
				puts("YES"); goto END;
			}
		}
		puts("NO"); END:;
	}
	return 0;
}

Measured memory_bytes: 912
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
long long ans[N];
int a[N],v[N],id[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
inline bool cmp(const int &x,const int &y) {return a[x]>a[y];}
int main() {
    int n,tp=0,l=1,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
	a[i]=gi(),id[i]=i;
	if(a[v[tp]]<a[i]) v[++tp]=i;
    }
    sort(id+1,id+1+n,cmp);
    while(tp--) {
	int x=v[tp+1],y=v[tp];
	ans[x]=1LL*sum*(a[x]-a[y]);
	while(a[id[l]]>a[y]) ++sum,ans[x]+=a[id[l++]]-a[y];
    }
    for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
    return 0;
}

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

int main()
{
    FASTIO;
    int n,m,i,j,counter=0,c;
    ld sum=0;
    cin>>n>>m;
    int arr[n];

    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        sum=sum+arr[i];
    }
    c=4*m;
    sum=sum/c;
    for(j=0;j<n;j++)
    {
        if(arr[j]>=sum)
            counter++;
    }
    if(counter>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

double dp[2][1000000];

int main() {
  int n, m, k;
  while (scanf("%d %d %d", &n, &m, &k), n|m|k) {
    //MEMSET(dp, 0);
    dp[0][0] = 1.0;
    REP(iter, n) {
      int prev = iter & 1;
      int next = (iter + 1) & 1;
      memset(dp[next], 0, sizeof(double) * (iter * m + m + 1));
      FOREQ(i, 0, iter * m) {
        FOREQ(j, 1, m) {
          dp[next][i + j] += dp[prev][i] / m;
        }
      }
    }
    double ans = 0;
    FOREQ(i, 1, n * m) {
      ans += max(i - k, 1) * dp[n & 1][i];
    }
    printf("%.7lf\n", ans);
  }
}

Measured memory_bytes: 0
loop do
    a, b = gets.split.map(&:to_i)
    break if a == 0 && b == 0
    dp = Array.new(a + 1, 0).map{Array.new(b + 1, 0)}
    n = gets.to_i
    n.times do
        x, y = gets.split.map(&:to_i)
        dp[x][y] = nil
    end
    dp[0][1] = 1
    for i in 1..a do
        for j in 1..b do
            if dp[i][j] == nil
                dp[i][j] = 0
            else
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
            end
        end
    end
    puts dp[a][b]
end

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




int main() {
  ll n,k;
  cin >> n >>k;
  vector<ll>v(n);
  vector<ll>l(n+1);
  vector<ll>r(n+1);


  l[0]=0;
  r[0]=0;
  rep(i,n){
    cin>>v[i];
    l[i+1]=l[i]+v[i];

  }
  rep(i,n){
    r[i+1]=r[i]+v[n-i-1];
  }
  ll A=-INF;

  rep(i,k+1){
    if(i>n)break;

    rep(j,i+1){
      ll ans=0;
  //    cout<<"i"<<i<<"j"<<j<<endl;
      ans+=l[i-j];
      ans+=r[j];
      //cout<<l[i-j]<<" "<<r[j]<<" "<<ans<<endl;
      vector<ll> a;
      rep(z,i-j)a.push_back(v[z]);
      rep(z,j)a.push_back(v[n-z-1]);
      sort(a.begin(),a.end());
//cout<<"siez"<<a.size()<<endl;
A=max(A,ans);
      rep(q,k-i){
        if (q>=i)break;
                  if (a[q]>0)break;
          ans-=a[q];
          A=max(A,ans);

        //  cout<<"ans"<<ans<<endl;

      }

    }
  }
  cout<<A;

}


Measured memory_bytes: 3640
import sys
import collections

s = list(map(str,input()))
t = list(map(str,input()))
cnts = collections.Counter(s)
cntt = collections.Counter(t)
cs = sorted(cnts.values())
ct = sorted(cntt.values())

if len(s) != len(t):
    print("No")
    sys.exit()

for i,j in zip(cs,ct):
    if i != j:
        print("No")
        sys.exit()

print("Yes")

Measured memory_bytes: 7056
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
var str=arr[0];
var n = (arr[1]-0)+2;
var ans="";
for(var i=2;i<n;i++){
   ans += (str.includes(arr[i])?1:0) +"\n";
}
console.log(ans.trim());


Measured memory_bytes: 35136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		//long a = long.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		string[] NMK = Console.ReadLine().Split(' ');
		int N = int.Parse(NMK[0]);
		int X = int.Parse(NMK[1]);
		int Y = int.Parse(NMK[2]);

		// i->jに到達済み（1）
		int[,] reach = new int[N+1,N+1];

		// 頂点iから1で到達できる頂点のリスト
		List<List<int>> one = new List<List<int>>();
		for(int i=0; i<=N; i++)
		{
			List<int> a = new List<int>();
			if(i==0)
			{

			}
			else if(i==1)
			{
				a.Add(2);
				reach[i,2] = 1;
			}
			else if(i==N)
			{
				a.Add(i-1);
				reach[i, i-1] = 1;
			}
			else
			{
				a.Add(i+1);
				a.Add(i-1);
				reach[i, i+1] = 1;
				reach[i, i-1] = 1;
			}

			if(i==X)
			{
				a.Add(Y);
				reach[i, Y] = 1;
			}

			else if(i==Y)
			{
				a.Add(X);
				reach[i, X] = 1;
			}

			one.Add(a);
		}

		// 距離kで到達できる頂点のリスト（距離１をコピー）
		List<List<int>> getWithk = new List<List<int>>(one);
		// 距離kで到達できる組み合わせの出力

		Console.WriteLine(N + "");
		for(int k=2;k<N; k++)
		{
			int route = 0; // 組み合わせ数
			for(int p = 1; p<=N; p++)
			{
				List<int> a = getWithk[p];
				List<int> b = new List<int>();
				foreach(int aa in a)
				{
					// 頂点a[q]から距離1で移動できる頂点を加える
					List<int> c = one[aa];
					foreach(int cc in c)
					{
						if(p != cc && reach[p, cc] == 0)
						{
							reach[p, cc] = 1;
							b.Add(cc);

							if(p<cc)
							{
								route++;
							}
						}
					}
				}
				// 頂点pから距離kで到達できる頂点のリストを上書き
				getWithk[p] = b;
			}
			Console.WriteLine(route + "");
		}

		// 文字列の入力
		//string s = Console.ReadLine();
		//出力
		//Console.WriteLine((a+b+c) + " " + s);
	}
}


Measured memory_bytes: 44348
#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(void)
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;

    if (k <= a) {
        ans = k;
    } else if (k <= a + b) {
        ans = a;
    } else {
        ans = a - (k - a - b);
    }

    cout << ans;
    return 0;
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  multiset<int> Set;

  for(int i = 0; i < N; ++i)
  {
    int Command; cin >> Command;

    if(Command == 0)
    {
      int Val; cin >> Val;
      Set.insert(Val);
      cout << Set.size() << endl;
    }
    else if(Command == 1)
    {
      int Val; cin >> Val;
      int Count = Set.count(Val);
      cout << Count << endl;

    }
    else if(Command == 2)
    {
      int Val; cin >> Val;
      auto ite = Set.equal_range(Val);
      Set.erase(ite.first, ite.second);
    }
    else 
    {
      int LB, UB; cin >> LB >> UB;

      auto ite = Set.lower_bound(LB);
      auto last = Set.upper_bound(UB);

      while(ite != last)
      {
	cout << *ite << endl;
        ++ite;
      }


    }

  }

  return 0;
}


Measured memory_bytes: 12356
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int main(void){
  int N;
  cin>>N;
  long p[N], flag[N];
  p[0] = 0, flag[0] = 0;
  long A;
  rep_s(i, 1, N+1) {
    cin >> p[i];
    if (p[i] == i) flag[i] = 1;
    else flag[i] = 0;
  }
  long count = 0;
  rep_s(i, 1, N+1){
    if (flag[i] == 1){
      count++;
 	  flag[i] = 0; flag[i+1] = 0;
    }
  }
  
  cout << count<< endl;
     
  }
  
  
   


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

using namespace std;

using ll = long long;

bool Solve() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> adj(n);
    vector<int> deg(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u - 1].push_back(v - 1);
        adj[v - 1].push_back(u - 1);
        ++deg[u - 1]; ++deg[v - 1];
    }

    int num_deg4 = 0, num_deg_gre6 = 0, s = -1, t = -1;
    for (int v = 0; v < n; ++v) {
        if (deg[v] & 1) return false;
        else if (deg[v] >= 6) ++num_deg_gre6;
        else if (deg[v] == 4) {
            ++num_deg4;
            if (s == -1) s = v;
            else t = v;
        }
    }
    if (3 <= num_deg4 || num_deg_gre6 != 0) return true;
    else if (num_deg4 <= 1) return false;

    for (int u : adj[s]) {
        int cur = u, prev = s;
        while (cur != s && cur != t) {
            for (auto v : adj[cur])
                if (v != prev) {
                    prev = cur;
                    cur = v;
                    break;
                }
        }
        if (cur == s) return true;
    }
    return false;
}

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

    cout << (Solve() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#include <cstdlib>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int c=(a+b)/2;
    if(abs(c-a)==abs(c-b))
    cout<<c<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            
            if(op.equals("?")){
                break;
            }else if(op.equals("+")){
                System.out.println(a + b);
            }else if(op.equals("-")){
                System.out.println(a - b);
            }else if(op.equals("*")){
                System.out.println(a * b);
            }else if(op.equals("/")){
                System.out.println(a / b);
            }
            
        }
    }
}



Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int arr[3][n+1];
    for(int i=1;i<=n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        arr[0][i]=a;
        arr[1][i]=b;
        arr[2][i]=c;
    }

    long long dp[3][n+1];

    for(int i=0;i<=n;i++){
        for(int j=0;j<3;j++)
        dp[j][i]=0;
    }

    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++){
        
            for(int k=0;k<3;k++){
                if(k!=j){
                    dp[j][i]=max(dp[j][i],dp[k][i-1]+arr[k][i]);
                }
            }
        }
    }
    long long ans=max(dp[0][n],max(dp[1][n],dp[2][n]));
    cout<<ans<<endl;

    
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,m,ans;
    cin >> n >> m;

    if(n==0 &&  m!=0){
        ans = m*(m-1)/2;
    }else if(n!=0 && m==0){
        ans = n*(n-1)/2;
    }else{
        ans = m*(m-1)/2 + n*(n-1)/2;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    if(c<d) swap(c,d); //c>=d;
    ll ans = b-a+1;
    ll ac = (a-1)/c;
    ll ad = (a-1)/d;
    ll bc = b/c;
    ll bd = b/d;
    //ll cdgcd = gcd(max(c,d),min(c,d));
    ll cdlcm = lcm(c,d);
    ll acd = (a-1)/cdlcm;
    ll bcd = b/cdlcm;
    ans -= (bc-ac) + (bd-ad);
    ans += bcd - acd;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>


using namespace std;

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

	int count_Y = 0;
	for (int i = 0; i < N; i++) {
		char s;
		cin >> s;
		if (s == 'Y') {
			count_Y++;
		}
	}

	if (count_Y > 0) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

struct UnionFind {
	vector<int> data;

	UnionFind(int sz) {
		data.assign(sz, -1);
	}

	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}

	int find(int k) {
		if(data[k] < 0) return(k);
		return data[k] = find(data[k]);
	}

	int size(int k)	{
		return -data[find(k)];
	}
};

struct edge {int from, to, cost;};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

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

    int v, e; cin >> v >> e;
    vector<edge> es(e);
    rep(i, e) {
        int x, y, z; cin >> x >> y >> z;
        es[i] = edge{x, y, z};
    }
    sort(all(es), comp);

    UnionFind uf(v);
    ll res = 0;
    rep(i, e) {
        edge e = es[i];
        if (uf.find(e.from)!=uf.find(e.to)) {
            uf.unite(e.from, e.to);
            res += e.cost;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 4236
#include <stdio.h>
#include <ctype.h>

int main()
{
	int ch, cnt[26] = {0};
	while(ch = getchar(), ch != EOF)
	{
		if(isalpha(ch))
		{
			++cnt[toupper(ch) - 'A'];
		}
	}

	for(int i = 0; i < 26; ++i)
	{
		printf("%c : %d\n", i + 'a', cnt[i]);
	}
	return 0;
}


Measured memory_bytes: 2104