akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#include <deque>
#define MOD 1000000007
#define REP(i,num)for(int i=0;i<(num);++i)
#define ll long long
using namespace std;

struct Edge {
    int x,y,v;
};

int main() {
    ios::sync_with_stdio(false);
    int L,x=2,v=1,longV=0,n;
    cin>>L;
    vector<Edge> edges;
    while (L>=(1<<(x-1))) {
        Edge e1,e2;
        e1.x=x-1;e1.y=x;e1.v=0;
        e2.x=x-1;e2.y=x;e2.v=(1<<(x-2));
        edges.push_back(e1);
        edges.push_back(e2);
        x++;
    }
    longV=(1<<(x-2));
    n=--x;
    if (L!=(1<<(x-1))) {
        L-=(1<<(x-1));
        x=n;
        while (L>0) {
            --x;
            if(L>=(1<<(x-1))){
                L-=(1<<(x-1));
                Edge e;
                e.x=x;e.y=n;e.v=longV;
                edges.push_back(e);
                longV+=(1<<(x-1));
            }
        }
    }
    
    cout<<n<<" "<<edges.size()<<endl;
    for(auto edge: edges){
        cout<<edge.x<<" "<<edge.y<<" "<<edge.v<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
std::mt19937 mt{std::random_device{}()};
int main()
{
    std::vector<int> n(4);
    for (int i = 0; i < 4; i++) { std::cin >> n[i]; }
    std::sort(n.begin(), n.end());
    std::cout << (n[0] == 1 and n[1] == 4 and n[2] == 7 and n[3] == 9 ? "YES" : "NO") << std::endl;
    return 0;
}


Measured memory_bytes: 256
// AOJ 1105
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

typedef vector<int> Seq;

const int NMAX = 2000100;

int solve(int a, int b, int n) {
  bool countable[NMAX];
  REP(i, n + 1) {
    countable[i] = false;
  }
  countable[0] = true;
  
  int unables = 0;
  REP(i, n + 1) {
    if (countable[i]) {
      countable[i + a] = true;
      countable[i + b] = true;
    } else {
      unables++;
    }
  }
  return unables;
}

int main() {
  int a, b, n;
  while (cin >> n >> a >> b and n + a + b) {
    cout << solve(a, b, n) << endl;
  }
}

Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
map<int, vector<int>> g;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> c(n);
    rep(i, n) cin >> c[i];
    sort(ALL(c), greater<int>());
    ll ans = 0;
    deque<int> que;
    que.push_back(0);
    map<int, bool> visited;
    int index = 0;
    vector<int> num(n, 0);

    while (!que.empty())
    {
        int cur = que.front();
        que.pop_front();
        if (visited[cur])
            continue;
        visited[cur] = true;
        num[cur] = c[index];
        index++;
        for (auto x : g[cur])
        {
            que.push_back(x);
        }
    }
    rep(i, n)
    {
        for (auto x : g[i])
        {
            if (x > i)
            {
                ans += min(num[i], num[x]);
            }
        }
    }
    cout << ans << endl;
    rep(i, n)
    {
        cout << num[i] << " ";
    }
    cout << endl;

    return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var N = line[0];
            var K = line[1];
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            Console.WriteLine((N - 1) % (K - 1) == 0 ? (N - 1) / (K - 1) : (N - 1) / (K - 1) + 1);
        }
    }
}

