akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    string blue[n];
    
	for (int i = 0; i < n; i++) {
        cin >> blue[i];
    }
    
	int m;
    cin >> m;
    string red[m];
    
	for (int i = 0; i < m; i++) {
        cin >> red[i];
    }

    int ans = 0;
    for (int i=0; i<n; i++)
	{
		string word=blue[i];   
		int count=0;
		
		for (int j=0; j<n; j++){
			if (blue[j]==word) count++;
		}
		
		for (int j=0; j<m; j++){
			if (red[j]==word) count--;
		}
		
		ans = max(ans, count);
	}
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		String[] fields = input.nextLine().split(" ");
		int H = Integer.parseInt(fields[0]);
		int W = Integer.parseInt(fields[1]);
		String[][] grid = new String[H][W];
		for (int i = 0; i < grid.length; i++) {
			String x = input.nextLine();
			for (int j = 0; j < x.length(); j++) {
				grid[i][j] = x.substring(j,j+1);
			}
		}
		System.out.println(uniquePathsWithObstacles(grid));
	}
	public static int uniquePathsWithObstacles(String[][] obstacleGrid) {
        int[][] dp = new int[obstacleGrid.length][obstacleGrid[0].length];
        int mod = 1000000007;
        if (obstacleGrid[0][0].equals("#")) return 0;
        dp[0][0] = 1;
        for (int i = 1; i < obstacleGrid.length; i++) {
        	if (!obstacleGrid[i][0].equals("#")) dp[i][0] = 1;
        	else break;
        }
        for (int i = 1; i < obstacleGrid[0].length; i++) {
        	if (!obstacleGrid[0][i].equals("#")) dp[0][i] = 1;
        	else break;
        }
        for (int i = 1; i < obstacleGrid.length; i++) {
        	for (int j = 1; j < obstacleGrid[0].length; j++) {
        		if (!obstacleGrid[i][j].equals("#")) dp[i][j] = dp[i-1][j]+dp[i][j-1];
        		else dp[i][j] = 0;
        		if (dp[i][j]>mod) dp[i][j]-=mod;
        	}
        }
		return dp[obstacleGrid.length-1][obstacleGrid[0].length-1];
    }
}

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

using namespace std;

// HLD + Euler Tour Trick
const int N = 100 * 1000 + 10;
int n; vector<int> g[N];
int size[N], depth[N], par[N];
int head[N], chain[N], heavy[N];
int tchains;
vector <int> nodes;
int tin[N], tout[N];

void dfs(int u, int p, int d) {
	par[u] = p; depth[u] = d; 
	size[u] = 1; heavy[u] = -1;
	for (auto v : g[u]) if (v != p) {
		dfs(v, u, d + 1); size[u] += size[v];
		if (heavy[u] == -1 || size[v] > size[heavy[u]])
			heavy[u] = v;
	}
}

void build_hld(int root, int u, int p) {
	head[u] = root; chain[u] = tchains;
	tin[u] = nodes.size(); nodes.push_back(u);
	if (heavy[u] != -1) build_hld(root, heavy[u], u);
	for (auto v : g[u]) if (v != p && v != heavy[u])
		tchains++, build_hld(v, v, u);
	tout[u] = nodes.size() - 1;
}

void hld() { 
	tchains = 0; nodes.clear(); 
	dfs(0, 0, 0); 
	build_hld(0, 0, -1);
}

int lca(int u, int v) {
	while (chain[u] != chain[v]) {
		if (depth[head[v]] > depth[head[u]]) swap(u, v);
		u = par[head[u]];
	}
	if (depth[u] > depth[v]) swap(u, v); return u;
}

void test_hld() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		g[i].clear();
	}
	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		while (c--) {
			int x;
			cin >> x;
			g[i].push_back(x);
			g[x].push_back(i);
		}
	}
	hld();
	int m;
	cin >> m;
	while (m--) {
		int x, y;
		cin >> x >> y;
		cout << lca(x, y) << "\n";
	}
}

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


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

int main() {
 	int N, K;
  	cin >> N >> K;
  
	if (N == K || K == 1) {
  	cout << 0 << endl;
  }
  else {
  	cout << N - K << endl; 
  }  
  
}

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int a[100001];
long b[100001];
long d[100001];
int main(void){
	int n=nextint();
	a[0]=nextint();
	if(n==0){
		if(a[0]==1){
			puts("1");
		}else{
			puts("-1");
		}
	}else{
		if(a[0]==0){
			d[0]=1;
			for(int i=1; i<=n; i++){
				a[i]=nextint();
				if(a[i]>d[i-1]*2){
					puts("-1");
					return 0;
				}
				d[i]=d[i-1]*2-a[i];
				if(d[i]>LONG_MAX/2) d[i]=LONG_MAX/2;
			}
			b[n]=0;
			for(int i=n; i>0; i--){
				if(d[i-1]>=a[i]+b[i]){
					b[i-1]=a[i]+b[i];
				}else{
					b[i-1]=d[i-1];
				}
			}
			long ans=0;
			for(int i=0; i<=n; i++){
				ans+=a[i];
				ans+=b[i];
			}
			printf("%ld\n", ans);
		}else{
			puts("-1");
		}
	}
}


Measured memory_bytes: 3552
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		TreeSet<Integer> ts = new TreeSet<>();
		for (int i = 0; i < k; i++) {
			if (a + i <= b) {
				ts.add(a + i);
			}
			if (a <= b - i) {
				ts.add(b - i);
			}
		}
		Iterator<Integer> ite = ts.iterator();
		while (ite.hasNext()) {
			System.out.println(ite.next());
		}
	}
}


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

