akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

static class CodeJam
{
    static int[] Solve(int M, int[] B)
    {
        var factors = new int[M];
        var balls = new List<int>();
        for (int i = M; i > 0; --i)
        {
            if (factors[i - 1] % 2 != B[i - 1])
            {
                balls.Add(i);
                for (int j = 1; j * j <= i; ++j)
                {
                    if (j * j == i)
                    {
                        ++factors[j - 1];
                    }
                    else if (i % j == 0)
                    {
                        ++factors[j - 1];
                        ++factors[i / j - 1];
                    }
                }
            }
        }
        return balls.ToArray();
    }

    static void Main(string[] args)
    {
        int M = int.Parse(Console.ReadLine());
        int[] B = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var ans = Solve(M, B);
        if (ans != null)
        {
            Console.WriteLine(ans.Length);
            Console.WriteLine(string.Join(" ", ans));
        }
        else
        {
            Console.WriteLine(-1);
        }
    }
}


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

int main(){
    int n,i,r,minv,maxv;
    cin >> n;
    cin >> r;
    minv = r;
    maxv = -1000000000;
    for(i=1;i<n;i++){
        cin >> r;
        if(r - minv > maxv) maxv = r - minv;
        if(r < minv) minv = r;
    }
    cout << maxv << endl;

    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
int n;
string s;
int main(){
  cin >> n >> s;
  for (size_t i = 0; i < s.size(); i++) {
    if(s[i]+n <= 'Z')
      s[i] = s[i]+n;
    else{
      s[i] = 64+((s[i]+n)-'Z');
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
from heapq import*
import sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:F[v]=t;heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r()
  if'0'==f[0]:print(g(n,E,*map(int,f[2:].split())))
  else:c=[*map(int,f[2:].split())];[E[c[i]].append([c[2],c[1-i]])for i in[0,1]]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6312
num = gets.to_i

words = []

def valid?(from, to)
    from[-1] == to[0]
end

words.push gets.chomp
num -= 1

res = true
num.times do |i|
    w = gets.chomp
    if words.include?(w) || !valid?(words[-1], w)
        # puts [words[-1], w].join("-")
        res = false
        break
    end
    words.push w
end

puts res ? "Yes" : "No"

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

int main() {
    
    
    int n,ans;
    ans  = 0;
    cin >> n ;
    
    vector <int> a(n);
	
	for(int i = 0; i < n;i++){
	    cin >> a[i];
	}
	sort(a.begin(),a.end());
	ans = a[n- 1] - a[0];
	
	cout << ans;
	
	
	return 0;
}


Measured memory_bytes: 256
import math
N = int(input())
H = list(map(int,input().split()))

max_num = 0
count = 0
for i in range(N-1):
    if H[i]>=H[i+1]:
        count+=1
    else:
        count=0
    if max_num<count:
        max_num = count
        
print(max_num)

Measured memory_bytes: 64208
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	str := nextLine()
	s := strings.Replace(str, ",", " ", -1)
	fmt.Println(s)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const int MOD = 1000000007;

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

  ll n, m;
  string s, t;
  cin >> n >> m >> s >> t;

  if(n > m) {
    swap(n, m);
    swap(s, t);
  }

  map<int, char> mp;
  ll l = n/__gcd(n, m)*m;
  ll tmp = l/n;
  REP(i, n) {
    mp[i*tmp] = s[i];
  }
  tmp = l/m;
  REP(i, m) {
    if(mp.find(i*tmp) != mp.end()) {
      if(mp[i*tmp] != t[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  cout << l << endl;

  return 0;
}


Measured memory_bytes: 3968
/*     *******************Bismillahir Rahmanir Rahim************************
                          MD. ASFAKUL GHANI!
                          *ProMAGFAT*!
 SECRET_warning :)->FAT   CSE-25!
                          JAHANGIRNAGAR UNIVERSITY!
                          Dhaka,Bangladesh!
*/

#include <bits/stdc++.h>
#include <set>
using namespace std;

#define           fasterIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define           Im int main()
#define           ll long long
#define           sc scanf
#define           pf printf
#define           rn0 return 0
#define           rn return
#define           f0(i,n) for(ll i=0;i<n;i++)
#define           f1(i,n) for(ll i=1;i<=n;i++)
#define           f2(i,n) for(ll i=n-1;i>=0;i--)
#define           pi 2*acos(0.0)
#define           modulo 1000003
#define           dd double
#define           PI 3.14159265358979
#define           pi 2*acos(0.0)
#define           p_b push_back
#define           ps push

/*
ll for_binarySearch(ll a,ll b,ll aa[],ll x){while(a<=b){ll mid=(a+b)/2;if(aa[mid]==x) return 1;else if(aa[mid] > x) b=mid-1;else a=mid+1;}return -1;}
ll for_gcd(ll a,ll b){if(a==0) return b;else return for_gcd(b%a,a);}
ll for_prime(ll x){for (ll i=2;i*i<=x;i++){if(x%i==0) return 0;}return 1;}
void for_swap(char *x,char *y){char temp;temp=*x;*x=*y;*y=temp;}
ll for_big_mod(ll b,ll p,ll m){if(p==0) return 1;else if(p%2==0){ll k=for_big_mod(b,p/2,m);return (k*k)%m;}else return ((b%m)*(for_big_mod(b,p-1,m)))%m;}
ll for_josephus(ll n,ll k){if(n==1) return 1;return (for_josephus(n-1,k)+k-1)%n+1;}
ll for_gcdExtended(ll a,ll b,ll *x,ll *y){if(a==0){*x=0;*y=1;return b;}ll x1,y1;ll gcd=for_gcdExtended(b%a,a,&x1,&y1);*x=y1-(b/a)*x1;*y=x1;return gcd;}
*/

void debug1()
{
    cout << "***" << endl;
}

void debug11(ll n)
{
    cout << n << endl;
}

ll m,n;
vector <ll> v1[101010];
ll in_dg[101010];

void FAT_topSort()
{
    //memset(in_dg,0,sizeof(in_dg));

    for (ll i = 0; i < n; i += 1){
        vector <ll> ::iterator it;
        for (it = v1[i].begin(); it != v1[i].end(); it += 1){
            in_dg[*it] += 1;
        }
    }
    queue <ll> q1;
    for (ll i = 0; i < n; i += 1){
        if (in_dg[i]==0) q1.ps(i);
    }
    vector <ll> v2;
    ll cnt = 0;
    while (!q1.empty()){
        ll u = q1.front();
        q1.pop();
        v2.p_b(u);
        vector <ll> ::iterator it;
        for (it = v1[u].begin(); it != v1[u].end(); it += 1){
            //in_dg[*it] -= 1;
            if (--in_dg[*it]==0) q1.ps(*it);
        }
        cnt += 1;
    }

    for (ll i = 0; i < v2.size(); i += 1){
        cout << v2[i] << endl;
    }
    rn;
}

Im
{
    /*#ifdef FAT
       freopen("input.txt","w",stdin);
    #endif // FAT*/

    fasterIO;

    cin>>n>>m;

    for (ll i = 0; i < m; i += 1){
        ll u,v;
        cin>>u>>v;
        v1[u].p_b(v);
    }

    FAT_topSort();

   // main();

    rn0;
}

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

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

  string S;
  cin >> S;
  vector<int> children(S.size());
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == 'R' && S[i + 1] == 'L') {
      int j = 0;
      while (true) {
        if (S[i - j] == 'R') {
          if (j % 2 == 1) {
            children.at(i + 1)++;
          } else {
            children.at(i)++;
          }
          j++;
        } else {
          break;
        }
      }
      j = 0;
      while (true) {
        if (S[i + 1 + j] == 'L') {
          if (j % 2 == 1) {
            children.at(i)++;
          } else {
            children.at(i + 1)++;
          }
          j++;
        } else {
          break;
        }
      }
    }
  }
  for(int i = 0; i < S.size(); ++i){
    cout << children.at(i) << " ";
  }
}

Measured memory_bytes: 1104
#include<stdio.h>
#include<math.h>
#define TYPE int
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }

int main() {
	int N;
	int meda = -1, medb = -1;
	long long tmpa = 0, tmpb = 0;
	long long ans = 0;
	scanf("%d", &N);
	int *A = (int *)malloc(sizeof(int)*N);
	int *B = (int *)malloc(sizeof(int)*N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
		B[i] = A[i] - (i + 1);
		//printf("B[%d];%d\n", i, B[i]);
	}

	qsort(B, N, sizeof(TYPE), cmp);
	//for (int i = 0; i < N; i++)
	//{
	//	printf("B[%d];%d\n", i, B[i]);
	//}
	if (N % 2 == 1)
	{
		if (N == 1)
		{
			meda = B[0];
		}
		else
		{
			meda = B[N / 2];
		}

	}
	else if (N % 2 == 0)
	{
		meda = B[N / 2];
		medb = B[N / 2 - 1];
	}
	if (meda != -1)
	{
		for (int i = 0; i < N; i++)
		{
			tmpa += (long long)abs(A[i] - (meda + i + 1));
		}
	}
	if (medb != -1)
	{
		for (int i = 0; i < N; i++)
		{
			tmpb += (long long)abs(A[i] - (medb + i + 1));
		}
	}
	if (tmpa <= tmpb && meda != -1 && medb != -1)
	{
		ans = tmpa;
	}
	else if (tmpa > tmpb && meda != -1 && medb != -1)
	{
		ans = tmpb;
	}
	else if (meda != -1 && medb == -1)
	{
		ans = tmpa;
	}
	else if (meda == -1 && medb != -1)
	{
		ans = tmpb;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   for(int i = 0; i < n; i++){
      cin >> a[i];
   }

   vector<int> rev(n);
   for(int i = 0; i < n; i++){
      rev[a[i] - 1] = i + 1;
   }
   for(int i = 0; i < n; i++){
      cout << rev[i] << endl;
   }
   return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a_co=0;
  string s;
  cin >> s;
  for(int i=0; i<3; i++) {
    if (s[i] == 'A') a_co++;
  }
  if (a_co==3 || a_co==0) {
    cout << "No" << endl;
  } else { 
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 888
#include<stdio.h>
int tosi[7];
int i,n,j,nen,toshi,t;
int main(void){
	while(1){
		for(i=0;i<7;i++){
			tosi[i]=0;
		}
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d",&nen);
			toshi=10,t=0;
			for(j=0;j<6;j++){
				if(nen<toshi){
					tosi[t]++;
					break;
				}
				toshi+=10;
				t++;
				if(toshi==70){
					tosi[t]++;
		//		printf("tt%d\n",t);
				}
			}
		}
		for(i=0;i<7;i++){
			printf("%d\n",tosi[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1028
package main

import "fmt"

func sumDeci(p int) int {
	sum := 0
	for p != 0 {
		sum += p % 10
		p = p / 10
	}
	return sum
}

func main() {
	var n, a, b, sum int
	fmt.Scan(&n, &a, &b)
	for i := 1; i <= n; i++ {
		x := sumDeci(i)
		if a <= x && x <= b {
			sum += i
		}
	}
	fmt.Println(sum)
}


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

int main() {
	long double a, b, c;
	while(cin >> a >> b >> c) {
		string ans = "No";
		if(sqrt(a) + sqrt(b) < sqrt(c) - 1.0E-14) ans = "Yes";
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int, int>;
#define ss second
#define ff first
#define all(x) ((x).begin(), (x).end())

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;
const ll oo = 1 << 31;


int main(){

    ios_base::sync_with_stdio(false);
    int n, m;
    string a[51], b[51];

    cin >> n >> m;

    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    for (int i=0; i<m; i++){
        cin >> b[i];
    }
    int count = 0, maior = 0;
    for (int i=0; i<= n-m; i++){
        for (int j=0; j<=n-m; j++){
            count = 0;
            for (int k =0; k<m; k++){
                for (int l=0; l<m; l++){
                    if (a[i+k][j+l] == b[k][l]) count++;
                }
            }
            maior = max(maior, count);
        }
    }

    cout << (maior == m*m? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

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

        String str = sc.nextLine();

        if(str.equalsIgnoreCase("SUN")) {
            System.out.print(7);
        } else if(str.equalsIgnoreCase("MON")) {
            System.out.print(6);
        } else if(str.equalsIgnoreCase("TUE")) {
            System.out.print(5);
        } else if(str.equalsIgnoreCase("WED")) {
            System.out.print(4);
        } else if(str.equalsIgnoreCase("THU")) {
            System.out.print(3);
        } else if(str.equalsIgnoreCase("FRI")) {
            System.out.print(2);
        } else if(str.equalsIgnoreCase("SAT")) {
            System.out.print(1);
        }


    }
}

Measured memory_bytes: 21588
#include <iostream>

using namespace std;

int main()
{   int health;
    int attack;
    int counter;

    cin>>health>>attack;
    int i;
    for (i=1 ;health >0; i++){
        health=health-attack;
        counter =i;

    }
             cout<<counter;
       cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i, n, b, f, r, v;
  int people[5][4][11] = {0, 0, 0, 0, 0};

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ )
  {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    people[b][f][r] += v;
  }

  for( b = 1 ; b <= 4 ; b++ )
  {
    for( f = 1 ; f <= 3 ; f++ )
    {
      for( r = 1 ; r < 10 ; r++ )
        printf(" %d", people[b][f][r]);
      printf(" %d\n", people[b][f][10]);
    }
    if( b == 4 )
      break;
    printf("####################\n");
  }
}



Measured memory_bytes: 2084
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;


namespace Piza
{
    class Paiza
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = s[0];
            int B = s[1];
            int ans = 0;
            ans = Max(ans, A + A-1);
            ans = Max(ans, B + B-1);
            ans = Max(ans, A + B);
            WriteLine(ans);
        }
    }
}


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

int main() {
	int a,b;
	cin>>a>>b;
	if(a==1 && b==1){
		cout<<1000000<<endl;
	}
	else if(a==2 && b==1){
		cout<<500000<<endl;
	}
	else if(b==2 && a==1){
		cout<<500000<<endl;
	}
	else if(a==3 && b==1){
		cout<<400000<<endl;
	}
	else if(a==1 && b==3){
		cout<<400000<<endl;
	}
	else if(a==2 && b==2){
		cout<<400000<<endl;
	}
	else if(a==2 && b==3){
		cout<<300000<<endl;
	}
	else if(b==2 && a==3){
		cout<<300000<<endl;
	}
	else if(a==3 && b==3){
		cout<<200000<<endl;
	}
  	else if(a==1 && b>3){
		cout<<300000<<endl;
	}
  	else if(b==1 && a>3){
		cout<<300000<<endl;
	}
  	else if(a==2 && b>3){
		cout<<200000<<endl;
	}
  	else if(b==2 && a>3){
		cout<<200000<<endl;
	}
  	else if(a==3 && b>3){
		cout<<100000<<endl;
	}
  	else if(b==3 && a>3){
		cout<<100000<<endl;
	}
  	else{
      	cout<<0<<endl;
    }
	return 0;
}

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

using namespace std;

int main()
{
    string s; cin >> s;
    string t; cin >> t;

    int best=t.length();
    int c=0;

    for (int i=0;i<=s.length()-t.length();i++)
    {
        c=0;
        for (int j=0;j<t.length();j++)
        {
            if (s[i+j]!=t[j]) {c++;}
        }
        best=min(best,c);
    }
    cout << best << endl;
    cin.sync();cin.get();
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

const int INF = 0xfffffff;
const int MAX = 10000;

struct Edge {
	Edge() {};
	Edge(int v, int c) :v(v), c(c) {};
	bool operator < (const Edge& e)const {
		return c > e.c;
	}
	int v;
	int c;
};

int main() {
	int n;
	priority_queue<Edge> graph[MAX];
	vector<Edge> table;
	bool check[MAX] = { false };
	int ary[MAX] = { 0 };

	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			Edge e;
			cin >> e.v >> e.c;
			graph[u].push(e);
		}
	}

	Edge e(0, 0);
	table.push_back(e);
	check[0] = true;

	for (int i = 1; i < n; i++) {
		Edge minv(0, INF);
		int erase = 0;

		for (int j = 0; j < table.size(); j++) {
			int v = table[j].v;
			int c = table[j].c;	
			while (!graph[v].empty() && check[graph[v].top().v])graph[v].pop();
			if (graph[v].empty())continue;
			if (c + graph[v].top().c < minv.c) {
				minv.c = c + graph[v].top().c;
				minv.v = graph[v].top().v;
				erase = v;
			}
		}
		table.push_back(minv);
		check[minv.v] = true;
		graph[erase].pop();
	}
	
	for (int i = 0; i < n; i++) {
		ary[table[i].v] = table[i].c;
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << ary[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3436
def main():
    from collections import deque, defaultdict
    n, *uvw = map(int, open(0).read().split())
    l = defaultdict(dict)
    g = [[] for _ in range(n + 1)]

    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        g[u].append(v)
        g[v].append(u)
        l[u].update({v: w % 2})

    l[0].update({1: 0})

    vis = [False] * (n + 1)
    col = [0] * (n + 1)

    q = deque()
    q.append([0, 1, 0])

    while q:
        i, j, k = q.popleft()
        if vis[j]:
            continue
        vis[j] = True
        c = k if l[min(i, j)][max(i, j)] == 0 else 1 - k
        col[j] = c

        for x in g[j]:
            q.appendleft([j, x, c])

    print(*col[1:], sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 54596
// include
// ----------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>

// repetition
// ----------------------------------------------------------------------------
#define FOR(i, a, b) for (i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// memory clear
// ----------------------------------------------------------------------------
#define CLRNUM(a) memset((a), 0, sizeof(a))
#define CLRBOOL(a, flag) memset((a), flag, sizeof(a))
#define CLRCHAR(a) memset((a), '\0', sizeof(a))

// debug
// ----------------------------------------------------------------------------
#define DEBUGINT(x) printf("%d\n", x);
#define DEBUGFLOAT(x) printf("%f\n", x);
#define DEBUGCHAR(x) printf("%c\n", x);
#define DEBUGSTR(x) printf("%s\n", x);
#define DEBUGFORINT(i, a, b, x) FOR(i, a, b){ printf("%d ", x[i]); }
#define DEBUGFORFLOAT(i, a, b,x ) FOR(i, a, b){ printf("%f ", x[i]); }
#define DEBUGFORCHAR(i, a, b, x) FOR(i, a, b){ printf("%c ", x[i]); }
#define DEBUGREPINT(i, n, x) REP(i, n){ printf("%d ", x[i]); }
#define DEBUGREPFLOAT(i, n, x) REP(i, n){ printf("%f ", x[i]); }
#define DEBUGREPCHAR(i, n, x) REP(i, n){ printf("%c ", x[i]); }

// other
// ----------------------------------------------------------------------------
#define PUTNL printf("\n")

// constant
// ----------------------------------------------------------------------------
#define INF 1000000000

int main(void)
{
    char str[1024];
    int i, j;
    int len;
    bool flag;

    memset(str, '\0', sizeof(str));

    while (fgets(str, sizeof(str), stdin) != NULL){
        flag = false;
        len = strlen(str);

        while (1){
            for (i = 0; i < len; ++i){
                if (str[i] == 't'){
                    if (str[i + 1] == 'h'){
                        if (str[i + 2] == 'e'){
                            flag = true;
                            break;
                        }
                        else if (str[i + 2] == 'i'){
                            if (str[i + 3] == 's'){
                                flag = true;
                                break;
                            }
                        }
                        else if (str[i + 2] == 'a'){
                            if (str[i + 3] == 't'){
                                flag = true;
                                break;
                            }
                        }
                    }
                }
            }
            
            if (flag == false){
                for (i = 0; i < len; ++i){
                    if (str[i] >= 'a' && str[i] <= 'z'){
                        if (str[i] == 'z'){
                            str[i] = 'a';
                        }
                        else {
                            str[i]++;
                        }
                    }
                }
            }
            else if (flag = true){
                printf("%s", str);
                break;
            }
        }
        
        memset(str, '\0', sizeof(str));

    }
    return 0;
                  
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x%y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;

int main() {
	int n;
	int min = -1, max = 99999;
	cin >> n;
	vector<int> vec(n);

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

	sort(ALL(vec));

	if (n == 1) {
		cout << 0 << endl;

	}
	else {
		cout << vec[n - 1] - vec[0] << endl;

	}

}

Measured memory_bytes: 256
N = int(input())
S = input()
ans = 0
for i in range(1000):
    lucky = str(i)
    if 0 <= i <= 9:
        lucky = "00" + lucky
    elif 10 <= i <= 99:
        lucky = "0" + lucky
    else:
        pass
    now = 0
    index = 0
    while index < N:
        if lucky[now] == S[index]:
            now += 1
        if now == 3:
            ans += 1
            break
        index += 1
print(ans)


Measured memory_bytes: 73772
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
		int n = sc.nextInt();
		int x = 0;
		for(int a = 0; a < 10; a++){
			for(int b = 0; b < 10; b++){
				for(int c = 0; c < 10; c++){
					for(int d = 0; d < 10; d++){
						if(a + b + c + d == n)x++;
					}
				}
			}
		}
		System.out.println(x);
		}
	}
}

Measured memory_bytes: 18856
parseint(x) = parse(Int, x)
readint() = readline() |> parseint
readints() = map(parseint, readline() |> split)

function main()
    n = readint()
    d = readints()
    sort!(d)
    m = n >> 1
    l, r = d[m:m+1]
    println(r - l)
end

main()


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

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

long long dp[100010];
long long h[100010];

long long INF = 1ll<<60;

int main(void){
    int n;
    std::cin >> n;

    for(int i = 0; i < 100010; i++){
        dp[i] = INF;
    }

    for(int i = 0; i < n; i++){
        std::cin >> h[i];
    }

    dp[0] = 0;

    for(int i = 0; i < n; i++){
        chmin(dp[i+1], dp[i] + std::abs(h[i] - h[i+1]));
        chmin(dp[i+2], dp[i] + std::abs(h[i] - h[i+2]));

    }
    std::cout << dp[n-1] << std::endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int w=in.nextInt(),h=in.nextInt(),c=in.nextInt();
		int g;
		if(w<h)g=gcd(h,w);
		else g=gcd(w,h);
		System.out.println((w/g)*(h/g)*c);
	}
	
	static int gcd(int a,int b) {
		int g=a%b;
		if(g==0)return b;
		else return gcd(b,g);
	}

}



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

int s[1000000];

int main()
{
	int i,j;
	int n;
	int num;
	int count=0;
	
	while(scanf("%d",&n)==1){
		count=0;
		for(i=0;i<n;i++){
			s[i]=1;
		}
		s[0]=0;
		num=(int)sqrt((double)n);
		for(i=1;i<num;i++){
			if(s[i]==1){
				for(j=(i+1);(i+1)*j<=n;j++){
					s[(i+1)*j-1]=0;
				}
			}
		}
		for(i=0;i<n;i++){
			count+=s[i];
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 4308
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)

	var x int
	if sc.Scan() {
		x, _ = strconv.Atoi(sc.Text())
	}

	if x == 7 || x == 5 || x == 3 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
def solve():
    from sys import stdin
    from collections import Counter
    f_i = stdin
    
    while True:
        w, d = map(int, f_i.readline().split())
        if w == 0:
            break
        
        h_w = Counter(map(int, f_i.readline().split()))
        h_d = Counter(map(int, f_i.readline().split()))
        
        for k, v in h_w.items():
            if v > h_d.setdefault(k, v):
                h_d[k] = v
        
        print(sum(k * v for k, v in h_d.items()))

solve()


Measured memory_bytes: 6004
using System;
using System.Linq;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int N = arr[0], M = arr[1];
            var X = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(val => val).ToArray();
            var delta = new int[M - 1];
            for (var i = 0; i < delta.Length; i++) delta[i] = X[i + 1] - X[i];
            delta = delta.OrderBy(val => val).ToArray();
            int sum = 0;
            for (int i = 0; i < M - N; i++)
            {
                sum += delta[i];
            }

            Console.WriteLine(sum);
        }
    }
}

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

const double EPS = 1e-8;

const char* fortune[] = {
	"dai-kichi",
	"chu-kichi",
	"kichi",
	"syo-kichi",
	"kyo",
};

template<class T> class Vector2
{
public:
	int crossProduct( const Vector2& v )
	{
		return x * v.y - v.x * y;
	}

	T x, y;
};

int main()
{
	int x1, y1, x2, y2;
	while( cin >> x1 >> y1 >> x2 >> y2 && ( x1 || y1 || x2 || y2 ) ){
		Vector2<int> p[ 3 ][ 2 ];
		Vector2<int> v[ 3 ];
		p[ 0 ][ 0 ].x = x1;
		p[ 0 ][ 0 ].y = y1;
		p[ 0 ][ 1 ].x = x2;
		p[ 0 ][ 1 ].y = y2;
		v[ 0 ].x = x2 - x1;
		v[ 0 ].y = y2 - y1;
		for( int i = 1; i < 3; ++i ){
			cin >> x1 >> y1 >> x2 >> y2;
			p[ i ][ 0 ].x = x1;
			p[ i ][ 0 ].y = y1;
			p[ i ][ 1 ].x = x2;
			p[ i ][ 1 ].y = y2;
			v[ i ].x = x2 - x1;
			v[ i ].y = y2 - y1;
		}

		int result = 0;
		if( v[ 0 ].crossProduct( v[ 1 ] ) * v[ 1 ].crossProduct( v[ 2 ] ) * v[ 2 ].crossProduct( v[ 0 ] ) == 0 ){
			result = 4;
		}else{
			Vector2<double> e[ 3 ];
			for( int i = 0; i < 3; ++i ){
				int a = i;
				int b = ( i + 1 ) % 3;
				int ax = p[ a ][ 0 ].x;
				int ay = p[ a ][ 0 ].y;
				int cx = p[ b ][ 0 ].x;
				int cy = p[ b ][ 0 ].y;
				int abx = v[ a ].x;
				int aby = v[ a ].y;
				int cdx = v[ b ].x;
				int cdy = v[ b ].y;
				double s = static_cast<double>( cdy * ( cx - ax ) - cdx * ( cy - ay ) )
					/ static_cast<double>( abx * cdy - cdx * aby );
				double t = static_cast<double>( aby * ( cx - ax ) - abx * ( cy - ay ) )
					/ static_cast<double>( abx * cdy - cdx * aby );
				if( s + EPS > 1.0 || s - EPS < 0.0 ){
					result = 4;
					break;
				}
				if( t + EPS > 1.0 || t - EPS < 0.0 ){
					result = 4;
					break;
				}
				e[ i ].x = p[ i ][ 0 ].x + s * v[ i ].x;
				e[ i ].y = p[ i ][ 0 ].y + s * v[ i ].y;
			}
			if( result != 4 ){
				Vector2<double> tmp;
				tmp.x = e[ 0 ].x;
				tmp.y = e[ 0 ].y;
				for( int i = 0; i < 3; ++i ){
					e[ i ].x -= tmp.x;
					e[ i ].y -= tmp.y;
				}
				double sq = fabs( e[ 1 ].x * e[ 2 ].y - e[ 2 ].x * e[ 1 ].y ) / 2;
				if( sq < EPS ){
					result = 4;
				}else if( sq < 100000 ){
					result = 3;
				}else if( sq < 1000000 ){
					result = 2;
				}else if( sq < 1900000 ){
					result = 1;
				}else{
					result = 0;
				}
			}
		}
		cout << fortune[ result ] << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    int f[5] = {a, b, c, d, e}, sum = 0, min = 99999;
    bool g[5] = {false};
    for(int i = 0; i < 5; i++){
        fill(g, g+5, false);
        sum = 0;
        g[i] = true;

        for(int j = 0; j < 5; j++){
            if(i == j) continue;
            g[j] = true;
            
            for(int k = 0; k < 5; k++){
                if(k == i || k == j) continue;
                g[k] = true;

                for(int l = 0; l < 5; l++){
                    if(l == i || l == j || l == k) continue;
                    g[l] = true;
                    int m = 0;

                    for(int ii = 0; ii < 5; ii++){
                        if(!g[ii]){
                            m = ii;
                            g[m] = true;
                        }
                    }

                    sum = f[i];
                    if(sum%10 != 0) sum += 10 - sum%10;
                    sum += f[j];
                    if(sum%10 != 0) sum += 10 - sum%10;
                    sum += f[k];
                    if(sum%10 != 0) sum += 10 - sum%10;
                    sum += f[l];
                    if(sum%10 != 0) sum += 10 - sum%10;
                    sum += f[m];

                    min = std::min(min, sum);
                    g[l] = false;
                    g[m] = false;
                }
                g[k] = false;
            }
            g[j] = false;
        }
    }
    cout << min << endl;
    return 0;
}

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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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


int main(){
    int n,d;
    cin>>n>>d;
    cout<<(n+2*d)/(2*d+1)<<endl;
    return 0;
}

Measured memory_bytes: 256
import fractions
[a,b,k] = [int(i) for i in input().split()]
counter = 0
c = fractions.gcd(a,b)
for i in range(c,0,-1):
    if c % i == 0:
        counter += 1
        #print(i)
    if counter == k:
        print(i)
        break


Measured memory_bytes: 5472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  int res = 0;
  bool ok = true;
  while (ok)
  {
    for (auto &n : a)
    {
      if (n % 2)
      {
        ok = false;
        break;
      }
      n /= 2;
    }
    if (ok)
      res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MAXN=1e5+10;
#define ll long long
using namespace std;
ll readll(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int readint(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
int num[MAXN];
int main(){
    int n;int k;n=readint();k=readint();
    ll ans=0;
    for(int i=k+1;i<=n;i++){
        if(n%i){
            ll tt=n/i;ans+=tt*(i-k);
            if(n%i>=k){
                if(k) ans+=n%i-k+1;
                else ans+=n%i;
            }
        }
        else{
                ll t=n/i;
                ans+=(i-k)*t;
            }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
from math import factorial


def solve(n,lst):
    nums = list(range(1,n+1))
    counter = 0
    for i in range(n):
        counter += (nums.index(lst[i])) * factorial(n-i-1)
        nums.pop(nums.index(lst[i]))
    return counter + 1




def main():
    n = int(input())
    lst1 = list(map(int,input().split()))
    lst2 = list(map(int,input().split()))
    lst1_ans = solve(n,lst1)
    lst2_ans = solve(n,lst2)
    answer = abs(lst1_ans - lst2_ans)
    print(answer)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    ll minA = 1LL << 60, maxA = 0;
    vector<ll> diff;
    ll prev = 0;
    REP(i, 0, n) {
        ll v;
        cin >> v;
        chmin(minA, v);
        chmax(maxA, v);
        if (i != 0) {
            diff.push_back(v - prev - 1);
        }
        prev = v;
    }

    ll ans = maxA - minA + 1;
    sort(diff.rbegin(), diff.rend());
    REP(i, 0, k - 1) {
        ans -= diff[i];
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
  double L; cin >> L;
  L = L/3;
  double ans = L*L*L;
  printf("%lf\n", ans);
  return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	int a[n+5];
	rep(i,1,n)
	{
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	int x= a[n/2];
	int y= a[n/2 + 1];
	int ans= y - (x);
	if(ans<0)
		ans=0;
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void)
{
	int W, H, x, y, r, a, b, c, d;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	a = x + r;
	b = x - r;
	c = y + r;
	d = y - r;

	if ((W >= a) && (b >= 0))
	{
		if ((H >= c) && (d >= 0))
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 2104
def main(N, X):
    lst = list(map(int, list(X)))
    num = lst.count(1)  # 初期状態で1を持つ数．

    def func(x):    # xは10進数
        lst = list(bin(x)[2:])
        amari =  x % lst.count('1')
        return amari

    d = {}
    for i in range(1, N):
        d[i] = func(i)


    # 反転させるので num + 1 か， num - 1 で割る場合しか存在しない．
    plus = []   # num + 1 で各桁 (2 ** n) を割った値を保存
    minus = []  # num - 1 で各桁 (2 ** n) を割った値を保存

    p = 1
    m = 1
    for n in range(N):
        p %= (num + 1)
        plus.append(p)
        p *= 2
        if num - 1 > 0:
            m %= (num - 1)
            minus.append(m)
            m *= 2

    o = int(X, 2)   # originalの 'o'
    amari_plus = o % (num + 1)
    if num - 1 > 0:
        amari_minus = o % (num - 1)

    for i in range(N):
        if lst[i] == 0:
            amari = (amari_plus + plus[- i - 1]) % (num + 1)
        elif num - 1 <= 0:
            print(0)
            continue
        else:
            amari = (amari_minus + (num - 1) - minus[- i - 1]) % (num - 1)
        ans = 1
        while amari != 0:
            amari = d[amari]
            ans += 1
        print(ans)

if __name__ == '__main__':
    N = int(input())
    X = input()
    main(N, X)


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

int main()
{
    int n, m;
    int sum = 0; //n_day,homework_m
    cin >> n >> m;
    int a;
    for (int i = 1; i < m + 1; i++)
    {
        cin >> a;
        sum += a;
    }
    if (n < sum)
    {
        cout << "-1" << endl;
    }
    else
    {
        cout << n - sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int64_t g(int64_t a,int64_t b){
  if(a==0)
    return b;
  return g(b%a,a);
}
int main(){
  int n;
  cin>>n;
  int p=1000000007;
  map<vector<int64_t>,int> m;
  for(int _=0;_<n;_++){
    int64_t a,b;
    cin>>a>>b;
    if(a==0||b==0){
      if(a==0&&b==0)
        m[{a,b}]++;
      else
        m[{a/g(a,b),b/g(a,b)}]++;
      continue;
    }
    int s=(a>0^b>0?-1:1);
    a=abs(a);
    b=abs(b);
    m[{a/g(a,b)*s,b/g(a,b)}]++;
  }
  int z=m[{0,0}];
  m.erase({0,0});
  int64_t c=1;
  while(!m.empty()){
    auto k=(*m.begin()).first;
    auto kp=k;
    int64_t a=k.at(0);
    int64_t b=k.at(1);
    if(a==0||b==0)
      kp={b,a};
    else
      kp={b*(a<0?1:-1),abs(a)};
    int64_t x,y;
    x=m[k];
    y=m[kp];
    int64_t cx=1;
    for(int i=0;i<x;i++)
      cx=cx*2%p;
    int64_t cy=1;
    for(int i=0;i<y;i++)
      cy=cy*2%p;
    c=c*(cx+cy-1)%p;
    m.erase(k);
    m.erase(kp);
  }
  cout<<(c+z-1+p)%p<<endl;
}

Measured memory_bytes: 25324
from collections import deque
N = int(input())

AM, Am, BM, Bm = -1*10**9*2, 10**9*2, -1*10**9*2, 10**9*2
for _ in range(N):
    x, y = map(int, input().split())
    AM = max(AM, x+y)
    Am = min(Am, x+y)
    BM = max(BM, x-y)
    Bm = min(Bm, x-y)


print(max(AM-Am, BM-Bm))

Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
//#define MOD 1000000007
const int INF = 1LL<<30;

vector<vector<int>> cnt(26);

int main() {
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int m=t.size();

    rep(i,n){
        cnt[s[i]-'a'].push_back(i);        
    }

    ll ans=0;
    int x=-1;
    rep(i,m){
        int c=t[i]-'a';
        if(cnt[c].empty()){
            cout<<-1<<endl;
            return 0;
        }
        int ind=upper_bound(all(cnt[c]),x)-cnt[c].begin();
        if(ind==cnt[c].size()){
            ans+=n;
            x=cnt[c][0];
        }
        else x=cnt[c][ind];
    }

    cout<<ans+x+1<<endl;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
using namespace std;

ll a,b,c,k;
int main(){
	// debug;
	ios;

	cin>>a>>b>>c>>k;
	ll ans;
	if(k <= a) ans = k;
	else if(k <= a+b) ans = a;
	else ans = a - (k - a - b);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 3656
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let A = read::<i32>();
    let B = read::<i32>();
    let C = read::<i32>();

    if A <= C && C <= B {
        println!("Yes");
    }else {
        println!("No");
    }
}


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

int main(){

    int N,K;

    string S;

    cin >>N>>K>>S;

    if(S[K-1] == 'A')S[K-1] ='a';
    if(S[K-1] == 'B')S[K-1] ='b';
    if(S[K-1] == 'C')S[K-1] ='c';

    cout <<S<<endl;
    return 0;
}

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

using namespace std;

int main()
{
  string A,B;
  cin >> A;
  cin >> B;

  string result;
  if (A.size()>B.size()) {
    result = "GREATER";
  } else if (A.size()<B.size()) {
    result = "LESS";
  } else {
    result = "EQUAL";
    for (unsigned ii=0; ii<A.size(); ++ii) {
      if (A[ii]>B[ii]) {
	result = "GREATER";
	break;
      } else if (A[ii]<B[ii]) {
      	result = "LESS";
	break;
      }
    }
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int K, Q;
ll d[5000], d2[5000];
ll sum = 0;

signed main(){
	cin >> K >> Q;
	rep(i, K){
		cin >> d[i];
		sum += d[i];
	}

	rep(q, Q){
		ll n, x, m;
		cin >> n >> x >> m;
		x %= m;

		ll ans = 0;

		ll c = 0;
		ll now = 0;
		rep(i, K){
			if(now < (now+d[i])%m) c++;
			now += d[i];
			now %= m;
		}

		ll T = (n-1) / K;
		ans = c * T - (x+(sum%m)*T)/m;
		//cout << ans << endl;

		now = x + (sum%m)*T;
		now %= m;
		rep(i, (n-1) % K){
			if(now < (now+d[i])%m) ans++;
			now += d[i];
			now %= m;
		}
		cout << ans << endl;
	}
}
/*
5 26
1 2 4 2 3
2 0 5
3 0 5
4 0 5
5 0 5
6 0 5
7 0 5
8 0 5
9 0 5
10 0 5
11 0 5
12 0 5
13 0 5
14 0 5
15 0 5
16 0 5
17 0 5
18 0 5
19 0 5
20 0 5
21 0 5
22 0 5
23 0 5
24 0 5
25 0 5
26 0 5
27 0 5

//84
7 1
3 6 4 6 4 10 4
76 3 12
*/

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


//verified
//note that this is 1-index
template<class T>
class BIT{
private:
	vector<T> sum_of_section_;
	int elements_count_;
	T init_;
	
public:
	BIT(int elements_count=0 , T init=0):elements_count_(elements_count*2),init_(init),sum_of_section_(elements_count*2+1,0){
		for(int i=0;i<elements_count_;i++) add(i+1,init);
	}
	
	T sum(int i){   //(1,i)
		int sum=0;
		while(i>0){
			sum+=sum_of_section_[i];
			i -= i&-i;
		}
		return sum;
	}
	
	void add(int i,T val){
		while(i<=elements_count_){
			sum_of_section_[i]+=val;
			i += i&-i;
		}
	}
};


int main(){
	int n,m;
	cin>>n>>m;
	vector<pair<int,pii>> v(n);
	rep(i,n){
		int l,r;
		cin>>l>>r;
		v[i] = make_pair(r-l+1,pii(l,r));
	}
	sort(all(v));
	

	int p = 0;
	BIT<int> bt(100001,0);
	vector<int> ans(m+1,0);
	for(int i=1;i<=m;i++){
		for(int j=1;j*i<=m;j++){
			ans[i]+=bt.sum(j*i);
		}
		ans[i]+=n-p;
		while(p<n && v[p].first<=i){
			int l,r;
			tie(l,r) = v[p].second;
			bt.add(l,1);
			bt.add(r+1,-1);
			p++;
		}
	}
	for(int i=1;i<=m;i++) cout<<ans[i]<<endl;
}

Measured memory_bytes: 5632
import sys

n = int(input())
a = list(map(int,input().split()))
a.sort()

if 0 in a:
    print(0)
else:
    cur = 1
    for x in a:
        cur *= x
        if cur > 10 ** 18:
            print(-1)
            sys.exit()
    print(cur)


Measured memory_bytes: 21664
package main

import (
	"fmt"
)

func main() {
	var h, n int
	fmt.Scan(&h, &n)

	list := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&list[i])
	}

	result := "No"

	for i := 0; i < n; i++ {
		h = h - list[i]
		if h <= 0 {
			result = "Yes"
		}
	}
	fmt.Println(result)

}


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

int a, b;
char op;

signed main() {
	cin >> a >> op >> b;
	if (op == '+') {
		cout << a + b << endl;
	} else {
		cout << a - b << endl;
	}
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func cumSum(a []int) []int {
	res := make([]int, len(a)+1)
	var sum = 0
	for i := 1; i <= len(res)-1; i++ {
		sum += a[i-1]
		res[i] = sum
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := ri(), ri()

	a := make([]int, n+1)
	for i := 0; i < m; i++ {
		l, r := ri()-1, ri()-1
		a[l]++
		a[r+1]--
	}

	cs := cumSum(a)

	ans := 0
	for _, v := range cs {
		if v == m {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2304
//パーティション
//2018-12-21
//Ebitani Akira

#include <stdio.h>
#include <stdlib.h>

#define N 100000

int Array[N];
int n;

int main (){
  int i, p;

  scanf( "%d", &n );
  if( n < 1 || n > 100000 ){
    printf( "要素数が適当ではありません。\n" );
    exit(1);
  }
  for( i = 0 ; i < n ; i++ ){
    scanf( "%d", &Array[i] );
  }

  p = partition( 0, n - 1 );

  for( i = 0 ; i < n ; i++ ){
    if( i == p ){
      printf( "[" );
    }
    
    printf( "%d", Array[i] );
    
    if( i == p ){
      printf( "]" );
    }


    if( i != n - 1 ){
      printf( " " );
    }
  }
  printf( "\n" );
  return 0;
}

int partition( int a, int b ){
  int A, i, j, temp;

  A = Array[b];
  i = a - 1;

  for( j = a ; j < b ; j++ ){
    if( Array[j] <= A ){
      i++;
      temp = Array[i];
      Array[i] = Array[j];
      Array[j] = temp;
    }
  }

  temp = Array[i+1];
  Array[i+1] = Array[b];
  Array[b] = temp;

  return i + 1;
}
      



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

long long v[100000];

int main() {
	long long n,k;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		long long a,b;
		cin >> a >> b;
		v[a - 1] += b;
	}

	for(int i = 0;i < 100000;i++){
		if(v[i] >= k){
			cout << i + 1 << endl;
			return 0;
		}
		k -= v[i];
	}
	return 0;
}


Measured memory_bytes: 1024
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    ans = []
    for h in range(H):
        for w in range(W-1):
            if A[h][w] % 2 == 1:
                A[h][w] -= 1
                A[h][w+1] += 1
                ans.append([h+1,w+1,h+1,w+2])

    for h in range(H-1):
        if A[h][W-1] % 2 == 1:
            A[h][W-1] -= 1
            A[h+1][W-1] += 1
            ans.append([h+1,W,h+2,W])
    print(len(ans))
    for a in ans:
        print(*a)



if __name__ == "__main__":
    main()

Measured memory_bytes: 88764