Measured memory_bytes: 19936
/*
 * main.cpp
 *
 *  Created on: 2020/04/10
 *      Author: SkAaO
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

	int flag[101] = {0};
	int sum = 0;

	for(int i = 0; i < N; i++){
		flag[d[i]] = 1;
	}

	for(int i = 0; i < 101; i++){
		sum += flag[i];
	}

	cout << sum << endl;

	return 0;

}




Measured memory_bytes: 256
H, W, K = map(int, input().split())
mod = 10 ** 9 + 7

# 高さiにおいて左からj番目の棒にいる通り数
dp = [[0] * W for i in range(H + 1)]
dp[0][0] = 1


def pattern(w):
    """ 幅wのあみだにおいて、validなものの通り数を返す """
    # 例外処理
    if w < 0:
        return 1

    cnt = 0
    for i in range(2 ** w):
        b = bin(2 ** w + i)[3:]
        if '11' not in b:
            cnt += 1
    return cnt


for i in range(1, H + 1):
    for j in range(W):
        tmp = 0
        # 上からおりてくる
        tmp = (tmp + dp[i - 1][j] * (pattern(j - 1) * pattern(W - j - 2))) % mod

        # 左からおりてくる
        if j > 0:
            tmp = (tmp + dp[i - 1][j - 1] * (pattern(j - 2) * pattern(W - j - 2))) % mod

        # 右からおりてくる
        if j < W - 1:
            tmp = (tmp + dp[i - 1][j + 1] * (pattern(j - 1) * pattern(W - j - 3))) % mod

        dp[i][j] += tmp

print(dp[H][K - 1] % mod)


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

int main(){
    int d, n;
    cin >> d >> n;

    if(d == 0){
        if(n == 100){
            cout << 101 << endl;
        }else{
            cout << n << endl;
        }
    }else if(d == 1){
        int k = 100;
        k *= n;
        if(n == 100){
            cout << 10100 << endl;
        }else{
            cout << k << endl;
        }
    }else{
        int k = 10000;
        k *= n;
        if(n == 100){
            cout << 1010000 << endl;
        }else{
            cout << k << endl;
        }
    }
}

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

using namespace std;
int dx[8]={1,1,1 ,0, 0,-1,-1,-1};
int dy[8]={0,1,-1,1,-1, 1, 0,-1};
int c[55][55];
int w,h;
int res;
void paint(int i,int j,int k){
  if(i<0||j<0)return;
  else if(i>=h||j>=w) return;
  else if(c[i][j]!=1) return;
  c[i][j]=k;
  for(int l=0;l<8;l++) paint(i+dx[l],j+dy[l],k);
  return;
}
void count(int i,int j){
  res++;
  paint(i,j,res);
  return;
}
int main(void){
  int i,j;
  while(scanf("%d %d",&w,&h),w|h){
    res=1;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        scanf("%d",&c[i][j]);
      }
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        if(c[i][j]==1){
          count(i,j);
        }
      }
    }
    printf("%d\n",res-1);
  }
  return 0;
}

Measured memory_bytes: 3204
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans=n/(a+b)*a+min(a,n%(a+b));
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    char a [10];
    scanf("%s",a);
    if(a[1]==a[2]&&(a[1]==a[0]||a[2]==a[3])) 
    printf("Yes");
    else 
    printf("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll n;
    cin >> n;
    vector<ll> D(n);
    rep(i, n) cin >> D[i];
    ll m;
    cin >> m;
    vector<ll> T(m);
    rep(i, m) cin >> T[i];

    sort(D.begin(), D.end());
    sort(T.begin(), T.end());
    ll j = 0; //Dの参照位置
    rep(i, m)
    {
        if (T[i] == D[j])
        {
            j++;
            continue;
        }
        else
        {
            while (1)
            {
                if (j == n)
                {
                    cout << "NO" << endl;
                    return 0;
                }
                if (T[i] == D[j])
                {
                    j++;
                    break;
                }
                else
                {
                    j++;
                }
            }
        }
    }
    cout << "YES" << endl;
}

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

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int s = a * b / 2;
	cout << s << endl;

	return 0;
}

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

int dist[2][100000];
bool visit[2][100000];
vector<int> graph[100000];

void dfs(int x, int n, int i){
   visit[i][x] = true;
   
  // printf("dist:%d\n",dist[x]);
   for(auto g :graph[x]){
      if(visit[i][g]) continue;
      dist[i][g] = dist[i][x] + 1;
      dfs(g,n,i);
   }
}

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

   // 5-7-4-1-2 
   //       L3-6
   // 1-4-2-3

   rep(i,n-1){
      int a,b;
      cin >> a >> b;
      --a; --b;
      graph[a].emplace_back(b);
      graph[b].emplace_back(a);
   }

   //それぞれからの距離を求める
   //フェネックA
   dfs(0,n,0);
   //リセット
   //rep(i,n) visit[i] = false;
   //スヌケ
   dfs(n-1,n,1);

   int A = 0;
   int B = 0;

   rep(i,n){
      if(dist[0][i] <= dist[1][i]) ++A;
      else ++B;
   }
  // rep(i,n) printf("A:%d B:%d\n",distA[i], distB[i]);

   if(A > B) cout << "Fennec" << endl;
   else cout << "Snuke" << endl;
   return 0;
}

Measured memory_bytes: 14464
def c_lining_up(N, A):
    # Nが偶数なら、人数の差の絶対値のリストは[N-1,N-3,...,3,1,1,3,...,N-3,N-1]
    # Nが奇数なら、人数の差の絶対値のリストは[N-1,N-3,...,2,0,2,...,N-3,N-1]
    # でなければならない。このリストとAを共にソートして一致しなければ解は0。

    # 人数の差の絶対値のリストを昇順ソートしたものに等しいリストを得る
    if N % 2 == 0:
        B = [i for i in range(1, N, 2) for _ in range(2)]
    else:
        B = [0] + [i for i in range(2, N, 2) for _ in range(2)]

    ans = 2**(N // 2) % (10**9 + 7) if sorted(A) == B else 0
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_lining_up(N, A))

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

#define LL long long

const int maxN = 505, lim = 61;

int n, T;
LL a[maxN + 1], p[maxN + 1];
char s[maxN + 1];

inline void insert(LL x)
{
	for(int i = lim; i >= 0; i--)
		if(x & (1ll << i))
		{
			if(p[i]) x ^= p[i];
			else
			{ 
				p[i] = x; 
				break; 
			}
		}
}

inline bool check(LL x)
{
	for(int i = lim; i >= 0; i--)
		if(x & (1ll << i)) x ^= p[i];
	return x == 0;
}

int main()
{
	scanf("%d", &T);
	while(T --)
	{
		scanf("%d", &n);
		for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
		
		for(int i = 0; i <= lim; i++) p[i] = 0;
		scanf("%s", s + 1);

		bool flag = true;
		for(int i = n; i >= 1; i--)
			if(s[i] == '0') insert(a[i]);
			else if(!check(a[i])) { flag = false; break; }
		
		puts(flag ? "0" : "1");
	}
	return 0;
}


Measured memory_bytes: 3652
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	// mainA()
	mainB()
}

func mainA() {
	var a, b, c int64

	fmt.Scan(&a, &b, &c)
	var res = solveA(a, b, c)
	fmt.Print(res)

}

func solveA(a int64, b int64, c int64) int64 {

	var res = b / a

	if res > c {
		return c
	}
	return res
}

func mainB() {

	var a, b, k int
	fmt.Scan(&a, &b, &k)
	var res = solveB(a, b, k)
	fmt.Println(res)
}

func solveB(a int, b int, k int) int64 {
	var i = 1
	var res = int64(0)
	var resSlice []int
	var loop = int(math.Min(float64(a), float64(b)))
	for i <= loop {
		if a%i == 0 && b%i == 0 {
			resSlice = append(resSlice, i)
		}
		i++
	}

	// sort.SliceStable(resSlice, func(a, b int) bool { return resSlice[a] < resSlice[b] })
	sort.Sort(sort.Reverse(sort.IntSlice(resSlice)))
	res = int64(resSlice[k-1])
	return res
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    long long int ara[5],i,x,j;
    for(i=0;i<5;i++)
    {
        scanf("%lld",&ara[i]);
    }
    for(i=1;i<5;i++)
    {
        x=ara[i];
        j=i-1;
        while(j>=0&&ara[j]>x)
        {
            ara[j+1]=ara[j];
            j--;
        }
        ara[j+1]=x;
    }
    for(i=4;i>=0;i--)
    {
        printf("%lld",ara[i]);
        if(i>0)
        {
            printf(" ");
        }
        else
            printf("\n");
    }
}



Measured memory_bytes: 2028
import sys
def input():
    return sys.stdin.readline()[:-1]
N,K=map(int, input().split())
s=[None]*N
for i in range(N):
    t,d=map(int,input().split())
    s[i]=(d,t)
s.sort(reverse=True)
l=[0]*N
d=0
for i in s[:K]:
    l[i[1]-1]+=1
    d+=i[0]
c=0
for i in l:
    if i:
        c+=1
a=d+c**2
h=K-1
for i in s[K:]:
    if not l[i[1]-1]:
        while h>=0:
            if l[s[h][1]-1]>1:
                l[i[1]-1]=1
                l[s[h][1]-1]-=1
                c+=1
                d=d+i[0]-s[h][0]
                a=max(a,d+c**2)
                h-=1
                break
            h-=1
        else:
            break
print(a)

Measured memory_bytes: 18012
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;


int main() {
	int n;
	cin >> n;
	vector<ll>a(n);
	rep(i, 0, n) {
		cin >> a[i];
		a[i] -= (i + 1);
	}
	sort(all(a));
	int b = a[n / 2];
	ll sum = 0;
	rep(i, 0, n) {
		sum += abs(a[i] - b);
	}
	cout << sum;



	return 0;
}





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

int main() {  
  int N;
  cin>>N;
  vector<int> vect(N+1);
  vector<int> vecx(N+1);
  vector<int> vecy(N+1);
  for(int i=0;i<N;i++){
    cin>>vect.at(i+1)>>vecx.at(i+1)>>vecy.at(i+1);
  }
  bool can =true;
  for(int i=0;i<N;i++){
    int x=vecx.at(i+1)-vecx.at(i);
    int y=vecy.at(i+1)-vecy.at(i);
    int t=vect.at(i+1)-vect.at(i);
    if(abs(x+y)>t) can=false;
    if((t-abs(x+y))%2==1) can=false;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}
       

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var a = ReadSplitInt();
            if (a[0] < a[1])
            {
                Println(0);
            }
            else
            {
                Println(10);
            }
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define yn(i) print((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// pair 型
template<class S,class T>
std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){
  cout << "(" << p.first << "," << p.second << ")";
  return os;
}

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main(){
  int r; cin >>r;
  int abc=1200,arc=2800;
  if(r<abc){
    print("ABC");
  }else if(r<arc){
    print("ARC");
  }else{
    print("AGC");
  }
  
}





Measured memory_bytes: 3512
#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<long long> A(N);
    long long sum = 0;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        sum += A[i];
        if(i != 0) A[i] += A[i-1];
    }
    long long ret = 1L<<60;
    for(int i = 0; i < N-1; ++i){
        ret = min(ret, abs(A[i] - (sum - A[i])));
    }
    cout << ret << '\n';
    return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const int x) { assert(x > 0); return 31-__builtin_clz(x); } // floor(log2(x))
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); }
inline int cLog2(const int x) { assert(x > 0); return (x == 1) ? 0 : 32-__builtin_clz(x-1); } // ceil(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
void fail() { puts("-1"); exit(0); }
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  int n, m; cin >> n >> m;
  VV a(n, V(m)); cin >> a;
  rep(i, n) rep(j, m) --a[i][j];
  rep(i, n) reverse(all(a[i]));

  int ans = n;

  Vbo deled(m);
  while (true) {
    VV idx(m);
    rep(i, n) idx[a[i].back()].push_back(i);
    int j = -1;
    int cm = 0;
    rep(i, m) if (chmax(cm, sz(idx[i]))) j = i;
    chmin(ans, cm);
    deled[j] = true;
    for (auto i : idx[j]) {
      while (!a[i].empty() && deled[a[i].back()]) a[i].pop_back();
      if (sz(a[i]) == 0) {
        cout << ans << '\n';
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3964
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 

using namespace std; 

const long long mod=1e9+7;

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

    int res=0;
    vector<int> a(n+1),b(n+1),c(n);

    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i],res+=b[i];
    for(int i=1;i<=n-1;i++) cin>>c[i];

    
    for(int i=2;i<=n;i++){
        if(a[i-1]+1==a[i]) res+=c[a[i-1]];
    }

    cout<<res<<endl;

    return 0;
}

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

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint euler(llint x){
	if(x==0)return 0;
	llint ret=x;
	for(llint i=2;i*i<=x;i++){
		if(x%i==0){
			ret-=ret/i;
			while(x%i==0)x/=i;
		}
	}
	if(x>1)ret-=ret/x;
	return ret;
}

llint gcd(llint x,llint y){
	if(x<y)return gcd(y,x);
	llint r;
	while((r=x%y)){
		x=y;
		y=r;
	}
	return y;
}

vector<llint>make_div(llint x){
	vector<llint>div;
	llint t=x;
	for(llint i=2;i*i<=x;i++){
		if(t%i==0){
			div.push_back(i);
			while(t%i==0)t/=i;
		}
	}
	if(t!=1)div.push_back(t);
	return div;
}

void solve(){
	llint a,b;
	cin >> a >> b;
	llint g=gcd(a,b);
	vector<llint>div=make_div(g);
	cout << div.size()+1 << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath> 
using namespace std;
int main(){
//	long long n,m;
//	while(scanf("%d%d",&n,&m)==2){
//		long long sum;
//		sum = (n-2)*(m-2);
//		if(sum< 0) cout<<-sum<<endl;
//		else cout<<sum<<endl; 
//	}
	int n,k;
	while(scanf("%d%d",&n,&k)==2){
		long long sum;
		sum = 0;
			for(int b = k+1; b<=n;b++){
				sum += (n/b)*(b-k); 
				int i=n%b-k+1;
				if(i>=0) sum += i;
			}
		if(k==0) sum -= n;
		cout<<sum<<endl;
	}
}  

Measured memory_bytes: 256
s = input()
a = len(s)
if a%2==0:
  cnt=0
  for i in range (a//2):
    if(s[i]!=s[a-1-i]):
      cnt += 1
if a%2==1:
  cnt=0
  for i in range ((a-1)//2):
    if(s[i]!=s[a-1-i]):
      cnt +=1
print(cnt)

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

s = list(input())
t = list(input())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

l = lcm(n,m)

#x = ['' for _ in range(l)]
step = l // n
step_m = l // m
for i in range(n):
    if (step * i) % step_m == 0:
        if s[i] != t[(step * i) // step_m]:
            #print(step, i, (step * i) // step_m, s[i], t[(step * i) // step_m])
            print(-1)
            exit()

print(l)

Measured memory_bytes: 4628
"""
https://atcoder.jp/contests/abc151/tasks/abc151_d
"""
H, W = map(int, input().split())
S = []
for i in range(H):
    s = input()
    S.append(list(s))

# 隣接のマスをループで表すために必要
di = [-1, 0, 1, 0]
dj = [0, -1, 0, 1]

def is_street(s, t):
    """
    道であること（壁ではないこと）を確認
    """
    return S[s][t] == '.'

def count(maze):
    """
    最大のコストを探索
    """
    r = -1
    for i in range(H):
        for j in range(W):
            r = max(r, maze[i][j])
    return r

def bfs(h, w):
    """
    h: スタート位置（高さ）
    w: スタート位置（横）
    """
    m = []  # スタート地点からの距離が入る
    for i in range(H):
        s = [-1] * W
        m.append(s)
    m[h][w] = 0  # スタート地点は0

    q = [[h, w]]
    while len(q) != 0:
        si, sj = q.pop(0)
        cost = m[si][sj]

        for i in range(4):
            ni = si + di[i]
            nj = sj + dj[i]
            if not (0 <= ni < H and 0 <= nj < W):
                continue
            if not is_street(ni, nj): 
                continue
            if m[ni][nj] != -1:
                continue

            m[ni][nj] = cost + 1
            q.append([ni, nj])

    max_cost = count(m)
    return max_cost

ans = -1
# 壁以外のすべてのマスをスタートにして探索
for i in range(H):
    for j in range(W):
        if not is_street(i, j):
            continue
        c = bfs(i, j)
        ans = max(ans, c)

print(ans)


Measured memory_bytes: 45932
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> st;*/

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

