akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N; cin >> N;
  vector<double> A(N); cin >> A;
  sort(A.begin(),A.end());
  double sum = A[0];
  for (int i = 1; i < N; ++i) {
    sum = (sum + A[i]) / 2.0;
  }
  printf("%.9f\n", sum);
}


Measured memory_bytes: 3824
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
const int maxn=2e5+5;
typedef long long ll;
vector<ll>vec1,vec2,vec3;
ll n,k;
bool check(ll x){
	ll x1=vec1.size();
	ll x2=vec2.size();
	ll x3=vec3.size();
	ll pos=0;
     if(x==0){
		 pos+=(x1*x3);
		 pos+=(x2*x1+x3*x2);
		 pos+=(x2*(x2-1))/2;
		 return pos>=k;
	 }
	 else if(x>0){
		 pos+=(x1*x3);
		 pos+=(x2*x1+x3*x2);
		 pos+=(x2*(x2-1))/2;
		 for(int i=0;i<x1;i++){
			 ll tmp;
			 if(x%vec1[i]){
                 tmp=x/vec1[i];
			 }
			 else{
			     tmp=x/vec1[i];
			 }
             if(lower_bound(vec1.begin()+i+1,vec1.end(),tmp)==vec1.end()){
                 pos+=0;
			 }
			 else{
				 pos+=vec1.end()-lower_bound(vec1.begin()+i+1,vec1.end(),tmp);
			 }

		 }
		  for(int i=0;i<x3;i++){
			 ll tmp;
			 if(x%vec3[i]){
                 tmp=x/vec3[i];
			 }
			 else{
			     tmp=x/vec3[i];
			 }
			 if(upper_bound(vec3.begin()+i+1,vec3.end(),tmp)==vec3.end()){
                 pos+=vec3.end()-(vec3.begin()+i+1);
             }
             else{
                 pos+=upper_bound(vec3.begin()+i+1,vec3.end(),tmp)-1-vec3.begin()-i;
             }
			
		 }

		 return pos>=k;
	 }
	 else{
		 for(int i=x1-1;i>=0;i--){
			  ll tmp;
			 if(x%vec1[i]){
                 tmp=x/vec1[i]+1;
			 }
			 else{
			     tmp=x/vec1[i];
			 }
			if(lower_bound(vec3.begin(),vec3.end(),tmp)==vec3.end()){
                 pos+=0;
			 }
			 else{
				 pos+=vec3.end()-lower_bound(vec3.begin(),vec3.end(),tmp);
			 }
		 }
		 return pos>=k;
	 }
}
int main(){
	
	cin>>n>>k;
	ll x;
	for(int i=1;i<=n;i++){
        scanf("%lld",&x);
		if(x<0){
          vec1.push_back(x);
		}
		else if(x==0){
          vec2.push_back(x);
		} 
		else{
			vec3.push_back(x);
		}
	}
	sort(vec1.begin(),vec1.end());
	sort(vec2.begin(),vec2.end());
	sort(vec3.begin(),vec3.end());
	ll l=-1e18,r=1e18;
	ll mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid))r=mid-1;
		else{
            l=mid+1;
		}
		
	}
    cout<<r+1<<endl;

	return 0;
}


Measured memory_bytes: 2548
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  var B=input[1].split(' ').map(e=>{
    return e-0;
  });
  B.unshift(Infinity);
  B.push(Infinity)
  var ans=0;
  for(var i=1;i<=N;i++){
    ans+=Math.min(B[i],B[i-1]);
  }
  console.log(ans);
 
}




//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29604
import java.util.Scanner;

public class Main { 
	public static void main(String[] args){
		String str;
                int[] arr = new int[3];
                int i, j, temp;
 
                // 3????????°??????????????????
                Scanner scan = new Scanner(System.in);
                str = scan.next();
                arr[0] = Integer.parseInt(str);
                str = scan.next();
                arr[1] = Integer.parseInt(str);
                str = scan.next();
                arr[2] = Integer.parseInt(str);

                // selection sort
                for(i=1; i<3; i++){
                        temp = arr[i];
                        if(arr[i-1] > temp){
                                j = i;
                                do{
                                        arr[j] = arr[j-1];
                                        --j;
                                }while(j > 0 && arr[j-1] > temp);
                                arr[j] = temp;
                        }
                }

                System.out.println(arr[0] + " " + arr[1] + " " + arr[2]);
	}
}

