akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N);
    vector<int>B(N);
    vector<int>C(N - 1);
    rep(i, N)cin >> A[i];
    rep(i, N)cin >> B[i];
    rep(i, N - 1)cin >> C[i];
    long long ans = B[A[0]-1];
    REP(i, N) {
        ans += B[A[i]-1];
        if (A[i] - 1 == A[i - 1])ans += C[A[i-1]-1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
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 fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    int n , k ; 
    cin >> n >> k ; 
    string s ; 
    cin >> s ; 
    vector<int> groups ; 
    groups.push_back(0) ;
    for(int i=0;i<n;){
    	char c = s[i] ; 
    	int cnt = 0 ; 
    	while(i < n && c == s[i]) cnt++, i++ ;
    	groups.push_back(cnt) ; 
    }
    groups.push_back(0) ;
    n = (int) groups.size() ; 
    if ( n == 3 ){
    	return cout << groups[1] << endl , 0 ; 
    }
    debug() << imie(n) ; 
    vector<int> sum(n+1) ; 
    for(int i=0;i<n;i++){
    	sum[i+1] = sum[i] + groups[i];
    }
    debug() << imie(groups) ; 
    debug() << imie(sum) ; 
    int t = n / 2 ; 
    if ( n & 1 && s[0] == '0' ) t++;
    if ( k >= t ) {
    	return cout << (int) s.size() << endl , 0 ; 
    }
    int window = k + (k - 1) + 2 ; 
    if ( s[0] == '0' ){
    	int ans = 0 ; 
    	for(int i=1;i<n;i+=2){
    		if ( i - 1 + window <= n )
    			ans = max(ans, sum[i-1+window] - sum[i-1] );
    	}
    	cout << ans << endl;
    }
    else{
    	int ans = 0 ; 
    	for(int i=2;i<n;i+=2){
    		if ( i - 1 + window <= n )
    			ans = max(ans, sum[i-1+window] - sum[i-1] );
    	}
    	cout << ans << endl;
    }
    return 0 ;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vi l(n);
  rep(i, n) {
    cin >> l[i];
  }

  ll ans = 0;
  sort(all(l));

  rep(i, n) {
    for (int j = i+1; j < n; j++) {
      auto it = lower_bound(all(l), l[i]+l[j]);
      auto itt = lower_bound(all(l), abs(l[i]-l[j])+1);
      int cnt = it-itt;
      if (abs(l[i]-l[j]) < l[i] && l[i] < l[i]+l[j]) cnt--;
      if (abs(l[i]-l[j]) < l[j] && l[j] < l[i]+l[j]) cnt--;
      ans += cnt;
    }
  }
  cout << ans/3 << endl;
}


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

int main() {
  ll k,j,z;
  cin>>k;
  int ans=0;
  for(ll i=1;i*i<=k;i++){
    if(k%i==0){
      if(i==1){
        goto skip;
      }
      z=k;
      while(z%i==0){
        z/=i;
      }
      if(z%i==1){
        ans++;
      }
      skip:
      j=k/i;
      z=k;
      if(i!=j){
        while(z%j==0){
          z/=j;
        }
        if(z%j==1){
          ans++;
        }
      }
    }
    if((k-1)%i==0){
      if((k-1)/i!=i){
        ans++;
      }
      ans++;
      if(i==1||(k-1)/i==1){
        ans--;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
n, x, y = map(int, input().split())

cnt = [0] *n
for ind1 in range(1,n+1):
    for ind2 in range(ind1+1,n+1):
        cur_dist = min(ind2-ind1, abs(x-ind1)+abs(y-ind2)+1)
        # print(ind1,ind2,cur_dist)
        cnt[cur_dist] += 1
# print(cnt)            
for k in range(1,n):
    print(cnt[k])




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

using namespace std;

int main()
{
  int n; cin >> n;
  long long sum = 0;
  for(int i = 1; i <= n; i++)
  {
    if(i%3 != 0 and i%5 != 0)
      sum += i;
  }
  cout << sum << endl;
  return 0;
}
    

Measured memory_bytes: 3560
import java.util.*;

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

        int[] b = new int[total];

        for (int k = 0; k < total; k++) {
            int a = inp.nextInt();

            b[k] = a;
        }

        shellSort(b, total);
    }

    public static int insertionSort(int[] b, int n, int g) {
        int counter = 0;
        for (int i = g; i < n; i++) {
            int v = b[i];
            int j = i - g;
            while (j >= 0 && b[j] > v) {
                b[j + g] = b[j];
                j = j - g;
                counter++;
            }

            b[j + g] = v;
        }

        return counter;
    }

    public static void shellSort(int[] b, int n) {
        int counter = 0;
        int m = 0;
        int g[] = new int[100];

        for (int i = 1; i <= n; i=i*3+1) {
            g[m] = i;
            m++;
        }

        System.out.println(m);

        m--;

        for (int i = m; i >= 0; i--) {
            counter += insertionSort(b, n, g[i]);

            if (i == 0) {
                System.out.printf(" %d", g[i]);
            } else {
                System.out.printf(" %d", g[i]);
            }
        }

        System.out.println("\n" + counter);

        for (int i = 0; i < n; i++) {
            System.out.println(b[i]);
        }
    }
}



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

struct vector{
	double x;
	double y;
};

void printVector(vector v){
		cout <<   v.x << " " << v.y  << endl;
}

void drawCock(vector begin, vector end, int depth){
	if(depth == 0){
		printVector(begin);
	}else{
		depth --;
		vector v[3];
		v[0].x = (begin.x * 2.0 + end.x)/3.0;
		v[0].y = (begin.y * 2.0 + end.y)/3.0;
		v[2].x = (begin.x + end.x * 2.0)/3.0;
		v[2].y = (begin.y + end.y * 2.0)/3.0;
		v[1].x = v[0].x + (v[2].x - v[0].x) * cos(M_PI/3.0) - (v[2].y - v[0].y) * sin(M_PI/3.0); 
		v[1].y = v[0].y + (v[2].x - v[0].x) * sin(M_PI/3.0) + (v[2].y - v[0].y) * cos(M_PI/3.0);

		drawCock(begin, v[0], depth);
		drawCock(v[0], v[1], depth);
		drawCock(v[1], v[2], depth);
		drawCock(v[2], end, depth);
		
	}
}

int main(){
	cout << fixed << setprecision(8);
	ios_base::sync_with_stdio(false);
	vector begin = {0,0};
	vector end = {100,0};
	int num;
	cin >> num;
	drawCock(begin,end,num);
	printVector(end);
	return 0;
}

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

typedef long long LL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e1 + 10;
int a[MAXN], b[MAXN], c[MAXN-1];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	LL ans = 0;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
	{
		cin >> b[i];
		ans += b[i];
	}
	for (int i = 0; i < n-1; ++i)
		cin >> c[i];
	for (int i = 1; i < n; ++i)
	{
		if (a[i] == a[i - 1] + 1)
		{
			//cout << c[a[i - 1]-1] << endl;
			ans += c[a[i - 1]-1];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
mt19937 rnd(1337);
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pNN pair <Node *, Node *>
#define SZ(x) (int)(x).size()
#define pii pair <int, int>
#define pb push_back
#define rev reverse
#define ins insert
#define ers erase
#define S second
#define F first
#define int ll
const int N = 1e5 + 10, INF = 1e9 + 10;

void solve() {
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << ' ' << x << ' ' << y; 
}
 
signed main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    #ifdef Solenoid555
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    //cin >> t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
import sys

def main():
    X = int(input())
    
    if X == 2:
        print('2')
        sys.exit()

    while True:
        for j in range(2, X):
            if X % j == 0:
                break

            if X % j == 1 and j == X-1:
                print(X)
                sys.exit()
            
        X+=1

main()


Measured memory_bytes: 2940
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<c-(d-b)<<" "<<d+c-a<<" "<<a+b-d<<" "<<b+c-a<<endl;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M = 1000001;
  int i,j,ct;
  int w=0,x;

  vector<int> c(M,0);
  cin >> N;
  for(i=0;i<N;i++){
    cin >> x;
    c[x] = 1;
    w = gcd(w,x);
  }

  if (w>1){
    cout << "not coprime" << endl;
    return 0;
  }
  
  for(i=2;i<M;i++){
    ct = 0;
    for(j=1;j*i<M;j++)
      if (c[j*i])
        ct++;
    if (ct>1){
      cout << "setwise coprime" << endl;
      return 0;
    }
  }

  cout << "pairwise coprime" << endl;
  return 0;
}

Measured memory_bytes: 7068
# from math import factorial,sqrt,ceil
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n = int(input())

ans = 0
for i in range(1,n+1):
    if i%3==0 or i%5==0:
        pass
    else:
        ans += i

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9096
class Grid
  attr_reader :h, :w
  attr_accessor :grid

  def initialize(h, w)
    @h = h
    @w = w
    @grid = []
  end

  def count_mine(r, c)
    cnt = 0

    # 上のrow
    if 1 <= r
      row = @grid[r-1]
      # 左
      cnt += 1 if 1 <= c && row[c-1] == "#"
      # 中
      cnt += 1 if row[c] == "#"
      # 右
      cnt += 1 if c+1 < @w && row[c+1] == "#"
    end

    # 下のrow
    if r < @h-1
      row = @grid[r+1]
      # 左
      cnt += 1 if 1 <= c && row[c-1] == "#"
      # 中
      cnt += 1 if row[c] == "#"
      # 右
      cnt += 1 if c+1 < @w && row[c+1] == "#"
    end

    # 自分のrow
    row = @grid[r]
    # 左
    cnt += 1 if 1 <= c && row[c-1] == "#"
    # 右
    cnt += 1 if c+1 < @w && row[c+1] == "#"

    cnt
  end

  def replace_mine_count
    0.upto @h-1 do |r|
      0.upto @w-1 do |c|
        if @grid[r][c] == "."
          @grid[r][c] = count_mine(r, c)
        end
      end
    end
  end

  def print_result
    @grid.each do |row|
      0.upto(@w-1) do |c|
        print row[c]
      end
      puts
    end
  end

end

def main
  h, w = ARGF.gets.split.map(&:to_i)

  g = Grid.new(h, w)
  h.times do
    g.grid << ARGF.gets.chars
  end

  g.replace_mine_count

  g.print_result
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a)  a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define _for(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)

using namespace std;

int main(){
   int N;
   cin >> N;
   vector<int> a;
   int x;
   for(int n = 0; n < 2 * N; ++n){
      scanf("%d", &x);
      a.pb(x);
   }   
   sort(all(a));
   int res = 0;
   for(int n = 0; n < a.sz; n += 2){
      res += a[n];
   }
   cout << res << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int grt(int a,int b,int c)
{
    int p=__gcd(a,b);
    return __gcd(p,c);
}


int main()
{
    int p;
    cin>>p;
    long int sum=0;
    for(int i=1;i<=p;i++)
        for(int j=1;j<=p;j++)
            for(int k=1;k<=p;k++)
                sum+=grt(i,j,k);
    cout<<sum;

    return 0;
}


Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;

int a[100001];

int mpow(int b, int e)
{
    int ret=1;
    for(int i=0; i<e; i++)
    {
        ret=ret*b%mod;
    }
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    for(int i=0; i<y2-y1; i++)
        cout << 'U';
    for(int i=0; i<x2-x1; i++)
        cout << 'R';
    for(int i=0; i<y2-y1; i++)
        cout << 'D';
    for(int i=0; i<x2-x1; i++)
        cout << 'L';
    cout << 'D';
    for(int i=0; i<x2-x1+1; i++)
        cout << 'R';
    for(int i=0; i<y2-y1+1; i++)
        cout << 'U';
    cout << "LU";
    for(int i=0; i<x2-x1+1; i++)
        cout << 'L';
    for(int i=0; i<y2-y1+1; i++)
        cout << 'D';
    cout << 'R';
}

//TODO: 51
//come back to 50D,


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    ll h[n+1],d[n+1],a[n+1],s[n+1];
    ll ans=0;
    rep(i,n+1){
        cin>>h[i]>>a[i]>>d[i]>>s[i];
        if(i>0){
            a[i]-=d[0];
            d[i]=a[0]-d[i];
            if(a[i]<0)a[i]=0;
            if(d[i]<=0){
                if(a[i]>0){
                    cout<<-1<<endl;
                    return 0;
                }
                else d[i]=inf;
            }
            if(s[i]>s[0]){
                ans+=a[i];
            }
            h[i]=(h[i]+d[i]-1)/d[i];
        }
    }
    vector<int> ord(n);
    iota(ord.begin(),ord.end(),1);
    sort(ord.begin(),ord.end(),[&](int i,int j){
        return h[i]*a[j]<h[j]*a[i];
    });
    ll cur=0;
    for(auto i : ord){
        cur+=h[i];
        ans+=a[i]*(cur-1);
        if(ans>=h[0]){
            cout<<-1<<endl;
            return 0;
        }
    }
    if(ans<=h[0])cout<<ans<<endl;
    else cout<<-1<<endl;   
    return 0;
}


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

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

vector<int> vec(N);

  
for(int i=0;i<N;i++){
  cin>>vec.at(i);
}
  
  int count =0;
  
  for(int i=0;i<N;i++){
    if(vec.at(i)>=k){
      count+=1;
    }
  }
  
  cout << count <<endl;
    
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;

int main(){

    int n;
    cin >> n;

    vector<string> vs(n);
    vector<ll> vt(n);

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

    string x;
    cin >> x;
    bool flag = false;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(flag){
            ans += vt[i];
        }

        if( x == vs[i] ){
            flag = true;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
import sys


def main():
    input = sys.stdin.readline
    n, l = map(int, input().split())
    s = [input().rstrip() for i in range(n)]

    s.sort(key=lambda x: [x[i] for i in range(l)])

    print(''.join(s))


if __name__ == '__main__':
    main()


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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int h,w;
	cin >> h >> w;
	char c[h][w];
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> c[i][j];
		}
	}
	int ok = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(c[i][j] == '.')continue;
			if(i != 0 && c[i][j] == '#' && c[i - 1][j] == '#')continue;
			if(i != h - 1 && c[i][j] == '#' && c[i + 1][j] == '#')continue;
			if(j != 0 && c[i][j] == '#' && c[i][j - 1] == '#')continue;
			if(j != w - 1 && c[i][j] == '#' && c[i][j + 1] == '#')continue;

			ok = 1;
		}
	}
	if(ok)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0; 
}