pair<int, int> func(string s) {
	bool x = 1;
	while (x && s.size() > 1) {
		x = 0;
		for (int i = 0; i < (int)s.size() - 1; i++) {
			if (s[i] == '(' && s[i + 1] == ')') {
				string s1 = "";
				for (int j = 0; j < i; j++) {
					s1 += s[j];
				}
				for (int j = i + 2; j < (int)s.size(); j++) {
					s1 += s[j];
				}
				s = s1;
				x = 1;
				break;
			}
		}
	}
	if (s.size() == 0) {
		return { 0, 0 };
	}
	int cnt = 0, cnt1 = 0;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == ')') {
			cnt++;
		}
		else {
			cnt1++;
		}
	}
	return { cnt, cnt1 };
}

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
	return a.first > b.first || (a.first == b.first && a.second > b.second);
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<string> v(n);
	vector<pair<int, int>> a, b;
	int now = 0, del = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		pair<int, int> p = func(v[i]);
		if (p.first == 0) {
			now += p.second;
		}
		else if (p.second == 0) {
			del += p.first;
		}
		else {
			if (p.second >= p.first) {
				a.pb(p);
			}
			else {
				b.pb(p);
			}
		}
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < (int)a.size(); i++) {
		if (now >= a[i].first) {
			now += a[i].second - a[i].first;
		}
		else {
			cout << "No";
			return 0;
		}
	}
	sort(b.begin(), b.end(), cmp);
	for (int i = 0; i < (int)b.size(); i++) {
		if (now >= b[i].first) {
			now += b[i].second - b[i].first;
		}
		else {
			cout << "No";
			return 0;
		}
	}
	if (now - del == 0) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 34504