bool f(int x)
{
	int keta = 0;
	while(x)
	{
		keta++;
		x /= 10;
	}
	return keta % 2 == 1;
}

int main()
{
int a;
cin >> a;
int ans =0;
for(int i = 1; i <= a; i++)
{
	if(f(i)) ans++;
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
R, C, N = map(int, input().split())


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def check(x, y):
    if x == 0:
        return y
    elif x == R:
        return R + C + C - y
    elif y == 0:
        return C + R + C + R - x
    elif y == C:
        return C + x
    else:
        return -1


lr_list_raw = []
z_list = []
for i in range(N):
    x1, y1, x2, y2 = map(int, input().split())
    z1, z2 = check(x1, y1), check(x2, y2)
    if z1 >= 0 and z2 >= 0:
        lr_list_raw.append((min(z1, z2), max(z1, z2)))
        z_list.append(z1)
        z_list.append(z2)

z_list.sort()
idx = {zi: i+1 for i, zi in enumerate(z_list)}
lr_list = []
for l_raw, r_raw in lr_list_raw:
    lr_list.append((idx[l_raw], idx[r_raw]))

'''
print(z_list)
print(idx)
print(lr_list_raw)
'''

bit = Bit(max(idx.values()) + 3)
for l, r in lr_list:
    if (bit.sum(r) - bit.sum(l)) % 2 == 1:
        print('NO')
        exit()
    bit.add(l, 1)
    bit.add(r, 1)

print('YES')


Measured memory_bytes: 93472
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
    int A, B;
    cin >> A >> B;

    if(A % 3 == 0 && A >= 3){
      cout << "Possible";
    }else if(B % 3 == 0 && B >= 3){
      cout << "Possible";
    }else if((A+B)%3 == 0 && A+B >= 3){
      cout << "Possible";
    }else{
      cout << "Impossible";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXA 1001
#define MAXB 1001
#define MAXH 1000000001
#define MAXW 1000000007
#define INF 1000000007
#define MAXN 101
#define MAXP 1000001
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> p;

int sx, sy, tx, ty;
int main(){
    string s;
    cin >> sx >> sy >> tx >> ty;
    for(int i = 0;i < ty - sy;i++){
        s += "U";
    }
    for(int i = 0;i < tx - sx;i++){
        s += "R";
    }
    for(int i = 0;i < ty - sy;i++){
        s += "D";
    }
    for(int i = 0;i < tx - sx;i++){
        s += "L";
    }
    s += "LU";
    for(int i = 0;i < ty - sy;i++){
        s += "U";
    }
    for(int i = 0;i < tx - sx;i++){
        s += "R";
    }
    s += "RDRD";
    for(int i = 0;i < ty - sy;i++){
        s += "D";
    }
    for(int i = 0;i < tx - sx;i++){
        s += "L";
    }
    s += "LU";
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    for (auto &&i : a)
    {
        cin >> i;
    }

    ll ans = 0;

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

    cout << ans << endl;
}


Measured memory_bytes: 4768
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

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

  int ans = 0;
  FOR(i, 22, d + 1)
  {
    int d1 = i / 10;
    int d2 = i % 10;
    if (d1 < 2 || d2 < 2)
      continue;
    if (d1 * d2 <= m)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
N,M = map(int, input(). split())

s = [0,]*M
c = [0,]*M
ans =[10,]*N



for i in range(M):
    s[i], c[i] = map(int, input(). split())
    if ans[s[i]-1] != 10 and ans[s[i]-1] != c[i]:
        print(-1)
        sys.exit()
    else:
        ans[s[i]-1] = c[i]       
if N >= 2:
        
    A = 0        
    if ans[0] == 0:
        print(-1)
        sys.exit()
    elif ans[0] == 10:
        ans[0] = 1
        for j in range(N):
            if ans[j] == 10:
                ans[j] = 0
        for k in range(N):
            A += 10**(N-k-1)*ans[k] 
    
        print(A)
        
    else:
        for j in range(N):
            if ans[j] == 10:
                ans[j] = 0
        for k in range(N):
            A += 10**(N-k-1)*ans[k] 
        print(A)
else:
    A = 0
    if ans[0] == 0 or ans[0] == 10:
        print(0)
    else:
        print(ans[0])
    


    

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

int main()
{
	list<int> noList;
	int i, no;
	double w, h;
	char c;

	while (1)
	{
		cin >> no;
		if (cin.eof()) break;
		cin >> c >> w >> c >> h;
		if (w / (h * h) >= 25)
			noList.push_back(no);
	}

	while (!noList.empty())
	{
		cout << noList.front() << endl;
		noList.pop_front();
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1e9+7;
ll ans,n,m,k,jc[1000010],ny[1000010];
ll ksm(ll x,ll y){
	ll xlh=1;
	while(y){
		if(y&1)xlh=xlh*x%p;
		x=x*x%p;
		y/=2;
	}
	return xlh;
}
ll C(ll x,ll y){
	return jc[x]*ny[y]%p*ny[x-y]%p;
}
int main(){
	ll i,j;
	scanf("%lld%lld%lld",&n,&m,&k);
	jc[0]=ny[0]=1;
	for(i=1;i<=n+m+k;i++)jc[i]=jc[i-1]*i%p,ny[i]=ksm(jc[i],p-2);
	if(m<k)swap(m,k);
	for(i=0,j=1;i<=m+k;i++){
		ans=(ans+C(n-1+i,n-1)*ksm(3,m+k-i)%p*j%p)%p;
		if(i<k)j=j*2%p;
		 else if(i>=m)j=(j*2-C(i,k)-C(i,i-m)+p*2)%p;
		  else j=(j*2-C(i,k)+p)%p;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 15104
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,y;cin >>x  >> y;
    for(int i=0;i<=x;i++)
    {
    	for(int j=0;j<=x;j++)
    	{
    		if(i+j==x and 2*i+4*j==y){cout << "Yes\n";return 0;}
    	}
    }
    cout << "No\n";
    }

Measured memory_bytes: 3660
#include <iostream>
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
using namespace std;



int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,n,k,m;
     ll t;
     cin>>n;
     double d=(1.0*3.141592653589793238);
     d=d*(2*n);
     cout<<d;
}


Measured memory_bytes: 3796
#include <stdio.h>
#include <inttypes.h>

int N, P;
char S[271828];

int count[12345];

int add(int a, int b) {
	int r = (a % P) + (b % P);
	if (r >= P) r -= P;
	return r;
}

int sub(int a, int b) {
	int bb = b % P;
	return bb == 0 ? a % P : add(a, P - bb);
}

int mul(int a, int b) {
	return ((a % P) * (b % P)) % P;
}

int pou(int a, int b) {
	int r = 1;
	while (b > 0) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

int inv(int a) {
	return pou(a, P - 2);
}

int dexibu(int a, int b) {
	return mul(a, inv(b));
}

int main(void) {
	int i;
	int asumi = 1, iguti = 0;
	int64_t mizuhasu = 0;
	if (scanf("%d%d", &N, &P) != 2) return 1;
	if (scanf("%271827s", S) != 1) return 1;
	if (P == 2) {
		for (i = 0; i < N; i++) {
			int x = S[i] - '0';
			if (0 <= x && x < 10 && x % 2 == 0) mizuhasu += i + 1;
		}
	} else if (P == 5) {
		for (i = 0; i < N; i++) {
			int x = S[i] - '0';
			if (0 <= x && x < 10 && x % 5 == 0) mizuhasu += i + 1;
		}
	} else {
		count[0] = 1;
		for (i = 0; i < N; i++) {
			int ogura;
			if (S[i] < '0' || '9' < S[i]) continue;
			asumi = mul(asumi, 10);
			iguti = add(mul(iguti, 10), S[i] - '0');
			ogura = dexibu(sub(0, iguti), asumi);
			mizuhasu += count[ogura]++;
		}
	}
	printf("%" PRId64 "\n", mizuhasu);
	return 0;
}

/*

P = 7

  0 1 2

0 0 1 5
1 3 3 4
2 6 5 3
3 2 0 2
4 5 2 1
5 1 4 0
6 4 6 6

(x*10+0)=k1 x=(k1-0)/10
((x*10+0)*10+1)=k2 x=((k2-1)/10)-0)/10
	x*100+(0*10+1)=k2
(((x*10+0)*10+1)*10+2)=k3
	x*1000+(0*100+1*10+2)=k3

各桁ごとにそれぞれの状態(Pで割った余り)の数を数えておいて0になった数をカウントし、
さらに0の状態の数に1を加えたい。
ただし、それぞれの状態の数を毎回コピーしていたら遅い。
コピーの代わりにどこに格納しているかを管理し、
さらに0がどこにあるかだけを管理すればいい。
どうやって？ → 位置の決まり方を考えると、最初の状態をxとし、
xの項と定数項に分けておけば、x*(10**n)+k=0の形になり、
これはすぐ解けるはずである。

*/


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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i = 0; i < N; i++)
        cin >> L[i];

    int res = 1, now = 0;
    for (int i = 0; i < N; i++) {
        now += L[i];
        if (now <= X) res++;
        else break;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn modpow(a: usize, n: usize, p: usize) -> usize {
    let mut base = a;
    let mut acc = 1;
    let mut exp = n;

    while exp > 0 {
        if (exp & 1) == 1 {
            acc = acc * base % p;
        }
        exp /= 2;
        base = base * base % p;
    }

    acc
}

#[fastout]
fn main() {
    input! {
    n: usize,
    a: [usize; n]
    }
    let p = 1_000_000_007;
    let d = n / 2 + if n % 2 == 1 {1} else {0} ;
    let mut c = vec![0; d + 1];
    for i in 0..n{
        c[(n - a[i]) / 2] += 1;
    }
    for i in 0..d {
        if i == d - 1 && c[i] == 1 {
            break;
        }
        if c[i] != 2 {
            println!("0");
            return
        }
    }
    println!("{}", modpow(2, n / 2, p));
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define inf INFINITY
#define file freopen( "input.txt" , "r" , stdin) ; freopen( "output.txt" , "w" , stdout) ;
#define Gamed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define _3102_ main()
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
const int N = 1e5 + 100;
const ll MX = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-9 ;

ll n, a[N] , b[N] , c[N], dp[N][3] ;


int _3102_{
	Gamed
	cin >> n ;
	for ( int i = 0 ; i < n ; i ++ ) {
		cin >> a[i] >> b[i] >> c[i] ;
	}
	dp[0][0] = a[0] , dp[0][1] = b[0] , dp[0][2] = c[0] ;
	for ( int i = 1 ; i < n ; i ++){
		dp[i][0] = a[i] + max (dp[i-1][1] , dp[i-1][2]) ;
		dp[i][1] = b[i] + max (dp[i-1][0] , dp[i-1][2]) ;
		dp[i][2] = c[i] + max (dp[i-1][0] , dp[i-1][1]) ;
	}
	cout << max ( dp[n-1][0] , max ( dp[n-1][1] , dp[n-1][2])) << endl ;
	return 0;
}


Measured memory_bytes: 8268
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>
#include <queue>
#include <assert.h>
#include <set>
#include <numeric>
#include <memory.h>

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

//#define int long long
typedef long long ll;

const ll INF = 1e18;

using namespace std;

const int N = 2005;
int n, m, cnt, s[N][N], s1[N][N], s2[N][N];
char a[N][N];

int calc(int s[][N], int x1, int y1, int x2, int y2)
{
    if (x1 > x2 || y1 > y2) return 0;
    return s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1];
}

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> m >> n >> cnt;
    for (int i=1; i<=m; i++) scanf("%s", a[i] + 1);
    for (int i=1; i<=m; i++) {
        for (int j=1; j<=n; j++) {
            s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(a[i][j]=='1');
            s1[i][j]=s1[i-1][j]+s1[i][j-1]-s1[i-1][j-1]+(a[i][j]=='1' && j<n && a[i][j+1]=='1');
            s2[i][j]=s2[i-1][j]+s2[i][j-1]-s2[i-1][j-1]+(a[i][j]=='1' && i<m && a[i+1][j]=='1');
        }
    }
    while (cnt--){
        int x1,x2,y1,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        printf("%d\n",calc(s,x1,y1,x2,y2)-calc(s1,x1,y1,x2,y2-1)-calc(s2,x1,y1,x2-1,y2));
    }
}


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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#define IF_DEBUG 0
typedef long long ll;
typedef double db;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;
const db pi = acos(-1.0);

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 200050;

int x1, yy, x2, y2, N, n, f[maxn], d[maxn], cnt;
struct node{int x, y;}a[maxn];
int bit[maxn], ans;
db Ans;

bool cmp(node a, node b){return a.x < b.x;}
void add(int x,int z){for(;x<=cnt;x+=x&-x)bit[x]=max(bit[x],z);}
int ask(int x,int ret = 0){for(;x;x-=x&-x)ret=max(ret,bit[x]);return ret;}
int main()
{
	scanf("%d%d%d%d",&x1,&yy,&x2,&y2);
	if(x1 > x2)
	{
		swap(x1,x2); swap(yy,y2);
	}
	bool tag = false;
	if(yy > y2)
	{
		swap(yy, y2);
		tag = true;
	}
	Ans = (abs(x1-x2)+abs(yy-y2));
	Ans *= 100;
	scanf("%d",&N);
	fo(i,1,N) 
	{
		int x, y; scanf("%d%d",&x,&y);
		if(tag) y = yy+y2-y;
		if(x < min(x1,x2) || x > max(x1,x2) || y < min(yy,y2) || y > max(yy,y2))
			continue;
		++ n;
		a[n] = (struct node){x,y};
	}
	sort(a+1,a+n+1,cmp);
	fo(i,1,n) d[++cnt] = a[i].y;
	sort(d+1,d+cnt+1);
	cnt = unique(d+1,d+cnt+1)-d-1;
	fo(i,1,n) a[i].y = lower_bound(d+1,d+cnt+1,a[i].y)-d;
	fo(i,1,n) {f[i] = ask(a[i].y)+1; add(a[i].y,f[i]); gmax(ans, f[i]);}
	if(ans > min(abs(x2-x1),abs(y2-yy))) Ans += pi*5*(ans+1);
	else Ans += pi*5*ans;
	Ans -= ans*20;
	printf("%.12f",Ans);
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

int main() {
    string s;
    cin >> s;
    bool ans = true;
    for (int i = 0; i < s.size()/2; i++) {
        if (s[i] != s[s.size()/2 - 1 - i]) {
            ans = false;
        }
    }

    for (int i = s.size()/2 + 1; i < s.size(); i++) {
        int a = i;
        int b = s.size() - 1 - i + (s.size()/2 + 1);
        if (s[i] != s[s.size() - 1 - i + (s.size()/2 + 1)]) {
            ans = false;
        }
    }

    string reversed(s);
    reverse(reversed.begin(), reversed.end());
    ans = ans && (s == reversed);
    cout << (ans ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;


int main(){
    int n,m;cin >>n>>m;
    V a(m);
    V b(m);
    V c(m);
    VVl d(n,Vl(n,INF));
    for (int i = 0; i < n; ++i) {
        d[i][i]=0;
    }
    for (int i = 0; i < m; ++i) {
        cin >>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
        d[a[i]][b[i]]=c[i];
        d[b[i]][a[i]]=c[i];
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    ll ans=0;
    for (int i = 0; i < m; ++i) {
        if(d[a[i]][b[i]]!=c[i])ans++;
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int N;
  cin >> N;
  vector<int> X(N);
  vector<int> A(100);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < N; j++) {
      A.at(i) += (X.at(j) - (i + 1))*(X.at(j) - (i + 1));
    }
  }
  sort(A.begin(), A.end());
  cout << A.at(0) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int n,m,memo = 0,cells[90][90] = {0},is_visited[90][90] = {0};

void dfs(int x,int y,int d){
    memo = max(memo,d);
    
    if(x != 0 && !is_visited[x-1][y] && cells[x-1][y]){
        is_visited[x-1][y] = 1;
        dfs(x-1,y,d+1);
        is_visited[x-1][y] = 0;
    }
    if(x != n-1 && !is_visited[x+1][y] && cells[x+1][y]){
        is_visited[x+1][y] = 1;
        dfs(x+1,y,d+1);
        is_visited[x+1][y] = 0;
    }
    if(y != 0 && !is_visited[x][y-1] && cells[x][y-1]){
        is_visited[x][y-1] = 1;
        dfs(x,y-1,d+1);
        is_visited[x][y-1] = 0;
    }
    if(y != m-1 && !is_visited[x][y+1] && cells[x][y+1]){
        is_visited[x][y+1] = 1;
        dfs(x,y+1,d+1);
        is_visited[x][y+1] = 0;
    }
    
    return;
}



int main(){
    
    while(1){
        cin >> n >> m;
        if(n+m == 0) break;
        memo = 0;
        
        rep(i,0,n){
            rep(j,0,m){
                cin >> cells[i][j];
            }
        }
        
        rep(i,0,n){
            rep(j,0,m){
                if(!cells[i][j]) continue;
                
                is_visited[i][j] = 1;
                dfs(i,j,1);
                is_visited[i][j] = 0;
            }
        }
        
        cout << memo << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define rem 1000000007

typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
#define v(x) vector<x>
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(x,y) make_pair(x,y)
#define mii map<ll,ll>
#define umii unordered_map<ll,ll>
#define mxheap priority_queue<ll> // Max Heap
#define mnheap priority_queue<ll,vi,greater<ll> > // Min Heap
#define da(type,arr,size) type *arr = new type[n] // Dynamically allocated array


#define f(i,n) for(ll i=0;i<(n);i++)
#define fa(i,a,b) for(ll i=(a);i<(b);i++)
#define far(i,a,b) for(ll i=(a);i>(b);i--)
#define T ll t; cin>>t; while(t--)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()

#define setbits(x) __builtin_popcountll(x) // Total set bits in a number
#define zerobits(x) __builtin_ctzll(x) // This will tell me number of zeroes till first set bit
#define all(c) (c).begin(),(c).end()
#define setp(x,y) fixed<<setprecision(y)<<x
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define INF 2e18


ll mod(ll n) {
	return n > 0 ? n : -1 * n;
}
ld dist(ll x1, ll y1, ll x2, ll y2) {
	ld ans = round(pow(mod(x2 - x1), 2)) + round(pow(mod(y2 - y1), 2));
	ans = sqrt(ans);
	return ans;
}

ld dist(pii a, pii b) {
	ld ans = round(pow(mod(b.ff - a.ff), 2)) + round(pow(mod(b.ss - a.ss), 2));
	ans = sqrt(ans);
	return ans;
}
umii isPrime;
void SieveOfEratosthenes(ll n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));

	for (int p = 2; p * p <= n; p++)
	{
		if (prime[p] == true)
		{
			for (ll i = p * p; i <= n; i += p)
				prime[i] = false;
		}
	}
	for (ll p = 2; p <= n; p++)
		if (prime[p])
			isPrime[p] = 1;
}
int *dp;
ll maxCompositeSummands(ll n) {
	if (n == 2 || n == 1 || n == 3) {
		return INT_MIN;
	}
	if (dp[n] != -1) {
		return dp[n];
	}
	ll mexx = INT_MIN;
	for (ll i = 4; i <= n; i++) {
		if (!isPrime[i]) {
			mexx = max(mexx, maxCompositeSummands(n - i));
		}
	}
	return dp[n] = mexx == INT_MIN ? mexx : mexx + 1;
}
int main() {
	fast
	ll n;
	cin >> n;
	umii mp;
	ll temp;
	f(i, (n - 1)) {
		cin >> temp;
		mp[temp]++;
	}
	fa(i, 1, (n + 1)) {
		cout << mp[i] << endl;
	}
}

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

const int INF = 0x3f3f3f3f;
const int MAXN = 1123;

int h, w;
char mapa[MAXN][MAXN];
int pd[MAXN][MAXN];
int mod = 1000000000+7;

int rec(int x, int y)
{
	if( pd[x][y] != -1)
		return pd[x][y];

	if((x==h) && (y==w))
		return 1;

	if(x>h || y>w)
		return 0;

	if(mapa[x][y] == '#')
		return 0;

	return pd[x][y] = (rec(x+1, y) + rec(x, y+1))%mod;
}

int main(){
	memset(pd, -1, sizeof(pd));
	scanf("%d %d\n", &h, &w);

	for(int i=1; i<=h; i++)
	{
		for(int j=1; j<=w; j++)
			cin >> mapa[i][j];
		scanf("%*c");
	}

	cout << rec(1, 1) << endl;

	return 0;
}

Measured memory_bytes: 6528
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    for(int i=0; i<M; i++){
      N -= sc.nextInt();
    }
    if(N<0){
      System.out.print("-1");
    }else{
      System.out.print(N);
    }
  }
}


Measured memory_bytes: 46576
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int> > A(n,vector<int>(m));
  vector<int> B(m);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>A[i][j];
    }
  }
  for(int i=0;i<m;i++)cin>>B[i];

  for(int i=0;i<n;i++){
    int tmp=0;
    for(int j=0;j<m;j++){
      tmp+=A[i][j]*B[j];
    }
    cout<<tmp<<endl;
  }
}



Measured memory_bytes: 3244
import sys
input = sys.stdin.readline

N=int(input())
S=list(map(int,input().split()))

ANS=0

for i in range(1,N//2):
    s=0
    l=N-1
    SCORE=0

    if (N-1)%i==0:
        while l>s and l>i:

            SCORE+=S[s]+S[l]
            ANS=max(ANS,SCORE)
            s+=i
            l-=i
        #print(SCORE,i,l,s)
    else:
        while l!=s and l>i:

            SCORE+=S[s]+S[l]
            ANS=max(ANS,SCORE)
            s+=i
            l-=i

        #print(SCORE,i,l,s)

print(ANS)

Measured memory_bytes: 14332
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl

#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
//int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.ff == b.ff) {
        return (b.ss < a.ss);
    }
    return (a.ff<b.ff);
}
int poww(int a, int b)
{
    int res = 1;
    for(int i = 1; i<=b; ++i)
        res *= a;

    return res;
}
int findlcm(int arr[], int n) 
{ 
    // Initialize result 
    int ans = arr[0]; 
  
    // ans contains LCM of arr[0], ..arr[i] 
    // after i'th iteration, 
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (__gcd(arr[i], ans))); 
  
    return ans; 
}
bool prime[100001];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
  }
}

//Define mx for maximum range and MOD for large numbers
#define mx 101
#define MOD 1000000007;

// Declare all the variables and global functions here - 
int n,m;
int32_t main()
{
    IOS;
 //    #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    freopen("output.txt","w",stdout);
	// #endif
    /********************* From here **********************/
    
    int a,b;
    cin >> a >> b;	
    if(a >= 13){
    	cout << b << endl;
    	return 0;
    }
    if(a>=6 && a<=12){
    	cout << b/2 << endl;
    	return 0;
    }
    if(a <= 5){
    	cout << 0 << endl;
    	return 0;
    }

    
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

ll dp[51][3100][2];

int main()
{
  int n;
  cin >> n;
  
  vi a(n);
  int x = 0;
  rep(i, n){
    cin >> a[i];
    x ^= a[i];
  }

  int ans = 0;
  for(int i = 30; i >= 0; i--){
    if(x & 1<<i){
      rep(j, n){
        if((a[j]^(a[j]-1)) == (1<<(i+1))-1){
          x ^= a[j]^(a[j]-1);
          ans++;
          break;
        }
      }
    }
  }

  if(x == 0){
    cout << ans << endl;
  }else{
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

ll k;
string s;

void solve(){
    cin >> s;
    cin >> k;
    int n=s.length();
    ll l=1;
    vector<ll> vec;
    Rep(i,1,n){
        if (s[i]==s[i-1]){
            l++;
        }
        else{
            vec.push_back(l);
            l=1;
        }
    }
    vec.push_back(l);
    int m=vec.size();
    if (m==1){
        cout << n*k/2 << endl;
        return;
    }
    ll ans=0;
    if (s[0]==s[n-1]){
        ans+=vec[0]/2+vec[m-1]/2;
        ans+=(k-1)*((vec[0]+vec[m-1])/2);
        Rep(i,1,m-1){
            ans+=k*(vec[i]/2);
        }
    }
    else{
        rep(i,m){

            ans+=k*(vec[i]/2);
        }
    }
    cout << ans << endl;
    
}

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

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

int dig(int n){
    int ans = 0;
    while( n > 0 ){
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

void solve(long long N){
    int ans = 10000;
    for(int i = 1 ; i < N ; i++){
        ans = min(ans, dig(i) + dig(N-i));
    }
    cout << ans << endl;
}

int main(){    
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int main(){
    int n,dp[100010]={},h[100010];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void) {
	int r, g, b,num;
	char buf[128];
	
	fgets(buf,128,stdin);
	sscanf(buf,"%d %d %d",&r,&g,&b);
	
	num = r*100 + g*10 + b*1;
	
	if(num%4 == 0) {
		printf("YES");
	} else {
		printf("NO");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L;
    cin >> L;
    double ans = L * L * L;
    printf("%.16lf", ans / 27);
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = list(str(input()))

count = 1
L = []
L.append(0)
for i in range(N):
    if i < N-1:
        if S[i] == S[i+1]:
            count += 1
        else:
            L.append(count)
            count = 1
    else:
        L.append(count)
        count = 1
L.append(0)

if S[0] == '1':
    ans = 0
    tmp = 0
    dist = 2 * (K + 1)
    for i in range(len(L)):
        tmp += L[i]
        if i % 2 == 1:
            if i - dist >= 0:
                tmp -= L[i-dist]
                tmp -= L[i-dist+1]
            ans = max(ans, tmp)
        else:
            if i == N - 1:
                ans = max(ans, tmp)
    print(ans)

if S[0] == '0':
    ans = 0
    tmp = 0
    dist = 2 * (K + 1)
    for i in range(len(L)):
        tmp += L[i]
        if i % 2 == 0:
            if i - dist + 1 >= 0:
                tmp -= L[i-dist+1]
            if i - dist >= 0:
                tmp -= L[i-dist]
            ans = max(ans, tmp)
        else:
            if i == N - 1:
                ans = max(ans, tmp)
    print(ans)

Measured memory_bytes: 49548
#include <bits/stdc++.h>
using namespace std;
using llong = long long;

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

llong fnSumOfMultpl(const vector<int>& cnrvnNum)
{
  const int cnnMod = 1e9 + 7;
  llong nCumlSum = 0;

  for (int i = 0; i < cnrvnNum.size(); ++i)
    nCumlSum += cnrvnNum[i];

  llong nSumOfMultpl = 0;

  for (int i = 0; i < cnrvnNum.size() - 1; ++i)
  {
    nCumlSum -= cnrvnNum[i];

    nSumOfMultpl += cnrvnNum[i] * ( nCumlSum % cnnMod );
    nSumOfMultpl %= cnnMod;
  }

  return nSumOfMultpl;
}
  
int main()
{
  vector<int> vnNum;
  
  fnInput(vnNum);
  cout << fnSumOfMultpl(vnNum) << endl;

  return 0;
}

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

#define PI 3.14159265358979323846264338327950L


int main()
{
  // 入力
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  
  long double rad = PI * 2 * (
 (long double) H / 12.0 + ((long double)M / 60.0) / 12.0 - (long double)M / 60.0);
  long double rsq = (long double)(A*A + B*B) - (long double)(2*A*B)*cosl(rad);

  //cout << fixed << setprecision(20) << rad << endl;
  cout << fixed << setprecision(20) << sqrtl(rsq) << endl;
  //printf("%20.20Lf\n", sqrtl(rsq));

  return 0;
}

Measured memory_bytes: 4060
#include <iostream>
#include <algorithm>
#include <cmath>

int main (int, char**) {
    long long N;
    long long K;
    std::cin >> N >> K;
    long long amari = N%K;
    long long amari2 = N%K - K;
    if (amari2 < 0) amari2 = -amari2;
    if (amari <= amari2) {
        std::cout << amari << std::endl;
    } else {
        std::cout << amari2 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 100010
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int a[N],val[N];
int main()
{
	int n=read(),m=read(),v=read(),p=read(); int t=1;
	for(int i=1;i<=n;i++)	a[i]=val[i]=read();
	sort(val+1,val+n+1); int l=1,r=n-p,ans=p;
	while(l<=r)
	{
		int mid=l+r>>1; int wei=val[mid];
		int rk=0; int nwei=wei+m;
		for(int i=1;i<=n;i++)	if(val[i]>nwei)	rk++;
		if(rk>=p)	l=mid+1;
		else
		{
			ll rst=1ll*m*(v-rk-1);
			for(int i=1;i<=n-rk;i++)	if(i!=mid)
				rst-=min(m,nwei-val[i]);
			int gg=p-1-rk;
			for(int i=n-rk,j=1;j<=gg;i--)	if(i!=mid)
				rst-=max(val[i]-wei,0),j++;
			if(rst<=0)	ans=n-mid+1,r=mid-1;
			else	l=mid+1;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll inf = 3e18;
const char sp = ' ';

int N, A, B, C, D;
string S;

bool tourist() {
	if (C < D) {
		for (int i = A; i < C; i++) {
			if (S[i] == '#'&&S[i + 1] == '#') {
				return false;
			}
		}
		for (int i = B; i < D; i++) {
			if (S[i] == '#'&&S[i + 1] == '#') {
				return false;
			}
		}
		return true;
	}
	else {
		for (int i = A; i < C; i++) {
			if (S[i] == '#'&&S[i + 1] == '#') {
				return false;
			}
		}
		for (int i = B; i <= D; i++) {
			if (S[i - 1] == '.'&&S[i] == '.'&&S[i + 1] == '.') {
				return true;
			}
		}
		return false;
	}
}

int main() {
	cin >> N >> A >> B >> C >> D >> S;
	A--;
	B--;
	C--;
	D--;
	if (tourist()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
int main(){
  char n[4];
  cin>>n[0]>>n[1]>>n[2]>>n[3];
  if(n[1]==n[2]&&(n[0]==n[1]||n[3]==n[1])){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,min_v,max_v;
  cin >> n;
  vector<ll> a(n),b(n);
  vector<ll> mi(n),ma(n);
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    if(n%2==0){
      a[i] *= 2;
      b[i] *= 2;
    }
    mi[i] = a[i];
    ma[i] = b[i];
  }
  sort(mi.begin(),mi.end());
  sort(ma.begin(),ma.end());
  if(n%2){
    min_v = mi[n/2];
    max_v = ma[n/2];
  }else{
    min_v = (mi[n/2]+mi[n/2-1])/2;
    max_v = (ma[n/2]+ma[n/2-1])/2;
  }
  cout << max_v - min_v + 1<<endl;
}


Measured memory_bytes: 9536
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    f = [1]*(n+1)
    ans = 1
    for i in range(2, n+1):
        for j in range(i, n+1, i):
            f[j] += 1
        ans += i*f[i]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 146048
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll k; cin >> k;
    ll a, b; cin >> a >> b;

    ll temp = 0;
    bool is_achieved = false;
    while(temp <= b){
        temp += k;
        if(a <= temp && temp <= b){
            is_achieved = true;
            break;
        }
    }

    if(is_achieved){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
    int n;
    scanf("%d", &n);

    int flag = 0;
    for (int i=0; i < 26; i++){
        for (int j=0; j < 16; j++){
            if (4*i + 7*j == n) flag = 1;
        }
    }

    if (flag == 1) printf("Yes\n");
    else printf("No\n");


    return 0;
} 



Measured memory_bytes: 128
import fractions
import math
def x(n):
    a=[1]
    for i in range(2,int(math.sqrt(n))+1):
        while n%i==0:
            n//=i
            a.append(i)
    a.append(n)
    return a
A,B = map(int,input().split())
n=fractions.gcd(A,B)
print(len(set(x(n))))

Measured memory_bytes: 64492
<?php
  $s = trim(fgets(STDIN));
  $ans = 0;
  for($i=1; $i<=strlen($s); $i++){
      $ss = substr($s,0,$i);
      $len = strlen($ss);
      if($len%2 == 0){
          $len2 = $len/2;
          $front_ss = substr($ss,0,$len2);
          $back_ss = substr($ss,$len2);
        //   echo $ss."\n";
        //   echo $front_ss."\n";
        //   echo $back_ss."\n";
        if($front_ss == $back_ss && $ss != $s){
            $ans = max($len,$ans);
        }
      }
  }
  
  echo $ans;

Measured memory_bytes: 4604
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"

using namespace std;

int main()
{
  int n;
  cin >> n;
  int s = 0;
  int a[110];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    s += a[i];
  }
  int ans = 0;
  int ansnum = abs(a[0] * n - s);
  for (int i = 0; i < n; i++)
  {
    if (ansnum > abs(a[i] * n - s))
    {
      ans = i;
      ansnum = abs(a[i] * n - s);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,M,X,Y = map(int, input().split())
Xx = [int(x) for x in input().split()]
Yy = [int(x) for x in input().split()]

mxx = max(Xx)
mny = min(Yy)
if mxx < mny and X < mny and mxx < Y:
    print("No War")
else:
    print("War")


Measured memory_bytes: 2940
N = int(input())
XY = []
points = []
for i in range(N):
	points.append(i)
	x, y = list(map(int, input().split()))
	XY.append((x, y))

import math
import itertools
count = math.factorial(N)
line = 0
for pp in itertools.permutations(points, N):
	i = 0
	while i < N - 1:
		i1, i2 = pp[i], pp[i + 1]
		t = ((XY[i1][0] - XY[i2][0]) ** 2 + (XY[i1][1] - XY[i2][1]) ** 2) ** 0.5 
		line += t
		i += 1
ans = line / count
print(ans)


Measured memory_bytes: 9412
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

int main()
{
  int64_t N;
  vector<string> S;

  cin >> N;
  S.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  map<string, int> C{
      {"AC", 0},
      {"WA", 0},
      {"TLE", 0},
      {"RE", 0},
  };

  for (auto &&s : S) {
    C[s]++;
  }

  cout << "AC"
       << " x " << C["AC"] << endl;
  cout << "WA"
       << " x " << C["WA"] << endl;
  cout << "TLE"
       << " x " << C["TLE"] << endl;
  cout << "RE"
       << " x " << C["RE"] << endl;

  return 0;
}


Measured memory_bytes: 6428
#include<bits/stdc++.h>
using namespace std;
signed main()
{ 
  vector <double> a;
  double  n,b=0,c;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c;
    a.push_back(c);
  }
  sort(a.begin(),a.end());
  b=a[0];
  for(int i=0;i<n-1;i++){
  b=(b+a[i+1])/2;
  }
  cout<<b<<"\n";
}

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

int main(){
	int count;
	int num1,num2,sum;

	while(1){
		cin >> num1;
		if(cin.eof( ) )break;
		cin >> num2;

		count = 1;
		sum = num1+num2;

		while( (sum / 10) > 0){
			sum /= 10;
			count++;
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 3040
n = gets.to_i
a = gets.split.map(&:to_i)

INF = 10**20
@ans = 0
def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = Array.new(n1+1, 0)
  (0..n1).each do |i|
    l[i] = a[left+i]
  end
  r = Array.new(n2+1, 0)
  (0..n2).each do |i|
    r[i] = a[mid+i]
  end
  l[n1] = INF
  r[n2] = INF
  i = 0
  j = 0
  (left..right-1).each do |k|
    if l[i] <= r[j]
      a[k] = l[i]
      i += 1
    else
      a[k] = r[j]
      j += 1
    end
    @ans += 1
  end
end

def mergeSort(a, left, right)
  if left+1 < right
    mid = (left+right)/2
    mergeSort(a, left ,mid)
    mergeSort(a, mid, right)
    merge(a, left, mid, right)
  end
end

mergeSort(a, 0, n)

puts a.join(" ")
puts @ans


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

int N, M;
double T, A;

int main(){
  cin >> N >> M;
  vector<vector <pair<int, int> > > city;
  city.resize(N+1);
  vector<string> ans(M+1);
  
  for(int i = 1; i <= M; i++){
    int p, y; cin >> p >> y;
    city[p].push_back(make_pair(y, i));
  }
  
  for(int i = 1; i <= N; i++){
    sort(city[i].begin(), city[i].end());
  }
  
  for(int i = 1; i <= N; i++){
    ostringstream ss1;
    ss1 << setw(6) << setfill('0') << i;
    string fst(ss1.str());
    
    for(int j = 1; j <= city[i].size(); j++){
    
      ostringstream ss2;
      ss2 << setw(6) << setfill('0') << j;
      string scd(ss2.str());
      
      ans[city[i][j - 1].second] = (fst + scd);
    }
  }
  for(int i = 1; i <= M; i++){
    cout << ans[i] << endl;
  }
  
}

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

int main(){
	std::vector<int> h(10);
	for(int i=0; i<10; i++)
		std::cin >> h[i];
	std::sort(h.rbegin(), h.rend());
	for(int i=0; i<3; i++)
		std::cout << h[i] << std::endl;
	return 0;
}

Measured memory_bytes: 1196
def gi; gets.split.map(&:to_i); end
H,W=gi

h=Hash.new(0)
$<.read.each_char do |c|
    h[c] += 1 if c != "\n"
end

x1 = (H.odd? && W.odd? ? 1 : 0)
x2 = 0
x2 += H/2 if W.odd?
x2 += W/2 if H.odd?
x4 = (H/2) * (W/2)

vs = h.values
n4 = vs.inject(0) {|n,v|n+=v/4}
n2 = vs.inject(0) {|n,v|n+=v/2} - x4*2
n1 = vs.inject(0) {|n,v|n+=v} - x4*4 - x2*2

if x4<=n4 && x2<=n2 && x1<=n1
    puts 'Yes'
else
    puts 'No'
end

Measured memory_bytes: 14368