Measured memory_bytes: 17268
#include<bits/stdc++.h>
using namespace std;
int n,x,y,ans;
int sg(int x,int y){
	if (x%y==0)return x/y;
	int z=x/y;x=z*y+(x+y)%(z+1);
	if (x%y==0)return x/y;
	return sg(x-z-1,y);
}
int main(){
	scanf("%d",&n);
	while (n--){
		scanf("%d%d",&x,&y);
		ans^=sg(x,y);
	}
	if (ans)puts("Takahashi");
	else puts("Aoki");
}

Measured memory_bytes: 256
#include <iostream>

char a[4] = {'A', 'C', 'G', 'T' };

int acgt (char b) {
    for(int i = 0; i < 4; ++i) {
        if(b == a[i]) return 1;
    }
    return 0;
}

int main () {
    std::string s;
    std::cin >> s;
    int c = 0, max = 0;
    for (int i = 0; i < s.length(); ++i) {
        if(acgt(s[i]) == 0) {
            if(max < c) max = c;
            c = 0;
        }
        else ++c;
    }
    if(max < c) std::cout << c << std::endl;
    else std::cout << max << std::endl;
}


Measured memory_bytes: 256
///-----Bismillahir Rahmanir Rahim-----///

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

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
///vector
typedef vector<int> vi;
typedef vector<ll> vl;
///pair
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int n,k,ans=0;
        cin>>n>>k;
        int p[n+5];
        for(int i=0;i<n;i++)
        {
            cin>>p[i];
        }
        sort(p,p+n);
        for(int i=0;i<k;i++)
        {
            ans+=p[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3580
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        String w;
        w = sc.next(); //入力された値
        int[] cntNum = new int[26]; //アルファベットの個数だけ配列を用意
        /* cntNumの中身を全部0に初期化 */
        for(int i:cntNum){
            i = 0; 
        }
        for(int j = 0; j < w.length(); j++){
            cntNum[w.charAt(j) - 'a']++;
        }
        for(int k:cntNum){
            if(k % 2 != 0){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
        
    }   
}


Measured memory_bytes: 22996
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H = I()
    A = [0]
    tmp = LI()
    for i in tmp:
        A.append(i)

    for i in range(1, H+1):
        ans = ''
        ans += 'node ' + str(i) + ': '
        ans += 'key = ' + str(A[i]) + ', '
        if 1 <= i//2 < H+1:
            ans += 'parent key = ' + str(A[i//2]) + ', '
        if 1 <= 2*i < H+1:
            ans += 'left key = ' + str(A[2*i]) + ', '
        if 1 <= 2*i+1 < H+1:
            ans += 'right key = ' + str(A[2*i+1]) + ', '
        print(ans)

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 5636
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( char *X, char *Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

// Print the lcs 
cout << lcs; 
} 

/* Driver program to test above function */
int main() 
{ 
	char X[3005]; 
	char Y[3005];
       cin >> X >> Y;	
	int m = strlen(X); 
	int n = strlen(Y); 
	lcs(X, Y, m, n); 
	return 0; 
} 


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	ll k,a,b; cin>>k>>a>>b;
	ll ans=1;
	ll res=(k-a+1)/2;
	if(b-a<2) ans=k+1;
	else{
		ans=a;
		ans+=res*(b-a);
		if((k-a-1)%2) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
class abc_164:
    
    def __init__(self):
        pass
    
    def A(self):
        sw=list(map(int,input().split()))
        print("unsafe") if sw[1]>=sw[0] else print("safe")
    
    def B(self):
        abcd=list(map(int,input().split()))
        while(abcd[0]!=0 and abcd[2]!=0):
            abcd[2]=abcd[2]-abcd[1]
            abcd[0]=abcd[0]-abcd[3]
            
            if abcd[2]<=0:
                print("Yes")
                break
            elif abcd[0]<=0:
                print("No")
                break
            else:
                pass
            
    def C(self):
        pass
    
    def D(self):
        pass
    
    def E(self):
        pass
    
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_164()
    obj.B()

Measured memory_bytes: 61868
N, M = map(int, input().split())

citys = {i: 0 for i in range(1, N+1)}

for _ in range(M):
    a, b = map(int, input().split())
    citys[a] += 1
    citys[b] += 1
    
for num in citys.values():
    print(num)

Measured memory_bytes: 9180
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		return true;
	}
	
	static void solve(){
		int sum = 1;
		for(int i = 2; i*i <= n; i++){
			if(n%i == 0){
				if(i*i == n){
					sum += i;
				}else{
					sum += i + n/i;
				}
			}
		}
		if(n == 1){
			System.out.println("deficient number");
		}else if(sum == n){
			System.out.println("perfect number");
		}else if(sum > n){
			System.out.println("abundant number");
		}else{
			System.out.println("deficient number");
		}
	}

}

Measured memory_bytes: 12000
eval'N,M,A,*B='+`dd`.split*?,
s=[x=0]*9**6
B.map{|b|c=b;A>b&&b+=M;x+=t=b-A
[0,M].map{|m|s[m-~A]+=1;s[m+b]-=t;s[m-~b]+=t-1}
A=c}
2.times{c=0;s=s.map{|s|c+=s}}
p x-s.max

Measured memory_bytes: 48788
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<ll> lucas({2, 1});
  if(n >= 2)
    for(int i = 2; i < n + 1; i++)
      lucas.push_back(lucas.at(i - 1) + lucas.at(i - 2));
  cout << lucas.at(n) << endl;
}

Measured memory_bytes: 256
from collections import deque


H, W = map(int, input().split())
Ch, Cw = map(lambda x: int(x) - 1, input().split())
Dh, Dw = map(lambda x: int(x) - 1, input().split())
maze = [input() for _ in range(H)]

INF = 10 ** 12
path = [[INF] * W for _ in range(H)]

q = deque()
path[Ch][Cw] = 0
q.append((Ch, Cw, 0))

walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = []
for i in range(-2, 3):
    for j in range(-2, 3):
        if (i, j) != (0, 0) and (i, j) not in walk:
            warp.append((i, j))

while q:
    x, y, s = q.popleft()
    for dx, dy in walk:
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s:
            path[nx][ny] = s
            q.appendleft((nx, ny, s))
    for dx, dy in warp:
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and path[nx][ny] > s + 1:
            path[nx][ny] = s + 1
            q.append((nx, ny, s + 1))
    
ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
print(ans)


Measured memory_bytes: 94228
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n,k,a[200005],now=1,s,l,ct=-1,cm;
    bool v[200005]={0},ok=false;
    vcl cy,cc;
    cin >> n >> k;
    rep(i,1,n){
        cin >> a[i];
    }
    cy.pb(1);
    v[1]=true;
    while(1){
        now=a[now];
        if(!v[now]){
            cy.pb(now); 
            v[now]=true;
        } else {
            l=now;
            break;
        }
    }
    for(auto to: cy){
        ct++;
        if(to==l&&!ok){
            ok=true;
            cm=ct;
        }
        if(ok){
            cc.pb(to);
        }
    }
    if(k<cm){
    	cout << cy[k] << endl;
    	return 0;
    }
    s=cc.size();
    k=(k-cm)%s;
    cout << cc[k] << endl;
    return 0;
}

Measured memory_bytes: 9400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  if(s == "RRR")
    cout << 3;
  else if(s == "SSS")
    cout << 0;
  else if(s == "RRS")
    cout << 2;
  else if(s == "SRR")
    cout << 2;
  else
    cout << 1;

}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
sys.setrecursionlimit(5000000)