#include<iostream>
#include<stdlib.h>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin>>K;
    int* a=(int*)calloc(100,sizeof(int));
    int n=0;
    int len=1;
    while(n!=K){
        a[0]++;
        int m=0;
        int kk=-1;
        while(a[m]==10||(a[m]==a[m+1]+2&&m+1<len)){
            a[m+1]++;
            m++;
        }
        for(int i=m-1;i>=0;i--){
            a[i]=a[i+1]-1;
            if(a[i]<0)a[i]=0;
        }
        if(m+1>=len){
            len=m+1;
        }
        n++;
    }
    for(int i=len-1;i>=0;i--){
        cout<<a[i];
    }
    cout<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int x, y;
    cin >> x >> y;
    out(x+y/2);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	long long N;	cin >> N;
	vector<long long> A(N);
	for (long long i = 0; i < N; ++i) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	long long answer = 0;
	long long num = A[0];
	long long n = 1;
	for (long long i = 1; i < N; ++i) {
		if (A[i - 1] == A[i]) {
			n++;
		}
		else {
			answer += n % 2;
			n = 1;
		}
	}
	answer += n % 2;
	cout << answer << endl;
	cin >> N;
}

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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

ll POW(ll a, ll b){
	if(b==1) return a;
	if(b%2==0) return POW(a*a%INF, b/2);
	return a*POW(a, b-1)%INF;
}

