akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int R;
        cin >> R;

        double ans = 6.28318530717958623200 * R;
        cout << ans << endl;

//        Int N, M;
//        cin >> N >> M;
//        rep(i, 0, M) {
//            Int tmp;
//            cin >> tmp;
//            N -= tmp;
//        }
//        if (N < 0) cout << -1 << endl;
//        else cout << N << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int det=0;
    string s;
    cin>>s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7') {
        ++det;
    }

    (det)?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
vector <ll> v[200005];
ll ans=0;
ll cnt=0;
bool vis[200005];
void dfs(ll src)
{
	vis[src]=true;
	cnt++;
	for(auto it:v[src])
	{
		if(!vis[it])
		{
			dfs(it);
		}
	}
}

int32_t main() 
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	fastIO;
	ll n,a,b,q,m,c,y,x,i,j,k,arr[200005];
	cin>>n>>m;
	while(m--)
	{
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	memset(vis,false,sizeof(vis));
	for(i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			cnt=0;
			dfs(i);
			ans=max(ans,cnt);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef struct{
  int dt;
  int idx;
}data;


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

  if(sum >= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  
}


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

int accept(int Num, int K, vector<int> &D){
  string s = to_string(Num);
  
  for (int d = 0; d < s.size(); d++){
    for (int i = 0; i < K; i++)
      if ((int)(s.at(d) - '0') == D[i]) return 0;
  }
  
  return 1;
}

int main(){
  int N, K, pay;
  vector<int> D(9, -1);
  
  cin >> N >> K;
  
  for (int i = 0; i < K; i++)
    cin >> D[i];
  
  pay = N;
  while (!(accept(pay, K, D))){
    pay++;
  }
  
  cout << pay;
    
}


Measured memory_bytes: 3656
#include <iostream>
#include <stdio.h>
using namespace std;

bool IsPrime(int n){
  for(int i=2;i*i<=n;i++){
    if(n%i==0) return false;
  }
  return true;
}

int main() {
	int n;
	cin >> n;
	cout << n <<":";
	
	if(IsPrime(n)) cout << " " << n;
	
	else{
		while(IsPrime(n)!=true){
		for(int i=2;i<=n&&n!=1;i++){
			while(n%i == 0){
				if(n%i==0){
					printf(" %d",i);
					n /= i;
				}
			}
		}
	}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3224
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int r; cin >> r;
  cout << 2 * M_PI * r << '\n';
  return 0;
}


Measured memory_bytes: 3800
def main37():
    num = int(input())
    data = input().split()
    retu = []
    for i in range(num):
        retu.append(int(data[i]))
    kari = list(retu)
    kari.sort()
    kosu = 0
    for i in range(num):
        if retu[i] != kari[i]:
            kosu = kosu + 1
    if kosu == 2 or kosu == 0:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main37()

Measured memory_bytes: 3064
fact = [1]
for i in range(20):
    fact.append(fact[-1] * (i+1))

def calc(L):
    NN = 17
    BIT=[0]*(2**NN+1)
    def addbit(i):
        while i <= 2**NN:
            BIT[i] += 1
            i += i & (-i)
    def getsum(i):
        ret = 0
        while i != 0:
            ret += BIT[i]
            i -= i&(-i)
        return ret
    re = 0
    for i, a in enumerate(L[::-1]):
        re += getsum(a) * fact[i]
        addbit(a)
    return re

N = int(input())
P = [int(a) for a in input().split()]
Q = [int(a) for a in input().split()]
 
print(abs(calc(P) - calc(Q)))

Measured memory_bytes: 4084
// #include <iostream>
// int main() {
//   char s[1201];
//   int c = 0;
//   while (true) {
//     scanf("%[^\n]", s);
//     for (int i = 0; s[i] != '\0'; i++) {
//       c += s[i] - '0';
//     }
//     if (c != 0) {
//       printf("%d", c);
//     }
//     break;
//   }
// }

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

int main() {
  while (true) {
    string str;
    cin >> str;
    if (str == "0") break;
    int s = 0;
    for (int i = 0; i < str.size(); i++) {
      s += str[i] - '0';
    }
    cout << s << endl;
  }
  return 0;
}



Measured memory_bytes: 3172
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 10;
long long n, arr[maxn], fpos_sum = 0, fneg_sum = 0, fpos_ans = 0, fneg_ans = 0;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i], fpos_sum += arr[i], fneg_sum += arr[i];
		if (i % 2 == 0) {
			if (fpos_sum <= 0)
				fpos_ans += -fpos_sum + 1, fpos_sum = 1;
			if (fneg_sum >= 0)
				fneg_ans += fneg_sum + 1, fneg_sum = -1;
		} else {
			if (fpos_sum >= 0)
				fpos_ans += fpos_sum + 1, fpos_sum = -1;
			if (fneg_sum <= 0)
				fneg_ans += -fneg_sum + 1, fneg_sum = 1;
		}
		//cout << fpos_ans << ' ' << fneg_ans << '\n';
	}
	//cout << fpos_ans << ' ' << fneg_ans << '\n';
	cout << min(fpos_ans, fneg_ans) << '\n';
	return 0;
}


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

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

typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<long long int> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvll;


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

  vpii v(n-1);
  vvi close(n);
  vi counter(n);
  vi ans(n);

  rep(i, n-1) {
    cin >> v[i].first >> v[i].second;
    v[i].first--;
    v[i].second--;
    close[v[i].first].emplace_back(v[i].second);
    close[v[i].second].emplace_back(v[i].first);
  }

  rep(i, q) {
    int p;
    int x;
    cin >> p >> x;
    p--;
    counter[p] += x;
  }

  vb used(n, false);
  queue<pii> que;
  que.emplace(make_pair(0, 0));

  while(!que.empty()) {
    pii p = que.front();que.pop();
    ans[p.first] = p.second + counter[p.first];

    rep(i, close[p.first].size()) {
      if(used[close[p.first][i]]) continue;
      else que.push(make_pair(close[p.first][i], ans[p.first]));
    }

    used[p.first] = true;
  }

  rep(i, n) cout << ans[i] << endl;

  return 0;
}

Measured memory_bytes: 18676
import sys
from math import pi, cos, sqrt
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    x, n = geta(int)
    p = set(tuple(geta(int)))

    if x not in p:
        print(x)
        return

    x1 = x - 1
    x2 = x + 1

    while True:
        if x1 not in p:
            print(x1)
            return

        if x2 not in p:
            print(x2)
            return

        x1 -= 1
        x2 += 1


if __name__ == "__main__":
    main()

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

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

# strlist = "abcdefghijklmnopqrstuvwxyz"
b = input()

AT = set(["A","T"])
CG = set(["C","G"])
if b in AT:
    ans = AT - set(b)
else:
    ans = CG -set(b)

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


Measured memory_bytes: 2940
from statistics import mean, median,variance,stdev
import sys
import math

x = input().split()
#y = input().split()
a = []
#for i in range(len(x)):
#   a.append(int(x[i]))

p  = [x[0][0],x[1][0],x[2][0]]

print(''.join(p))


Measured memory_bytes: 5148
#include <stdio.h>
#include <math.h>
#define Boolean int
#define TRUE 1
#define FALSE 0

Boolean prime(int n){
	int i;

	if(n < 2) return FALSE;
	if(n == 2) return TRUE;
	if(n % 2 == 0) return FALSE;

	for(i = 3;i <= sqrt(n);i += 2){
		if(n % i == 0) return FALSE;
	}
	return TRUE;
}

int main(void){
	int N,n,cnt = 0;

	scanf("%d", &N);

	while(N--){
		scanf("%d", &n);
		if(prime(n)){
			//printf("prime:%d\n", n);
			cnt++;
		}
	}
	printf("%d\n", cnt);

	return 0;
}

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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) cout << k << endl;
    else if (k <= a + b) cout << a << endl;
    else cout << a + (a + b - k) << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#define N 100000

typedef struct{
  char n[10];
  int q;
}Data;