f = 0
def ts(E):
    L = []
    n = len(E)
    done = [0] * n
    checking = [0] * n
    def visit(j):
        global f
        checking[j] = 1
        if done[j] == 0:
            done[j] = 1
            for k in E[j]:
                if f: return 1
                if checking[k]:
                    f = 1
                    return 1
                visit(k)
                D[j] = max(D[j], D[k] + 1)
            L.append(j)
        checking[j] = 0
        return f
    for i in range(n):
        if visit(i):
            return []
    return L[::-1]

def ca(i, j):
    return max(i, j) * (max(i, j)-1) // 2 + min(i, j)

N = int(input())
M = N * (N-1) // 2
X = [[] for i in range(M)]
for i in range(N):
    A = [int(a)-1 for a in input().split()]
    for j in range(N-2):
        X[ca(i, A[j])].append(ca(i, A[j+1]))
D = [0] * M
L = ts(X)
print(max(D) + 1 if L else -1)

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

int main(){
   int n; cin>>n;
   map<string,int> mp;
   rep(i,n){
      string s; cin>>s;
      sort(s.begin(),s.end());
      mp[s]++;
   }
   ll ans=0;
   for(auto& p:mp){
      int s=p.second;
      //ｎから二個選ぶ
      ans+=(ll)s*(s-1)/2;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;

int r; 
int main(){
	scanf("%d",&r);
	printf("%d\n",r*r);
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

public class Main {

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

		while (sc.hasNext()) {
			final int p = sc.nextInt();
			final int q = sc.nextInt();

			int[] mod = new int[q];
			Arrays.fill(mod, Integer.MAX_VALUE);

			int div = p;
			int count = 0;
			int start = 0;
			int end = 0;
			boolean ok = false;
			
			while (true) {
				if(div % q == 0){
					ok = true;
					end = count;
					break;
				}else if (mod[div % q] != Integer.MAX_VALUE) {
					end = count;
					start = mod[div % q];
					break;
				} else {
					mod[div % q] = count + 1;
					div = (div % q) * 10;
					count++;
				}
			}

			div = (p % q) * 10;
			for (int i = 1; i <= end; i++) {
				System.out.print((int) (div / q));
				div = (div % q) * 10;
			}
			System.out.println();
			if(!ok){
				for (int i = 1; i <= end; i++) {
					System.out.print(i < start ? " " : "^");
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 87612
# include <bits/stdc++.h>
using namespace std;
int main(){
	long long n , res = 1e15;
	cin >> n;
	for(long long i = 1; i * i <= n; i ++)
		if(n % i == 0)
			res = min(res , i + n / i - 2);
	cout << res << "\n";
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		sum+=a;
	}
	cout<<sum-n<<endl;
}


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

int gcd(int x,int y);

using namespace std;

int main(void){
	int N,X;
  	cin >> N >> X;
  	int d[N],x[N];
  	int i;
  	for(i=0;i<N;i++){
    	cin >> x[i];
      	d[i] = abs(x[i] - X);
    }
  	int tmp=d[0],p;
  	for(i=1;i<N;i++){
    	p = gcd(tmp,d[i]);
      	tmp = p;
    }
  	cout << tmp << endl;
}

int gcd(int x,int y){
  	int a,b;
  	if(x>=y){
    	a=x,b=y;
    } else {
    	a=y,b=x;
    }
	int n=a,tmp;
  	while(n!=0){
    	n = a%b;
      	tmp = b;
      	a = b;
      	b = n;
    }
  	return tmp;
}

Measured memory_bytes: 1024
// Problem Code: abc176_e

#include <bits/stdc++.h>

using namespace std;

int D(int H, int W, int M, vector<int>& h, vector<int>& w) {
	int max_bombs, r, c;
	set<int> seen;
	vector<int> row(H), col(W);
	
	for (int i = 0; i < M; i++) {
		row[h[i]]++;
		col[w[i]]++;
	}
	
	r = distance(row.begin(), max_element(row.begin(), row.end()));
	max_bombs = row[r];
	for (int i = 0; i < M; i++)
		if (h[i] == r)
			seen.insert(w[i]);
	
	for (c = 0; c < W; c++) {
		int bombs = row[r] + col[c] - seen.count(c);
		max_bombs = max(bombs, max_bombs);
	}
	
	seen.clear();
	c = distance(col.begin(), max_element(col.begin(), col.end()));
	max_bombs = max(max_bombs, col[c]);
	for (int i = 0; i < M; i++)
		if (w[i] == c)
			seen.insert(h[i]);
	
	for (r = 0; r < H; r++) {
		int bombs = row[r] + col[c] - seen.count(r);
		max_bombs = max(bombs, max_bombs);
	}
	
	return max_bombs;
}

int main() {
	int H, W, M;
	cin >> H >> W >> M;
	vector<int> h(M), w(M);
	for (int i = 0; i < M; i++) {
		cin >> h[i] >> w[i];
		--h[i], --w[i];
	}
	cout << D(H, W, M, h, w);
	return 0;
}

Measured memory_bytes: 21916
import sys

read = sys.stdin.read
readline = sys.stdin.readline
INF = 1 << 60


def main():
    H, W, K = map(int, readline().split())
    S = read().split()

    ans = INF

    for bit in range(1 << (H - 1)):
        idx = [0] * H
        for i in range(H - 1):
            if bit & (1 << i):
                idx[i + 1] = idx[i] + 1
            else:
                idx[i + 1] = idx[i]

        res = idx[-1]
        n = idx[-1] + 1
        A = [0] * n

        for j in range(W):
            B = [0] * n
            ok = True
            for i in range(H):
                if S[i][j] == '1':
                    B[idx[i]] += 1
                    if B[idx[i]] > K:
                        ok = False
                        break

            if not ok:
                res = INF
                break

            divided = False
            for k in range(n):
                A[k] += B[k]
                if A[k] > K:
                    divided = True
                    break

            if not ok:
                res = INF
                break
            if divided:
                A = B
                res += 1

        if ans > res:
            ans = res

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int v[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>v[i];
	}
	sort(v,v+n);
	double ans=(double)v[0];
	for (int i = 1; i < n; ++i)
	{
		ans=(double)(ans+v[i])/2.0;
	}
	printf("%.6f\n", ans);
	return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
cnt1,cnt2,cnt4=0,0,0
for i in A:
  if i%2!=0:
    cnt1+=1
  elif i%2==0 and i%4!=0:
    cnt2+=1
  else:
    cnt4+=1
if cnt2==0:
  if cnt4+1>=cnt1:
    print('Yes')
    exit()    
else:
  if cnt4>=cnt1:
    print('Yes')
    exit() 
print('No')

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

int main(){
    int N;
    long long a[100100];
    cin >> N;
    for(int i = 0; i < N; ++i) cin >> a[i];
    int res = 0;
    for(int i = 0; i < N; ++i){
        if(a[i] % 4 == 0) res +=2;
        else if(a[i] % 4 == 2) res += 1; 
    }
    if(N % 2 == 1) res++;
    if(res >= N) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  int N;
  string S, T;
  cin >> N;
  cin >> S >> T;
  
  string mj = "";
  
  for(int i = 0; i < N; i++) {
    mj += S.at(i);
    mj += T.at(i);
  }
  
  cout << mj << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int tot,n,m,op[500010],e[500010],hd[500010],v[500010],du[500010][2],cnt,nt[500010];
char s[500010];
queue<int>q;
void build(int x,int y){
	tot++;
	e[tot]=y;
	nt[tot]=hd[x];hd[x]=tot;
}
int main(){
	int i,j,x,y;
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(i=1;i<=n;i++)op[i]=(s[i]=='A'?0:1);
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		build(x,y);build(y,x);
		du[x][op[y]]++;du[y][op[x]]++;
	}
	for(i=1;i<=n;i++)if(!du[i][0]||!du[i][1]){
		cnt++;v[i]=1;q.push(i);
	}
	while(!q.empty()){
		x=q.front();q.pop();
		for(i=hd[x];i;i=nt[i])if(!v[e[i]]){
			du[e[i]][op[x]]--;
			if(!du[e[i]][op[x]]){
				cnt++;
				v[e[i]]=1;q.push(e[i]);
			}
		}
	}
	if(cnt==n)puts("No");
	 else puts("Yes");
}

Measured memory_bytes: 11264
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}

int main()
{
	fast();
	ll n,i,x;
	cin>>n;
	while(n--)
	{
		cin>>x;
		if(x%2==0 and x%3!=0 and x%5!=0)
		{
			cout<<"DENIED";
			exit(0);
		}
	}
	cout<<"APPROVED";
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    int st = s.find('A');
    int en = s.rfind('Z');

    cout << en - st + 1 << endl;
    return 0;
}


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

int main() {
	int q, x;
	char com[20];
	list<int> v;
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &x);
			v.push_front(x);
		}
		else if (com[6] == 'L')
			v.pop_back();
		else if (com[6] == 'F')
			v.pop_front();
		else if (com[0] == 'd') {
			scanf("%d", &x);
			for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
				if (*it == x) {
					v.erase(it);
					break;
				}
			}
		}
	}
	int i = 0;
	for (list<int>::iterator it = v.begin(); it != v.end(); it++) {
		if (i++)
			printf(" ");
		printf("%d", *it);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 34472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,a,b;
int main(){
	cin >> n >> a >> b;
	if((a-b)%2)puts("Borys");
	else puts("Alice");
	return 0;
}

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

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  map<ll, ll> m;
  for(ll i = 1; i<n; i++) {
    cin >> a[i];
    m[a[i]-1]++;
  }
  rep(i, n) {
    cout << m[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 17252
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int s,i,j,p,t=0;
    scanf("%d",&s);
    char n[s],a[]="ABC";
    scanf("%s",n);
    //gets(n);
    i=0;
    while(n[i]!='\0')
    {
        j=0;p=i;
        if(n[p]==a[j]&&n[p])
        {
            while(a[j]==n[p]&&a[j]&&n[p])
            {
                j++;p++;
            }
            if(a[j]=='\0') t++;

        }
        i++;
    }
    printf("%d\n",t);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] v = new int[n];
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        int result = 0;
        for (int i = 0; i < n; i++) {
            int dif = v[i] - c[i];
            if (dif >= 0) {
                result += dif;
            }
        }
        System.out.println(result);
        sc.close();
    }
}

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

typedef long long ll;
const int mod = 1e9 + 7;
ll N;

int main() {
    cin >> N;
    vector<ll> a(N);

    rep(i, N) cin >> a[i];

    ll sum = 0;
    rep(i, 60) {
        ll x = 0;
        rep(k, N) {
            if (a[k] >> i & 1) {
                x++;
            }
        }

        ll m = x * (N - x) % mod;
        // printf("m: %d i: %d\n", m, i);
        // m = m << i;
        rep(j, i) m = m * 2 % mod;
        // cout << m << endl;
        sum += m % mod;
        sum %= mod;
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool ok = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) ok = true;
  }
  if (ok)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int masu[100001];
int main(){
    ll w,a,b;
    cin>>w>>a>>b;
    if(a+w<=b){
        cout<<b-(a+w)<<endl;return 0;
    }else if(b+w<=a){
        cout<<a-(b+w)<<endl;return 0;
    }else{
        cout<<0<<endl;
    }
    return 0;
}

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

int main() {
    int i, N = 0;
    cin >> N;
    vector<int> buf_order(N), utility(N), add_util(N-1);

    rep(i, N) {
        cin >> buf_order.at(i);
    }

    rep(i, N) {
        cin >> utility.at(i);
    }

    rep(i, N-1) {
        cin >> add_util.at(i);
    }


    int ans = 0;
    int order = 0;
    for (int i = 0; i < N; i++) {
        /* code */
        order = buf_order.at(i);
        ans += utility.at(order-1);
        if (i==N-1) {
            /* code */
            break;
        }
        
        if (order+1 == buf_order.at(i+1))
        {
            /* code */
            ans += add_util.at(order-1);
        }
    }

    printf("%d", ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] アーグス) {
        Scanner スキャナー=new Scanner(System.in);
        int えー=スキャナー.nextInt();
        int びー=スキャナー.nextInt();
        System.out.println(まっくす(まっくす(えー+びー,えー-びー),えー*びー));
    }
    public static int まっくす(int えー, int びー){
        return Math.max(えー,びー);
    }
}


Measured memory_bytes: 21972
def main():
  N,W=map(int,input().split())
  Wlist=[]
  Vlist=[]
  for i in range(N):
    w,v=map(int,input().split())
    Wlist+=[w]
    Vlist+=[v]
  Vmax=max(Vlist)
  V=Vmax*N
  dp=[[float('inf') for p in range(V+1)] for i in range(N)]
  for i in range(V+1):
    if i<=Vlist[0]:
      dp[0][i]=Wlist[0]
  dp[0][0]=0
  for i in range(1,N):
    vi=Vlist[i]
    wi=Wlist[i]
    for j in range(V+1):
      if j-vi>=0:
        dp[i][j]=min(dp[i-1][j-vi]+wi,dp[i-1][j])
      else:
        dp[i][j]=min(dp[i-1][j],dp[i][j])
  dpn=dp[N-1]
  ans=0
  for i in range(V+1):
    if dpn[i]<=W:
      ans=i
  print(ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 310256
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
    
    size_t N;
    cin >> N;
    unordered_map<size_t, size_t> map;
    for (size_t i = 1; i < N; ++i) {
        size_t x;
        cin >> x;
        ++map[x - 1];
    }
    for (size_t i = 0; i < N; ++i) {
        cout << map[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 11472
//******************************************************************************* //
'use strict'; process.stdin.resume();                                             //
process.stdin.setEncoding('utf-8');                                               //
let inputString = ''; let currentLine = 0;                                        //
process.stdin.on('data', inputStdin => { inputString += inputStdin });            //
process.stdin.on('end', () => {inputString = inputString.split('\n'); main(); }); //
function readline() { return inputString[currentLine++]; }                        //
//******************************************************************************* //


function main() {

    //var input = readline()
    var T = Number(readline());
    
    var s = readline();
    var m = s.replace(/(.)\1+/g, "$1")
    console.log(m.length);
    
}

Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,i,j,k,l;
  string x;
  cin>>m;
  vector<vector<int>> v(m,vector<int>(26));
  for(i=0;i<m;i++){
    cin>>x;
    for(j=0;j<(int)x.length();j++) v.at(i).at(x.at(j)-'a')++;
  }
  for(j=0;j<26;j++){
    l=50;
    for(i=0;i<m;i++) l=min(l,v.at(i).at(j));
    for(k=0;k<l;k++) cout<<(char)('a'+j);
  }
  cout<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <map>
#include <set>
#include <algorithm>
using namespace  std;


int f[1000010];


int main()
{
    int n;scanf("%d",&n);
    for (int i=0;i<n;++i)
    {
        int t;scanf("%d",&t);
        f[t]++;
    }
    int ans=0;
    for (int i=1;i<=1000000;++i){
        if (f[i]==1) ans++;
        if (f[i]==0) continue;
        for (int k=2;k*i<=1000000;++k)
            f[k*i]=0;
    }
    printf("%d\n",ans);
}

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

int main(){
    string S; cin >> S;
    for (int i=0; i<3; i++){
        if (S[i]=='1'){
            S[i]='9';
        }else{
            S[i]='1';
        } 
    }
    cout << S;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,count;
	while(cin >> n){
		if(n==0) return 0;
		count=0;
		while( n != 1){
			if(n%2 == 0){
				n = n/2;
				count++;
			}
			else{
				n = n*3+1;
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        for(int i = 1;;i++){
            int x =scan.nextInt();
            if(x == 0){
                break;
            }else{
                System.out.println("Case "+ i +": "+ x);
            }
        }
        scan.close();
    }
}


Measured memory_bytes: 41368
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N, H, W;
    cin >> N >> H >> W;

    ll count = 0;

    FOR(i, 0, N){
        ll a, b;
        cin >> a >> b;

        if(a>=H && b>=W){
            count++;
        }
    }

    p(count);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n; cin >> n;
    V<ll> A(n);
    loop (n, i) cin >> A[i];
    sort(A.begin(), A.end());
    string YES = "Yes", NO = "No";

    if (n % 3) {
        if (A[n - 1] == 0) {
            cout << YES << endl;
        } else {
            cout << NO << endl;
        }
        return 0;
    }

    if ((A[0] == A[n / 3 - 1] && A[n / 3] == A[n * 2 / 3 - 1] && A[n * 2 / 3] == A[n - 1]) &&
        (A[0] ^ A[n / 3] ^ A[n * 2 / 3]) == 0) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }


    return 0;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = ip(br.readLine());
        int[] list = new int[n];
        for (int i = 0; i < n; i++) {
            list[i] = ip(br.readLine());
        }
        shellSort(list, n);
        for(int i:list){
            System.out.println(i);
        }

    }

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

    static void shellSort(int[] a, int n) {
        int count = 0;
        int h = 0;
        int m=0;
        while (h <= n / 9) {
            h = 3 * h + 1;
            m++;
        }
        System.out.println(m);
        String[] g = new String[m];
        int c = 0;
        for (; h > 0; h /= 3) {
            g[c++] = String.valueOf(h);
            count += insertionSort(a, n, h);
        }
        System.out.println(String.join(" ", g));
        System.out.println(count);

    }

    private static void print(int[] list) {
        int n = list.length;
        String[] str = new String[n];
        for (int i = 0; i < n; i++) {
            str[i] = String.valueOf(list[i]);
        }
        System.out.println(String.join(" ", str));
    }

    static void swap(int[] list, int a, int b) {
        int temp = list[a];
        list[a] = list[b];
        list[b] = temp;
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long A, long long B){
    cout<<max(0LL,A-2*B)<<endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
#define MAX 100
 
void MatrixChain(int, int*);
 
int main(void){
  int n, i, x;
  int P[MAX];
 
  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d%d", &P[i+1], &x);
 
  P[i+1] = x;
 
  MatrixChain(n, P);
 
  return 0;
}
 
void MatrixChain(int n, int *P){
  int i, j, k, x, q;
  int M[MAX][MAX];
 
  for(i=1; i<=n; i++) M[i][i] = 0;
 
  for(i=2; i<=n; i++){
    for(j=1; j<=n-i+1; j++){
 
      x = i+j-1;
      M[j][x] = 1000000;
      for(k=j; k<=x-1; k++){
 
        q = M[j][k]+M[k+1][x]+P[j]*P[k+1]*P[x+1];
        if(q < M[j][x]) M[j][x] = q;
 
      }
    }
  }
 
  printf("%d\n", M[1][n]);
 
  return;
}

Measured memory_bytes: 632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

const ll INF = 1000000000000000000LL;

using namespace std;

ll N, A, B, C, D;
map<ll, ll> memo;

ll rec(ll n) {
	if (n <= 1){
		return memo[n] = n * D;
	}
	if (memo[n] != 0) {
		return memo[n];
	}

	ll ret = INF;
	if (n <= INF / D){
		ret = n * D;
	}
	ll ref[3] = {2, 3, 5};
	ll add[3] = {A, B, C};
	for (int ii = 0; ii < 3; ++ii){
		ll q = n / ref[ii];
		ll r = n % ref[ii];
		if (r == 0){
			ret = min(ret, rec(q) + add[ii]);
		} else {
			ret = min(ret, rec(q) + add[ii] + r * D);
			ret = min(ret, rec(q+1) + add[ii] + (ref[ii] - r) * D);
		}
	}

	return memo[n] = ret;
}

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

	for (int ii = 0; ii < T; ++ii){
		cin >> N >> A >> B >> C >> D;

		memo.clear();
		ll ans = rec(N);
		cout << ans << "\n";
	}

	return 0;
}


Measured memory_bytes: 4468
def make_divisors(n: int) -> list:
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    divisors = sorted(divisors)
    return divisors


n = int(input())
div = make_divisors(n)
ans = 10 ** 18
for i in div:
    ans = min(ans, i + n // i - 2)
print(ans)

Measured memory_bytes: 3280
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    long n=sc.nextLong();//初期値
    long k=sc.nextLong();
    long count=0;
    long m=n;

    if (n>=k) {
      count=n/k;
    }


    long ans1=Math.abs(n-(k*count));
    long ans2=Math.abs(n-(k*(count+1)));

    long min=Math.min(ans1,ans2);

    System.out.println(min);
  }
}


Measured memory_bytes: 22740
#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 MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
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;
typedef vector<str> vs;
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;};

int main() {
    int a,b,c;
    cin >> a>>b>>c;
    cout << min(b/a, c) << endl;

}

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

int main() {
    int n, m, a=1;
    cin>>n>>m;
    for(int i=1;i*i<=m;i++){
        if(m%i==0){
            if(m/i>=n){
                a=max(a, i);
            }
            if(i>=n){
                a=max(a, m/i);
            }
            
        }
    }
    cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = []
B = []
for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())
flag = 0
for i in range(N-M+1):
    for k in range(N-M+1):
        p = 1
        for j in range(i,i+M):
            a = A[j][k:k+M]
            b = B[j-i]
            if a != b:
                p = 0
                break
        if p == 1:
            flag = 1
        

if flag == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <deque>

using namespace std;

int main(int argc, char const *argv[])
{
	string s;

	cin >> s;

	if (s[3]=='7')
	{
		s[3]='8';
	}

	cout << s << "\n";

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define vec vector
typedef int64_t intl;
#define fi first
#define se second
#define pushb push_back
#define popb pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
vec<int> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};



int main(){
  intl A,B,C,K;
  cin >> A>>B>>C>>K;
  if (A >= K){cout <<K;}
  else if (A + B >= K){ cout << A;}
  else { cout << A - ( K - (A+B) );}
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int p[65005];
  int j[65005];
  
  while(1){
    cin>>n;
    if(n==0)break;
    
    long long size=0;
    for(int i=0;i<n;i++){
      cin>>p[i];
      size+=p[i];
    }
    for(int i=0;i<n-1;i++){
      cin>>j[i];
      size+=j[i];
    }
    
    sort(j,j+n-1);
    
    long long ans=size;
    for(int i=1;i<n;i++){
      size-=j[i-1];
      ans=max(ans,size*(i+1));

    }
    
    cout<<ans<<"\n";
  }
  return 0;
}
  



Measured memory_bytes: 3568
X, N = map(int, input().split())
p = list(map(int, input().split()))

a = []
for i in range(-100, 201, 1):
    a.append(i)

panda_set = set(a) ^ set(p)
panda = list(panda_set)
panda.sort()

ans = 1000
absolute = 1000
for num in panda:
    if(absolute > abs(X - num)):
        ans = num
        absolute = abs(X - num)

print(ans)

Measured memory_bytes: 9176