int main(){
	ll l[51], p[51];
	l[0] = 1;
	p[0] = 1;
	REP(i, 50) l[i+1] = 2*l[i]+3;
	REP(i, 50) p[i+1] = 2*p[i]+1;
	ll n, x;
	cin >> n >> x;
	ll ans = 0;
	REP(i, n){
		x--;
		if(x < l[n-i-1]) continue;
		else{
			x -= l[n-i-1];
			ans += p[n-i-1];
			if(x==0) break;
			x--;
			ans++;
		}
	}
	if(x > 0) ans++;
	cout << ans << endl;
	return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main (){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans=0;
  int l_count[27]={0};
  int r_count[27]={0};
  for(int i=0;i<N;i++){
    r_count[S[i]-'a']++;
  }
  int k;
  for(int i=0;i<N;i++){
    k=0;
    l_count[S[i]-'a']++;
    r_count[S[i]-'a']--;
    for(int j=97;j<=122;j++){
      if(l_count[j-'a'] >0 && r_count[j-'a']>0) {
        k++;
      }
    }
    ans=max(ans,k);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
int main(void) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
        cout << 2 * a << endl;
    } else if (a > b) {
        cout << 2 * a - 1 << endl;
    } else {
        cout << 2 * b - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>

using namespace std;
int main(){
  long long k, a, b;
  cin >> k >> a >> b;

  long long ans = 1;
  long long mon = 0;

  int iCnt = 0;
  for(long long i=k;i>0;i--){
    if ((b-a)>=2) {
      if (iCnt==1) {
        ans += b;
        iCnt = 0;
        continue;
      } else {
        if(ans>=a){
          if(i>=2){
            iCnt++;
            //mon += ans/a;
            ans -= a;
          } else {
            ans++;
          }
        } else {
          ans++;
        }
      }
    } else {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int LLI;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if( a + b < c + d )
		cout << "Right";
	else if( a + b == c + d )
		cout << "Balanced";
	else cout << "Left";
}

Measured memory_bytes: 3568
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int A = GetInt();
		int B = GetInt();

		Console.WriteLine((A >= 13) ? B : (A >= 6) ? B/2 : 0);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;cin>>x;
    int ans;
    vector<int> av;
    for(int i=1;i*i<=x;i++){
        for(int j=2;j<=20;j++){
            int t=1;
            rep(k,j){
                t*=i;
            }
            if(t<=x){
                av.push_back(t);
            }
        }
    }
    sort(av.rbegin(), av.rend());
    cout<<av[0]<<endl;
}

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

#define MAX 2010

const int MOD = 1e9 + 7;

int dp[MAX][MAX];

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

  int n, m;

  cin >> n >> m;

  vector<int> v(n + 1), w(m + 1);

  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    dp[i][0] = 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> w[i];
    dp[0][i] = 1;
  }

  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
      if (v[i] != w[j])
        dp[i][j] = (MOD + dp[i][j] - dp[i - 1][j - 1]) % MOD;
    }
  }

  cout << dp[n][m] << endl;

  return 0;
}


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