int main(){
  int n,q,i,j,head=0,tail,sum=0;
  Data data[N];

  scanf("%d%d",&n,&q);

  for(i=0;i<n;i++){
    scanf("%s%d",&data[i].n,&data[i].q);
  }

  head=0;
  tail=n;
  while(1){
    data[head].q-=q;
    sum+=q;
    if(data[head].q<=0){
      printf("%s %d\n",data[head].n,data[head].q+sum);
      sum+=data[head].q;
    }
    else {
      data[tail]=data[head];
      tail++;
    }
    head++;
if(head==tail)break;
    if(head>=N)head=0;
    if(tail>=N)tail=0;
  }
  return 0;
}

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

int main(){
	int a,b,s,i,n;
	while(cin >> a >> b){
			
	n=0;
	s=a+b;
	while(s!=0){
	s/=10;
	n++;
	}
	cout << n << endl;
	}
	return 0;
}




Measured memory_bytes: 2972
n = int(input())
a = list(map(int, input().split()))

di = {}
for i in a:
    if i not in di:
        di[i] = 1
    else:
        di[i] += 1

m=0
for i in di:
    m+=di[i]*(di[i]-1) // 2

for i in a:
    print(m-di[i]+1)

Measured memory_bytes: 26268
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M, X[101010];
vector<int> S[101010];

pair<int, int> trans(vector<int> &V)
{
	sort(V.begin(), V.end());

	int evepair = 0, odds = 0;

	int con = 0;
	for (int i = 0; i < V.size(); ++i) {
		++con;
		if (i == V.size() - 1 || V[i] != V[i + 1]) {
			evepair += con / 2;
			odds += con % 2;
			con = 0;
		}
	}
	return{ evepair, odds };
}

int solve(vector<int> &A, vector<int> &B)
{
	auto p = trans(A);
	auto q = trans(B);

	int ret = 0;
	ret += min(p.second, q.second);
	p.second -= ret;
	q.second -= ret;
	if (p.second == 0) swap(p, q);

	int oddp = min(p.second, q.first * 2);
	return ret + oddp + p.first + (q.first * 2 - oddp) / 2;
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) {
		scanf("%d", X + i);

		S[X[i] % M].push_back(X[i]);
	}

	int ret = 0;
	for (int i = 0; i < M; ++i) {
		int comp = (M - i) % M;
		if (i <= comp) {
			if (i == comp) ret += S[i].size() / 2;
			else ret += solve(S[i], S[comp]);
		}
	}
	printf("%d\n", ret);
	return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,t;
	cin>>n>>t;
	pair<int , int > a[n];
	for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
	
	sort(a, a+n);
	int dp[t];
	memset(dp, 0, sizeof dp);
	int best=0;
	for(int i=0;i<n;i++)
	{	best=max(best, dp[t-1]+a[i].second);
		
		for(int j=t-1;j>=a[i].first;j--)
		dp[j]=max(dp[j], dp[j-a[i].first]+a[i].second);
		
		
		
	}
	cout<<best;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007LL
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
 
 
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int,int> ii;