Measured memory_bytes: 256
/*Made by Shivam Solanki*/
#include<bits/stdc++.h> 
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define repllr(i,k,n) for (ll i = n; i >= k; --i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
const int N = 1e5+5;
int n, m, k;
int f[N],sz[N],cnt[N];
int find1(int x){
	if(x==f[x]) return x;
	return find1(f[x]);
}

void merge1(int x, int y){
	int fx = find1(x), fy = find1(y);
	if(fx!=fy)
	{
		if(sz[fx]>sz[fy]) swap(fx, fy);
		f[fx] = fy;
		sz[fy] += sz[fx];
	}
}
void solve(){
    int n,m,k;
    cin>>n>>m>>k;
    rep(i,0,n){
        sz[i]=cnt[i]=1,f[i]=i;
    }
    rep(i,0,m){
        int u,v;
        cin>>u>>v;
        u--,v--;
        merge1(u,v);
        cnt[u]++,cnt[v]++;
    }
    rep(i,0,k){
        int u,v;
        cin>>u>>v;
        u--,v--;
        int fx=find1(u),fy=find1(v);
        if(fx==fy) cnt[u]++,cnt[v]++;
    }
    rep(i,0,n){
        cout<<max(0,sz[find1(i)]-cnt[i])<<' ';
    }
    cout<<'\n';
} 
 
  
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

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

using namespace std;

int main()
{
	for (int i = 0; i < 3; i++) {
		int h, m, s, h_out, m_out, s_out, H = 0, M = 0, S = 0;
		cin >> h >> m >> s >> h_out >> m_out >> s_out;
		if (s_out >= s) {
			S = s_out - s;
		}
		else {
			S = (60-s)+s_out;
			if (m_out == 0) {
				m_out = 59;
				h_out--;
			}
			else {
				m_out--;
			}
		}if (m_out >= m) {
			M = m_out - m;
		}
		else {
			M = (60-m)+m_out;
			h_out--;
		}
		if (h_out >= h) {
			H = h_out - h;
		}
		cout << H <<" "<< M <<" "<< S << endl;

	}
	return 0;
}

Measured memory_bytes: 1164
N = int(input())
L = list(map(int, input().split()))
L.sort()

if(N <= 2):
  print(0)
  exit()

ans = 0
for i in range(N):
  for j in range(i+1, N):
    for k in range(j+1, N):
      if(L[i]+L[j]>L[k] and L[i] != L[j] and L[j] != L[k]):
        ans += 1
        
print(ans)

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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long int lli;

int main()
{
	fio;
	int a,b;
	cin>>a>>b;
	if(max(a,b)<=8) cout<<"Yay!"<<endl;
	else cout<<":("<<endl;
	cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int main () {
  int y, m, d;
  char c1, c2;
  cin>>y>>c1>>m>>c2>>d;
  if(m<=4){
    cout << "Heisei" << endl ;
  }else{
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
<?php
  
  $n = intval(fgets(STDIN));

  $e = preg_split('/\s/', fgets(STDIN));
 
  $en = [$e[0]];
  
  for($i = 1; $i < $n; $i++) {
    $en[$i] = min($en[$i-1], $e[$i]);
  }
  $cnt = 0;
  for($i = 0; $i < $n; $i++) {
    $ii = $e[$i];
    $ij = $en[$i];

      if ($ii <= $ij) $cnt++;
  }

echo $cnt;

Measured memory_bytes: 58244
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {

	int n;
	cin >> n;
	vector<int>a(n), b(n), c(n - 1);

	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n - 1) cin >> c[i];

	rep(i, n) a[i]--;

	int ans = b[a[0]];
	for (int i = 1; i < n;i++) {
		ans += b[a[i]];

		if (a[i] - a[i - 1] == 1)
			ans += c[a[i - 1]];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
A,B = list(map(int,input().split()))
p = list(map(int,input().split()))

a = []
b = []
c = []

for i in p:
    if i <= A:
        a.append(i)
    elif (A+1 <= i) and (i <= B):
        b.append(i)
    else:
        c.append(i)

print(min(len(a),len(b),len(c)))

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

std::string solve(int a, int b, int c)
{
  if (a == b && a != c) return "Yes";
  if (a == c && a != b) return "Yes";
  if (b == c && a != b) return "Yes";
  return "No";
}

int main()
{
  int a, b, c;
  std::cin >> a >> b >> c;

  std::cout << std::setprecision(20) << solve(a, b, c) << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

using namespace std;

ll n;

int main(){
	cin.sync_with_stdio(0);
	cin >> n;	
	
	double sE; cin >> sE;
	double dp[n][n + 1] = {{ 0 }};
	dp[0][0] = 1.0 - sE;
	dp[0][1] = sE;
	
	FOR(number, 1, n) {
		double nE; cin >> nE;
		
		dp[number][0] = (1 - nE) * dp[number - 1][0];
		FOR(heads, 1, n + 1) {
			dp[number][heads] = nE * dp[number - 1][heads - 1] + (1 - nE) * dp[number - 1][heads];
		}
	}
	
	double output = 0;
	FOR(i, (n + 1) / 2, n + 1) {
		output += dp[n - 1][i];
	}
	
	cout << setprecision(15) << output << endl;
	
	return 0;
}

Measured memory_bytes: 70528
x,y,z,n = map(int, input().split())
a = sorted(list(map(int, input().split())),reverse = True)
b = sorted(list(map(int, input().split())),reverse = True)
c = sorted(list(map(int, input().split())),reverse = True)
d = []
for i,i1 in enumerate(a):
  for j,j1 in enumerate(b):
    if (i+1)*(j+1) <= n:
      for k,k1 in enumerate(c):
        if (i+1) * (j+1) * (k+1) <= n:
          d.append(i1 + j1 + k1)
        else:
          break
    else:
      break
d.sort(reverse = True)
for i in d[:n]:
  print(i)


Measured memory_bytes: 8728
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  for(int i=n/2*2; i>=0; i-=2) {
    if(n == i) continue;
    if(s.substr(0, i/2) == s.substr(i/2, i/2)) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << 0 << "\n";
  return 0;
}


Measured memory_bytes: 3668
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
const int mxn=1e5+1;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll t=1;
  //cin>>t;
    while(t--){
            ll a,b;
    cin>>a>>b;
    ll n=b-a-1;
    ll x=(n*(n+1))/2-a;
    cout<<x;

    }
  return 0;
  }



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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;

const ll MOD = 1e9+7;

// n^m%MOD を求める。O( log(m) )
ll modpow(ll n, int m){
	ll ret=1;
	for(int i=1; i<=m; i<<=1, (n*=n)%=MOD){
		if( m&i ) (ret *= n) %= MOD;
	}
	return ret;
}

// 逆元を求める
ll modinv(ll n){
	return modpow( n, MOD-2 );
}

// 階乗を求める。O(1)  準備O( n*log(n) )
// fact[n]     : nの階乗
// fact.inv[n] : nの階乗の逆元
class FACTORIAL{
public:
	vector<ll> fact, inv;
	FACTORIAL(int MAX_NUM): fact(MAX_NUM), inv(MAX_NUM) {
		fact[0] = inv[0] = 1;
		for(ll i=1; i<MAX_NUM; i++){
			fact[i] = (fact[i-1] * i) % MOD;
			inv[i] = modinv( fact[i] );
		}
	}
	const ll& operator [ ] ( const int i ) const {
		return fact[i];
	}
} fact(200006); // nの最大値を指定


// 組み合わせ(Combinationを求める) O(1)
ll cmb(unsigned int n, unsigned int r){
	if( n < r ) return 0;
	return fact[n] * fact.inv[r] % MOD * fact.inv[n-r] % MOD;
}


vector<int> edge[200005];
map<int,pll> memo[200005];
pll solve(int n, int b){
	if(memo[n].count(b)) return memo[n][b];
	if(b >= 0 && memo[b].count(n)){
		auto all = solve(n, -1);
		auto sub = solve(b, n);
		ll sum = all.X;
		sum = sum * modinv(sub.X) % MOD;
		sum = sum * modinv(cmb(all.Y - 1, sub.Y)) % MOD;
		ll cnt = all.Y - sub.Y;
		return memo[n][b] = pll(sum, cnt);
	}
	ll sum=1, cnt=0;
	for(auto t: edge[n]) if(t != b){
		auto ret = solve(t,n);
		cnt += ret.Y;
		sum = sum * cmb(cnt, ret.Y) % MOD;
		sum = sum * ret.X % MOD;
	}
	cnt += 1;
	//cout << n << " " << b << ": " << pll(sum, cnt) << endl;
	return memo[n][b] = pll(sum, cnt);
}

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

	cin >> N;
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	vector<ll> ans;
	rep(i,N) ans.push_back(solve(i,-1).X);
	for(auto t: ans) cout << t << "\n";

	return 0;
}

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

int main(){
    ll N,X;
    cin>>N>>X;
    ll max = 0;
    rep(i, N){
        ll x; cin>>x;
        max = __gcd(abs(X-x), max);
    }

    cout << max << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define l long 
#define V vector<vector<ll>>
using namespace std;
ll util(int i,int j,vector<ll>&sum,vector<l>&arr,V &dp){
	if(i==j)
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	ll res=LONG_LONG_MAX;
	for(int k=i;k<j;k++){
		ll temp=util(i,k,sum,arr,dp)+util(k+1,j,sum,arr,dp)+sum[j];
		if(i-1>=0)
			temp-=sum[i-1];
		res=min(res,temp);
	}
	dp[i][j]=res;
	return dp[i][j];
}
int main(){
	int n;
	cin>>n;
	vector<l>arr(n);
	vector<ll>sum(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(i==0){
			sum[i]=arr[i];
		}else{
			sum[i]=arr[i]+sum[i-1];
		}
	}
	vector<vector<ll>>dp(n,vector<ll>(n,-1));
	cout<<util(0,n-1,sum,arr,dp);
	return 0;
}

Measured memory_bytes: 1536
n = int(input())
f_max = s_max = 0
arr = []
for _ in range(n):
    a = int(input())
    arr.append(a)
    if a >= f_max:
        s_max = f_max
        f_max = a
    elif a >= s_max:
        s_max = a

for integer in arr:
    if integer == f_max:
        print(s_max)
    else:
        print(f_max)
    


Measured memory_bytes: 12560
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;
using llong = long long;
const int MOD=1000000007;


int main(int argc, char**argv){
    int a, b, c;

    cin >> a >> b >> c;

    if (a <= c && c <= b) cout << "Yes" << endl;
    else if (a >= c && c >= b) cout << "Yes" << endl;
    else cout << "No" << endl;



    return 0;
}











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

class P
{
  static int[] Input(){
    return Console.ReadLine().Split().Select(int.Parse).ToArray();
  }

  static int[][] Input2(int n){
    int[][] X = new int[n][];
    for(int i = 0; i < n; i++){
      X[i] = Input();
    }
    return X;
  }

  static void Main()
  {
    int[] HW = Input();
    bool f = false;
    var X = new List<string>();
    string s = "";
    for (int i = 0; i < HW[1]+2; i++){
      s += ".";
    }
    X.Add(s);
    for(int i = 0; i < HW[0]; i++){
      string t = Console.ReadLine();
      t = "." + t + ".";
      X.Add(t);
    }
    X.Add(s);
    for(int i = 1; i < HW[0]+1; i++){
      for(int j = 1; j < HW[1]+1; j++){
        if (X[i][j] == '#'){
          if (X[i+1][j] == '.' && X[i-1][j] == '.' && X[i][j+1] == '.' && X[i][j-1] == '.') f = true;
        }
      }
    }
    Console.WriteLine(f?"No":"Yes");
  }
}


Measured memory_bytes: 13396
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[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; }

int main()
{
    string s; cin >> s;
    int n = s.size();
    int ans = 0;
    for(int i=1;i<s.size();i++){
        if((n-i)%2==1) continue;

        int len = (n-i)/2;
        bool flg = false;
        rep(j, len){
            if(s[j] != s[len+j]) {
                flg = true;
                break;
            }
        }
        if(flg) continue;
        else{
            // rep(j, len){
            //     cout << s[j];
            // }
            // pr("");
            // rep(j, len){
            //     cout << s[len + j];
            // }
            // pr("");
            pr(n-i);
            return 0;
        }
    }
    return 0;}

Measured memory_bytes: 3620
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cctype>
#include<math.h>
using namespace std;
int main() {
	int n, a;
	vector<int> d;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		d.push_back(a);
	}
	sort(d.begin(),d.end());

	cout << (d[n / 2]) - (d[n / 2 - 1]) << endl;

}

Measured memory_bytes: 892
#include<iostream>
#include<vector>

using namespace std;

const int MAX_D = 11;
int m,c,n,ans;
vector<int> req;
vector<int> D[MAX_D];

void input(){
  vector<int> tmp[n];
  int sum = 0;

  for(int i = 0; i < n; i++){
    int num;
    cin >> num;
    sum += num;
    for(int j = 0; j < num; j++){
      int in;
      cin >> in;
      tmp[i].push_back(in);
    }
  }
  
  int pos = 0;
  while(sum){
    for(int i = 0; i < n; i++)
      if(tmp[i].size() > pos){
	req.push_back(tmp[i][pos]);
	sum--;
      }
    pos++;
  }

  D[m] = req;
}

void init(){
  req.clear();
  for(int i = 0; i < MAX_D; i++)
    D[i].clear();
  ans = 0;
}

int find(int num){

  vector<int>::iterator ite;

  for(int i = 0; i <= m; i++)
    for(ite = D[i].begin(); ite < D[i].end(); ite++)
      if(*ite == num){
	D[i].erase(ite);
	return i+1;
      }
}

int ret(int num){
  int cost = 0;

  if(D[0].size() < c){
    D[0].push_back(num);
    return 1;
  }else{
    int minpos = m;
    for(int i = 0; i < m; i++)
      if(D[i].size() < c){
	minpos = i;
	break;
      }

    //from counter to minpos+1
    cost += minpos+1;

    int tmppos = m;
    for(int i = 0; i < m; i++)
      if(i == minpos){
	if(D[i].size()+1 < c){
	  tmppos = i;
	  break;
	}
      }else if(D[i].size() < c){
	tmppos = i;
	break;
      }
    //from 1 to (tmppos+1)
    cost+=tmppos+2;

    D[tmppos].push_back(D[0][0]);
    D[0].erase(D[0].begin());


    D[0].push_back(num);

    //from (minpos+1) to 1
    cost += minpos+2;
  }
  return cost;
}
void solve(){

  for(int i = 0; i < req.size(); i++){
    int fpos = find(req[i]);
    int rcos = ret(req[i]);
    ans += fpos+rcos;
  }
  cout << ans << endl;
}

int main(){

  while(cin >> m >> c >> n && m+c+n){
    init();
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1352
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < static_cast<ll>(n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= static_cast<ll>(n); ++i)
#define RRANGE(i, m, n) for(ll i = static_cast<ll>(m); i >= static_cast<ll>(n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    vector<ll> v(N);
    ll ans = 0;
    ll prev = 0;
    REP(i, N) {
        in >> v[i];
        if (v[i] < prev) {
            ans += prev - v[i];
        } else {
            prev = v[i];
        }
    }
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,n,a) for(int i=n;i>=a;i--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pcnt(n) __builtin_popcount(n)
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const double PI = acos(-1);

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    cout<<(a+b>=k?min(a,k):2*a-k+b);
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define flb(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define mp make_pair
#define pb push_back
#define inf (long long)(1e18+1e15)
typedef pair<int,int> ii;
typedef vector <ll> vi;
typedef vector <pair<int,int> > vii;
typedef vector <vector <int> > vvi;

int main()
{
    int n,k;
    cin>>n>>k;
    vector <int> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    vector <int> li(n);
    li[0]=0;
    for(int i=1;i<n;i++)
    {
        li[i]=inf;
        for(int j=i-1;j>=max(0,i-k);j--)
        {
            li[i]=min(li[i],abs(v[i]-v[j])+li[j]);
        }
    }
    cout<<li[n-1];
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;

int main(void)
{
	int x, y;
	scanf("%d %d", &x, &y);
	if (x == 0 )
	{
		//0->pos
		if (y >= 0)return 0 * printf("%d\n", y);
		//0->neg
		return 0 * printf("%d\n", -y + 1);
	}
	if (y == 0)
	{
		//neg->0
		if (x <= 0)
		{
			return 0 * printf("%d\n",-x);
		}
		return 0 * printf("%d\n", x + 1);
	}
	bool mx = (x > 0);
	bool my = (y > 0);
	if (mx == my && x > y)
	{
		return 0 * printf("%d\n", x - y + 2);
	}
	if (mx ^ my)
	{
		return 0 * printf("%d\n", abs(abs(x) - abs(y)) + 1);
	}
	return 0 * printf("%d\n", y - x);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N], ans;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], a[i]--, ans += (a[i] == i);
	for (int i = 0; i < n; i++) {
		if (a[i] == i && a[i + 1] == i + 1)
			ans--, i++;
	}
	cout << ans;
	return 0;
}


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

#define REP(i, a, b)  for(int i = a, _b = b; i < _b; ++i)
#define FOR(i, a, b)  for(int i = a, _b = b; i <= b; ++i)
#define FORD(i, a, b) for(int i = a, _b = b; i >= b; --i)

#define endl "\n"
#define newline	cout << "\n"
#define puts(x)	cout << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef long long llong;

int n;
int a[11];
int answer = 0;

void back (int k, int product) {
	if(k == n) {
		answer += (product%2 == 0);
		return;
	}
	FOR(add, -1, 1) {
		back(k+1, product*((a[k] + add)%2));
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef Home
   freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	REP(i, 0, n) {
		cin >> a[i];
	}
	back(0, 1);
	puts(answer);
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
ll dp[100001],h[100001];
int main(){
    ll n;
    int k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
  for(int i=0;i<100001;i++){
    dp[i]=1000000000000;
  }
    dp[0]=0;//dp[1]=abs(h[0]-h[1]);
    for(int i=0;i<n;i++){
        //dp[i]=min((dp[i-1]+abs(h[i]-h[i-1])),(dp[i-2]+abs(h[i]-h[i-2])));
        for(int j=1;j<=k&&i+j<n;j++){
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
A, B, K = map(int, input().split())
count = 0
if K == 0:
    print('%d %d' % (A, B))
elif K <= A:
    print('%d %d' % (A-K, B))
elif A < K <= B+A:
    print('%d %d' % (0, B-(K-A)))
else:
    print('0 0')


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

int main(void)
{
  long long n, a ,b;
  cin >> n >> a >> b;
  long long sum = n / (a + b) * a;
  long long mod = n % (a + b);
  if(mod >= a)
  {
    sum += a;
  }else
  {
    sum += mod;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
  int n, k;
  cin >> n >> k;
  v memo(n, 0);
  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      memo[a - 1] = 1;
    }
  }
  int cnt = 0;
  rep(i, n) {
    if(memo[i] == 0) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};
const ll mod = 1000000007;
const double PI = acos(-1.0);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n,a,b;
  str s;
  cin>>n>>a>>b;
  cin>>s;
  int cnt=0,cnt2=0;
  rep(i,n){
    if (s[i]=='a'){
      if (cnt<a+b){
        cout << "Yes" << endl;
        cnt++;
      }
      else cout << "No" << endl;
    }
    else if (s[i]=='b'){
      if (cnt<a+b and cnt2<b){
        cout << "Yes" << endl;
        cnt++;cnt2++;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 848
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		ArrayList<String> list = new ArrayList<>();
        for(int i = 0; i < 4; i++) {
          list.add(sc.next());
        }
    
		// 出力
		System.out.println(list.contains("1") 
                           && list.contains("9")
                           && list.contains("7")
                           && list.contains("4") ? "YES" : "NO");
	}
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == 7 && b == 5 && c == 5 || a == 5 && b == 7 && c == 5 || a == 5 && b == 5 && c == 7){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int main(void)
{
	//変数の宣言
	int n,k;
	int ans;
	
	//データの読み込み
	scanf("%d %d",&n,&k);
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	n=(n+1)/2;
	
//	printf("計算部分終了\n");
	
	//出力
	if(n>=k){
		printf("YES");
	}else{
		printf("NO");
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 128