#define rep(i,n) for(int i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;

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

    int k,x;
    cin >> k >> x;
    int sum = k * 500;
    if(sum >= x) cout << "Yes" << endl;
    else cout << "No" << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

void make_minp_table(int MAX, vector<int> &is_prime, vector<int> &minp_table) {
    is_prime.assign(MAX,1);
    minp_table.assign(MAX, -1);
    is_prime[0] = 0; is_prime[1] = 0;
    for(int i = 2; i < MAX; ++i) {
        if(!is_prime[i]) continue;
        minp_table[i] = i;
        for(int j = i*2; j < MAX; j += i) {
            is_prime[j] = 0;
            if(minp_table[j] == -1) minp_table[j] = i;
        }
    }
}


int main()
{
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];

    int G = 0;
    rep(i,n) {
        G = gcd(G, a[i]);
    }

    if(G != 1) {
        cout << "not coprime" << endl;
        return 0;
    }

    vi IP,MP;
    make_minp_table(1000005,IP,MP);

    vi used(1000005);

    rep(i,n) {
        int s = a[i];
        while(s != 1) {
            if(used[ MP[s] ] == 0) used[ MP[s] ] = a[i];
            else if(used[ MP[s] ] != a[i]) {
                cout << "setwise coprime"<< endl;
                exit(0);
            }
            s /= MP[s];
        }
    }
    cout << "pairwise coprime" << endl;
    return 0;
}

Measured memory_bytes: 19116
h,w=map(int,input().split())
grid=[[-1]*w for _ in range(h)]
from collections import deque
que=deque()
for i in range(h):
    s=list(input())
    for j in range(w):
        if s[j]=='#':
            grid[i][j]=0
            que.append((i,j))
dirc=[(1,0),(-1,0),(0,1),(0,-1)]

while que:
    kuro=que.popleft()
    n=grid[kuro[0]][kuro[1]]
    for dx,dy in dirc:
        x=kuro[0]+dx
        y=kuro[1]+dy
        if 0<=x<h and 0<=y<w and grid[x][y]==-1:
            grid[x][y]=n+1
            que.append((x,y))

ans=0
for i in range(h):
    ans=max(ans,max(grid[i]))
print(ans)

Measured memory_bytes: 87388
#include<iostream>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;

typedef pair<int,int> pii;
int dp[101][101][1<<4];