ll power(ll a, ll b){
    int ans = 1;
    while(b){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
 

int main(){
	fastio;

    int n; cin>>n;
    vector<ll> v(n);
    vector<ll> p(n);
    FOR(i,0,n) cin>>v[i];
    p[0]=v[0];
    FOR(i,1,n) p[i]=p[i-1]+v[i];
    
    
    int x, y, z;
    ll ans, ans_=1e15;
    FOR(i,1,n-2){
        int pos=lower_bound(all(p),(p[i]+1)/2)-p.begin();
        if(pos-1>=0 && abs(2LL*p[pos]-p[i])>abs(2LL*p[pos-1]-p[i])) x=pos-1;
        else x=pos;
        pos=lower_bound(all(p), p[i]+(p[n-1]-p[i]+1)/2)-p.begin();
        ll xd=p[pos]-p[i], xdd=p[pos-1]-p[i];
        if(pos-1> i && abs(xd-p[n-1]+p[pos])>abs(xdd-p[n-1]+p[pos-1])) z=pos-1;
        else z=pos;
        
        ll sum1=p[x], sum2=p[i]-p[x], sum3=p[z]-p[i] ,sum4=p[n-1]-p[z];
        ans=max({abs(sum1-sum2), abs(sum1-sum3), abs(sum1-sum4), abs(sum2-sum3), abs(sum2-sum4), abs(sum3-sum4)});
        // cout<<"ans="<<ans<<endl;
        // cout<<x<<" "<<i<<" "<<z<<endl;
        ans_=min(ans, ans_);
    }

    cout<<ans_<<endl;

	return 0;
}

Measured memory_bytes: 6348
n = int(input())
cnt = 0
memo = [[0] * 10 for i in range(10)]
for i in range(1, n + 1):
    memo[int(str(i)[0])][int(str(i)[-1])] += 1
for i in range(10):
    for j in range(10):
        cnt += memo[i][j] * memo[j][i]
print(cnt)

Measured memory_bytes: 40428
#include <bits/stdc++.h>
using namespace std;
#define int       long long
#define w(x)      int x;cin >> x;while (x--)
#define rep(d,a,n)  for(int d=a;d<=n;d++)
#define rep_(d,a,n)  for(int d=a;d>=n;d--)
#define nl        "\n" 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define oj  freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
const int inf=1e18;
int gcd(int a,int b,int temp){
    if(temp==1){
        return 1;
    }else if(a%temp==0 && b%temp==0){
        return temp;
    }
    temp-=max(a%temp,b%temp);
    return gcd(a,b,temp);
}

void fun(){
    int n;cin>>n;
    int *p=new int[n];
    int check=0;
    rep(i,0,n-1){
        cin>>p[i];
        check=check^p[i];
    }
    rep(i,0,n-1){
        cout<<(check^p[i])<<" ";
    }

}
int32_t main()
{
    
    fast_io;
    fun();
    return 0;
}


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;

    cout << n * (n - 1) / 2 - n / 2 << endl;
    for (i64 a = 1; a + 1 <= n; a++) {
        for (i64 b = a + 1; b <= n; b++) {
            if (a + b == n + (n % 2 == 0)) continue;
            cout << a << " " << b << endl;
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int k,t;
  cin >> k >> t;
  int MA = 0;
  rep(i,t){
    int a;
    cin >> a;
    MA = max(MA,a);
  }
  if((MA - 1) > (k-MA)){
    cout << (MA-1) - (k-MA) << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
// #include <chrono>
#include <numeric>

using namespace std;
// using namespace std::chrono;

typedef long long int lo;
#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0);
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9
#define N (lo)1e5 * 5
#define all(x) (x).begin(), (x).end()
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
#define si pair<string,lo>
#define vi vector <lo> 
#define vii vector <ii> 

void solve(){
    string s;
    cin >> s;
    for(lo i = 0 ; i < s.size() ; i++){
        if(s[i] == '7'){
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
    return;
}
    
int main() {

    #ifndef ONLINE_JUDGE
        // freopen("soru.gir", "r", stdin);
        // freopen("soru.cik", "w", stdout);
    #endif
    
    fast
    
    // auto start = high_resolution_clock::now();

    lo p = 0;

    if(p){
        lo t;
        cin >> t;
        while(t--)
            solve();
    }
    else{
        solve();
    }

    // auto stop = high_resolution_clock::now();
    // auto duration = duration_cast<microseconds>(stop - start);
    
    // #ifndef ONLINE_JUDGE
    //     cout << "Elapsed time is " << duration.count() << " microseconds." << endl;
    // #endif
    
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long

using namespace std;

const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	ll n;


	
	cin >> n;
	ll sum = n*(n-1)/2;

	ce(sum);


}

int main()
{

	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

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

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
	return x * f;
}

const int N = 110;
int a[N], sum[N];

int main() {
	int n = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	for (int i = 1; i <= n; i++) {
		sum[i] = sum[i - 1] + a[i];
	}
	int ans = 1e9;
	for (int T = 1; T < n; T++) {
		int sum0 = 0;
		for (int i = 1; i <= n; i++) {
			if (i <= T) sum0 += a[i];
			else break; 
		}
		ans = min(ans, abs(sum[n] - sum0 - sum0));
	//	printf("%d\n", ans);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

int main() {

    string S;
    cin >> S;

    vector<int> nums;

    for (int i = 0; i < S.size() - 2; ++i) {
        string str = S.substr(i, 3);
        int num = atoi(str.c_str());
        nums.push_back(abs(753 - num));
    }

    int min = *std::min_element(nums.begin(), nums.end());
    cout << min << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



ll n, h, d;
ll dp[maxn];
ll acc[maxn];

ll fac[maxn];
ll facSum;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n>>h>>d;
    fac[0]=1;
    for (int i=1; i<=n; i++) {
	fac[i]=1ll*i*fac[i-1]%mod;
	facSum += fac[i];
	facSum %= mod;
    }


    dp[0] = fac[n];
    acc[0] = dp[0];
    for (ll i=1; i<=h; i++) {
	dp[i] += acc[i-1];
	if (i-1-d>=0) {
	    dp[i] += (mod-acc[i-1-d]);
	}
	dp[i] %= mod;
	if (i<h) {
	    dp[i] *= facSum;
	    dp[i] %= mod;
	}
	acc[i]=(acc[i-1]+dp[i])%mod;
    }


    cout<<dp[h]<<endl;    
    return 0;
}


Measured memory_bytes: 27080
from collections import deque

s = deque(input())
q = int(input())
flip = 0
for _ in range(q):
    com, *query = input().split()
    if com == "1":
        flip ^= 1
    else:
        f, c = query
        f = int(f)-1
        if f ^ flip == 1:
            s.append(c)
        else:
            s.appendleft(c)
s = "".join(s)
print(s if not flip else s[::-1])


Measured memory_bytes: 8692
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n; cin>>n;
    map<string,ll>mp;
    rep(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    ll ans=0;
    for(auto p:mp){
        ans++;
    }
    cout<<ans<<endl;
}





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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define repN_1(i, n) for(int i = 0; i < (int)(n - 1); i++)
#define repM(i, n) for(int i = (int)(n - 1); i >= 0; i--)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	int N;
	bool flag = false;

	cin >> N;

	rep(i, 10) {
		rep(j, 10) {
			if (i * j == N) {
				flag = true;
				break;
			}
		}
		if (flag)
			break;
	}

	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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


//INT_MAX	2,147,483,647 = 2*1.0e9

const ll MOD = 1000000007;
const ll nMax = 100050;


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

  int a[nMax];
  rep(i, M) cin >> a[i];


  ll dp[nMax];
  rep(i, nMax) dp[i] = 0;
  dp[0] = 1;

  int pos = 0;
  for(int i = 0; i < N; i++){
    if((i+1) != a[pos]){
      dp[i+1] += dp[i];
      dp[i+1] %= MOD;
    }

    if((pos+1) < M){
      if((i+2) != a[pos] && (i+2) != a[pos+1]){
        dp[i+2] += dp[i];
        dp[i+2] %= MOD;
      }
    } else {
      if((i+2) != a[pos]){
        dp[i+2] += dp[i];
        dp[i+2] %= MOD;
      }
    }
    if((i+1) == a[pos] && pos < M-1) pos += 1;
  }

  cout << dp[N] << endl;

  return 0;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,X[200001],Y[200001];
    cin>>n;
    rep(i,n) cin>>X[i],Y[i]=X[i];
    sort(Y,Y+n);
    rep(i,n){
        if(X[i]>=Y[n/2]) cout<<Y[n/2-1]<<endl;
        else cout<<Y[n/2]<<endl;
    }
}

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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, M;
int a[100000];
bool merged[100000] = {};
bool used[100000] = {};
vector<int> G[100000];

signed main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    if (N == 1 || M == N - 1) {
        cout << 0 << endl;
        return 0;
    }
    if (N == 2 && M == 0) {
        cout << a[0] + a[1] << endl;
        return 0;
    }
    if (M == 0) {
        cout << "Impossible" << endl;
        return 0;
    }
    int ans = 0;
    int sets = 0;
    for (int i = 0; i < N; i++) {
        if (!merged[i]) {
            stack<int> stk;
            stk.push(i);
            merged[i] = true;
            int cand = i;
            while (!stk.empty()) {
                int n = stk.top();
                stk.pop();
                for (int j = 0; j < G[n].size(); j++) {
                    if (!merged[G[n][j]]) {
                        stk.push(G[n][j]);
                        if (a[cand] > a[G[n][j]]) {
                            cand = G[n][j];
                        }
                        merged[G[n][j]] = true;
                    }
                }
            }
            ans += a[cand];
            used[cand] = true;
            sets++;
        }
    }
    auto c = [](int l, int r) {
            return a[l] > a[r];
        };
    priority_queue<int, std::vector<int>, decltype(c)> pq(c);
    for (int i = 0; i < N; i++) {
        if (!used[i]) {
            pq.push(i);
        }
    }
    for (int i = 0; i < sets - 2; i++) {
        if (pq.empty()) {
            cout << "Impossible" << endl;
            return 0;
        }
        ans += a[pq.top()];
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8316
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(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 trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


 int ans1,ans2;



int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    
    string s,t;
    cin >> s >> t;

    if(s.size() > t.size())
    {
      cout << "GREATER";
      return 0;
    }
    if(s.size() < t.size())
    {
      cout << "LESS";
      return 0;
    }

    for(int i = 0; i < s.size(); i++)
    {
      if(s[i] != t[i])
      {

    if(s[i] > t[i] )
    {
      cout << "GREATER";
      return 0;
    }
    if(s[i] < t[i] )
    {
      cout << "LESS";
      return 0;
    }
      }
    }

    cout << "EQUAL";




    return 0;   
}


Measured memory_bytes: 3596
from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = deque()
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat.append((h, w, 0))
    dp[h] = s

def search(dp, mat, nH, nW, cnt):
    if dp[nH][nW] == ".":
        mat.append((nH, nW, cnt+1))
        dp[nH][nW] = "#"

while len(mat):
    h, w, cnt = mat.popleft()

    if h > 0:
        search(dp, mat, h - 1, w, cnt)
    if h < H-1:
        search(dp, mat, h + 1, w, cnt)
    if w > 0:
        search(dp, mat, h , w - 1, cnt)
    if w < W-1:
        search(dp, mat, h , w + 1, cnt)

print(cnt)


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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<double,double>
#define PLD pair<long double, long double>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const int N = 300555;
const int M = 1155;

void solve() {
    ll h,w;
    cin >> h >> w;

    if (h == 1 || w == 1){
        cout << 1;
        return;
    }

    cout << (h*w+1)/2;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  int n = 0;
  cin >> s >> t;
  size_t size = s.length();
  for(int i=0; i<size; i++){
    if(s[i] != t[i]){
      n++;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;

int main(){
  int n,m;
  cin>>n>>m;
  int ans;
  pair<int,int> a[100000];
  int x,y,z;
  int p[100010];
  int h[100010];
  rep(i,100010) p[i]=0,h[i]=0;
  rep(i,m){
    cin>>x>>y>>z;
    if(x>y) swap(x,y);
    a[i]=make_pair(x,y);
  }
  ans=n;
  int cc=1,dd=0;
  rep(i,m){
    int aa=a[i].first,bb=a[i].second;
    while(p[aa]!=0) aa=p[aa];
    while(p[bb]!=0) bb=p[bb];
    if(aa==bb) continue;
    if(h[aa]>=h[bb]){
      p[bb]=aa;
      h[aa]++;
      h[bb]=0;
      ans--;
    }
    else{
      p[aa]=bb;
      h[bb]++;
      h[aa]=0;
      ans--;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 1792
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B,K;
	while(cin>>A>>B>>K) {
		set<ll> s;
		RANGE(i, A, min(B+1, A+K)) s.insert(i);
		RANGE(i, max(A, B-K+1), B+1) s.insert(i);
		for(auto e: s) cout<<e<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define len(s) s.length()
#define forp(i,a,b) for( i=a;i<=b;i++)
#define rep(i,n)    for( i=0;i<n;i++)
#define ren(i,n)    for( i=n-1;i>=0;i--)
#define forn(i,a,b) for( i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define b(v) v.begin()
#define e(v) v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vii vector<int>
#define vll vector<long long>
#define gl(cin,s)  getline(cin,s);
#define bitc(n) __builtin_popcountll(n)
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define SIZE 1010
#define SZ 1010

typedef long long  ll;
typedef unsigned long long ull;
typedef long double  ldo;
typedef double  db ;
using namespace std;
int N,M;
int dp[SIZE][SIZE];
char ch[SIZE][SIZE];
int main()
{  	
	/* #ifndef ONLINE_JUDGE
	freopen(fi, "r", stdin);
	#endif */
	//freopen("route.in","r",stdin);
	//freopen("route.out","w",stdout);
	//cin.ignore();
	//cin.clear();
	boost;
	//cin.tie(0);
	//cout<<"Case "<<tt<<": ";
	cin>>N>>M;
	for(int i=0;i<SZ;i++){
	    for(int j=0;j<SZ;j++){
	        ch[i][j] = '#';
	    }
	}
	for(int i=1;i<=N;i++){
	    for(int j=1;j<=M;j++){
	        cin>>ch[i][j];
	    }
	}
	dp[1][1] = 1;
	for(int i=1;i<=N;i++){
	    for(int j=1;j<=M;j++){
	        if(i == 1 and j == 1)
	        continue;
	        if(ch[i][j] == '.'){
	            dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
	        }
	    }
	}
	cout<<dp[N][M]<<endl;
	return 0;
}

Measured memory_bytes: 5248
s=input()
s_idx=0
e_idx=0
for i in range(len(s)):
    if s[i]=='A':
        s_idx=i
        break
for i in range(len(s)-1,0,-1):
    if s[i]=='Z':
        e_idx=i
        break
print(e_idx-s_idx+1)

Measured memory_bytes: 3516
#include<bits/stdc++.h>                          
using namespace std;
long long n,k,x;
int main(){
    cin>>n>>k;
    x=n%k;
    cout<<min(k-x,x);
	return 0;
}
//68871358
//76140264
//25446011
//200841159
//914174775

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
using namespace std;
int n;
int size;
vector<int> list;
void init(){
  n=0;
  list.clear();
}

bool input(){
  cin>>n;
  size=0;
  list.resize(n);
  if(n==0)return false;
  return true;
}


void rec(int n){
  if(n==0){
    for(int i=0;i<size-1;i++){
      cout<<list[i]<<" ";
    } cout<<list[size-1]<<endl;
  }else{
    for(int i=n;i>0;i--){
      if(size!=0&&(list[size-1]<i))continue;
      list[size]=i;
      size++;
      rec(n-i);
      size--;
    }
  }
}

void solve(){
  rec(n);
}

int main(){
  while(init(),input()){
    solve();
  }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

bool isPrime(int n){
    for(int i=2; i*i<=n; i++){
        if(n%i == 0) return false;
    }
    return true;
}

bool is2017like(int n){
    if(n%2 == 1 && isPrime(n) && isPrime((n+1)/2)) return true;
    else return false;
}

int main(){
    vector<int> cnt(100001, 0);
    for(int i=2; i<=100000; i++){
        if(is2017like(i)) cnt[i] = cnt[i-1]+1;
        else cnt[i] = cnt[i-1];
    }

    int q; cin >> q;
    for(int i=0; i<q; i++){
        int l, r; cin >> l >> r;
        cout << cnt[r] - cnt[l-1] << endl;
    }
}

Measured memory_bytes: 1024
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, x] <- getIntList
    ls <- getIntList
    print . length . filter (<= x) $ scanl (+) 0 ls

Measured memory_bytes: 508
#include<algorithm>
#include<bitset>
#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int N=2000;
const int inf=1e8;
typedef bitset<N> bs;

bs shl(const bs &x,int n,int c){
  bs y(x<<c);
  if(c>0)
    y|=x>>(n-c);
  y^=y>>n<<n;
  return y;
}

bs to_bitset(const string &a){
  bs ret;
  rep(i,a.length()){
    ret[i]=a[i]=='1';
  }
  return ret;
}

int f(const string &a,const string &b){
  int n=a.length();
  vector<bs> shift(n);
  bs ab=to_bitset(a),bb=to_bitset(b);
  rep(i,n){
    shift[i]=shl(bb,n,i)^ab;
  }
  if(!bb.any()){
    return ab.any()?1e8:0;
  }
  int ans=inf;
  // full
  {
    int mi=inf;
    rep(i,n){
      mi=min(mi,(int)shift[i].count()+min(i,n-i));
    }
    ans=min(ans,mi+n);
  }
  vector<bs>poss_neg(n);
  poss_neg[0]=bb;
  rep(i,n-1){
    poss_neg[i+1]=poss_neg[i]|shl(bb,n,n-i-1);
  }
  vector<bs>poss_pos(n);
  poss_pos[0]=bb;
  rep(i,n-1){
    poss_pos[i+1]=poss_pos[i]|shl(bb,n,i+1);
  }
  // O(n^2 * N/64)
  for(int k=-n+1;k<=n-1;++k){
    int imi=k<0?-k:0;
    int ima=k<0?n-1:n-k-1;
    int del=k<0?k+n:k;
    int bc=shift[del].count();
    int prev=n;
    for(int i=imi;i<=ima;++i){
      int p=min(prev,n-i-1),llim=max(0,k);
      while(p>=llim){
	bs poss=poss_neg[i]|poss_pos[p];
	if((shift[del]|poss)==poss){
	  p--;
	}else{
	  break;
	}
      }
      p++;
      if(p<n-i)
	ans=min(ans,2*i+2*p-abs(k)+bc);
      prev=p;
    }
  }
  return ans;
}

int main(){
  string a,b;
  cin>>a>>b;
  int ans=f(a,b);
  cout<<(ans>=inf?-1:ans)<<endl;
}


Measured memory_bytes: 1792
// #include <bits/stdc++.h>
 
// using namespace std;
 
// int main() {
    // long long int N;
    // cin >> N;
    // long long int times[5];
    // long long int capacity[5];
 
    // for(int i = 0; i < 5; i++)
    // {
        // cin >> capacity[i];
    // }
 
    // times[0] = ceil((double)N / (double)capacity[0]);
    // for(int i = 1; i < 5; i++)
    // {
        // times[i] = ceil((double)N / (double)capacity[i]);
    // }
 
    // for (int i = 4; i >= 1; i--)
    // {
        // if (times[i] <= times[i - 1])
        // {
            // times[i] = 1;
        // } else {
            // times[i] = times[i] - times[i - 1] + 1;
        // }
    // }
 
    // long long int ans = 0;
    // for (int i = 0; i < 5; i++)
    // {
        // ans += times[i];
    // }
 
    // cout << ans;
// }

#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    long long N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
    return 0;
}


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

#define ARC(i, a, b) for(int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T &anth(T &a, const T &b){ return a = ant(a, b); }
template<class T> T &onth(T &a, const T &b){ return a = ont(a, b); }

char ans[4][10] = {"NA", "MMYY", "YYMM", "AMBIGUOUS"};

int judge(int n){
	if(n == 0) return 0;
	if(n > 12) return 0;
	return 1;
}

int main(){
	int a = 0;
	char s[10];
	fgets(s, sizeof s, stdin);
	RC(i, 4) s[i] -= '0';
	a |= judge(s[0] * 10 + s[1]);
	a |= judge(s[2] * 10 + s[3]) << 1;
	printf("%s\n", ans[a]);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a;
    int t=0;
    cin>>a;
   for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(a==i*j)
                t=1;
        }
   }
   if(t==1)
    cout<<"Yes";
   else
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	ll sum = 0;
	rep2(i, k, n + 2) {
		sum += i * (n - i + 1) + 1;
		sum %= MOD;
	}
	cout << sum;
}

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

int main(){
    string S;
    cin >> S;
    int count = 0;
    
    for(int i=0;i<S.size();i++){
        if(S[i] != S[S.size()-1-i] && i <= S.size()-1-i){
            count++;
        }
    }
    cout << count;
    return 0;
}

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

def check(m):
  return sum([ (a+m-1)//m  - 1 for a in A ]) <= K

def main():
  l = 0
  r = max(A)
  
  while l + 1 < r:
    m = (l + r) // 2
    is_over = check(m)
    
    if is_over:
      r = m
    else:
      l = m
  return  r
  
print(main())

Measured memory_bytes: 30880