int main(){
    memset(dp, 0x3f, sizeof(dp));
    int n, m, e, s, t, r;
    cin >> n >> m >> e >> s >> t >> r;
    vector<pii> v[n];
    while(m--){
        int a, b;
        cin >> a >> b;
        v[a].push_back({b,-1});
        v[b].push_back({a,-1});
    }
    vector<int> event(n, -1);
    for(int i = 0; i < e; i++){
        int a, b, c;
        cin >> a >> b >> c;
        event[c] = i;
        v[a].push_back({b, i});
        v[b].push_back({a, i});
    }
    int initStat = 0;
    if(event[s] != -1)  initStat += 1<<event[s];
    dp[s][0][initStat] = 0;
    queue<pair<pii,int>> q;
    q.push({{s,0},initStat});
    while(!q.empty()){
        auto p = q.front(); q.pop();
        int pos = p.first.first, dist = p.first.second, stat = p.second;
        // play ocarina
        if(dp[s][0][stat] > dp[pos][dist][stat]+1){
            dp[s][0][stat] = dp[pos][dist][stat]+1;
            q.push({{s,0},stat});
        }
        if(dist == r)   continue;
        // move
        for(pii next : v[pos]){
            int npos = next.first;
            int roadStat = next.second;
            int nstat = stat;
            if(roadStat != -1 && (stat>>roadStat&1) == 0) continue;
            if(event[npos] != -1)    nstat |= 1<<event[npos];
            if(dp[npos][dist+1][nstat] > dp[pos][dist][stat]+1){
                dp[npos][dist+1][nstat] = dp[pos][dist][stat]+1;
                q.push({{npos,dist+1},nstat});
            }
        }
    }
    int ans = 1<<30;
    for(int i = 0; i <= r; i++){
        for(int j = 0; j < 1<<e; j++){
            ans = min(ans, dp[t][i][j]);
        }
    }
    cout << (ans > 1e9 ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 3928
:- use_module(library(clpfd)).

main :-
    read_num(X),
    read_num(Y),
    satisfy(X, Y).

satisfy(X, Y) :-

        X in 1..100,
        Y in 1..100,

        % 鶴をA、亀をBとする。
        0 #=< A, A #=< X,
        0 #=< B, B #=< X,

        X #= A + B,
        Y #= 2 * A + 4 * B,
    
        label([A, B]),
        write('Yes'),
        nl.
    
satisfy(_, _) :-
        write('No'),
        nl.

read_str(S) :-
        read_string(current_input, ' \n', '', _, S).
 
read_num(N) :-
	read_str(S),
	number_string(N, S).


:- main.


Measured memory_bytes: 9144
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

	if (k <= a) cout << k << endl;
	else if (k <= a + b) cout << a << endl;
	else cout << a - (k - a - b) << endl;
}


Measured memory_bytes: 3596
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def solve(X, K):
    N = len(X)

    cumsum = [0 for _ in range(N)]
    for i in range(1, N):
        cumsum[i] = abs(X[i] - X[i - 1]) + cumsum[i - 1]

    idx_zero = bisect.bisect_left(X, 0)

    ret = 1000000005
    for i in range(0, N):
        if X[i] >= 0:
            break
        res = -X[i]
        k = idx_zero - i
        if (k < K) and (idx_zero + K - k - 1 < N):
            res += cumsum[idx_zero + K - k - 1] - cumsum[i]
            ret = min(ret, res)

    return ret


if __name__ == '__main__':
    N, K = map(int, input().split())
    X = list(map(int, input().split()))

    res = 1000000005
    if min(X) >= 0:
        print(X[K - 1])
    elif max(X) <= 0:
        X = X[::-1]
        print(-X[K - 1])
    else:
        res = min(res, solve(X, K))
        X = [-x for x in X]
        res = min(res, solve(X[::-1], K))
        print(res)


Measured memory_bytes: 67668
import Control.Monad
import Control.Applicative
import Data.List
import Data.Ord


getBysplit = map read . words <$> getLine

getPair = do
  [a, b] <- map read . words <$> getLine
  return (a, b)

main :: IO()
main = do
  [n, m] <- getBysplit :: IO [Int]
  pairlst <- replicateM n getPair :: IO [(Int, Int)]
  let lst = sortOn fst pairlst
  print $ solve m 0 lst


solve ::Int -> Int -> [(Int, Int)] -> Int
solve _ _ [] = undefined
solve m acc ((a, b):xs)
            | m - b <= 0 = acc + a*m
            | m - b > 0  = solve (m - b) (acc + a*b) xs


Measured memory_bytes: 75260
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int> v;
int main(){
  //freopen("input.txt", "r", stdin);
  int a;
  for(int i = 0; i < 3; i++){
    scanf("%d", &a);
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  cin >> a;
  while(a--) v[2] = v[2] * 2;
  cout << v[0] + v[1] + v[2] << endl;
  return 0;
}


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

#define T 1;
#define F 0;
int hantei(int);

int main(){

  int n,i,a,b;
  int h;
  int cnt = 0;
  int flag = 0;
  int flag2 = 0;

  scanf("%d",&a);
  
  for(b = 0; b < a; b++){
    scanf("%d",&i);
    flag2 = hantei(i);
      if(flag2 == 1){
	flag++;
      }
    if(flag == 1){
      cnt++;
    }

    flag = 0;
    
  }

  printf("%d\n",cnt);

  return 0;

    }
    


int hantei( int t){
  int r;
  if(t == 2){
    return T;
  }

  if(t < 2 || t % 2 == 0){
    return F;
  }

  r = 3;
  while(r <= sqrt(t)){
    if(t % r == 0){
      return F;
    }
    r = r + 2;
   }

  return T;
}
  



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


int main()
{
  string a,b;
  getline(cin,a);
  getline(cin,b);
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  sort(a.begin(),a.end());
  if(a<b)cout<<"Yes\n";
  else cout<<"No\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>
using namespace std;
int read()
{
	char ch=getchar();
	int num=0,flus=1;
	while(ch<'0'||ch>'9')
	{if(ch=='-') flus=-flus;ch=getchar();}
	while(ch>='0'&&ch<='9')
	{num=num*10+ch-'0';ch=getchar();}
	return num*flus;
}
const int MAXN=2e5+2e2;
int a[MAXN];
int n,p=1,cnt=1,tot=0;
int main(void)
{
	//freopen("working.in","r",stdin);
	//freopen("working.out","w",stdout);
	unsigned long long int k=2,n,ans=0;
	cin>>n;
	while(k<=n)
	{
		k*=5;
		ans+=(n/k);
	}
	if(n&1) puts("0");
	else cout<<ans<<endl;
	return 0;
}
//	freopen("working.in","r",stdin);
//	freopen("working.out","w",stdout);

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
  
using namespace std;
  
int main(void){
  
   int hyo[11][11];
   int n;
   int sum;

   while(1){
	   for(int i=0;i<10;i++){
		   for(int j=0;j<10;j++){
			   hyo[i][j]=0;
		   }
	   }
	   cin>>n;
	   if(n==0) break;
	   for(int i=0;i<n;i++){
		   for(int j=0;j<n;j++){
			   cin>>hyo[i][j];
		   }
	   }
	   for(int i=0;i<n;i++){
		   sum=0;
		   for(int j=0;j<n;j++){
			   sum+=hyo[i][j];
		   }
		   hyo[i][n]=sum;
	   }
	   for(int j=0;j<=n;j++){
		   sum=0;
		   for(int i=0;i<n;i++){
			   sum+=hyo[i][j];
		   }
		   hyo[n][j]=sum;
	   }
	   for(int i=0;i<=n;i++){
		   for(int j=0;j<=n;j++){
			   printf("%5d",hyo[i][j]);
		   }
		   printf("\n");
	   }
   }

  
   return 0;
}

Measured memory_bytes: 1164
from sys import stdin,stdout
# n,e=list(map(int,stdin.readline().split()))
n=int(stdin.readline())
for a in range(-400,400):
    for b in range(-400,400):
        if abs(a**5-b**5)==n:
            print(max(a,b),min(a,b))
            exit(0)

Measured memory_bytes: 8764
n ,x = map(int,input().split())
m = [int(input()) for i in range(n)]
m.sort()
m
k = 0
for m_ in m : 
    x -= m_
    if x < 0 :
        break
    k += 1

while x >= m[0] :
    k += 1
    x -= m[0]
    
print('{}'.format(k))


Measured memory_bytes: 3060
h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]
y =0;x=0
while y < h:
    flag = True
    for x in range(w):
        if a[y][x]=='#':
            flag = False
    
    if flag == True:
        a.pop(y)
        h -= 1
        y = 0
    else:
    	y += 1
x = 0 
while x < w:
    flag = True
    for y in range(h):
        if a[y][x]=='#':
            flag = False
    
    if flag == True:
        for s in range(h):
            a[s].pop(x)
        w -= 1
        x = 0
    else:
        x += 1
            
for i in range(h):
    print(''.join(a[i]))

Measured memory_bytes: 40176
#include<iostream>
using namespace std;
int main(){
    int N, fN = 0, n;
    cin >> N;
    n = N;
    while(n > 0){
        fN += n % 10;
        n /= 10;
    }
    if(N % fN) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3616
#include <iostream>                   
                                      
using namespace std;                  
int main(void){                       
  int a,b,k,min,count = 0,ans;        
  cin >> a >> b >> k;                 
  if(a > b) min = b;                  
  else min = a;                       
  for(int i = min; i >= 1;--i){       
    if(a % i == 0 && b % i == 0){     
      count++;                        
      ans = i;                        
    }                                 
    if(count >= k){                   
      break;                          
    }                                 
  }                                   
  cout << ans << endl;                
  return 0;                           
}                                     
                                      

Measured memory_bytes: 256