akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
int main() {
  int N; cin>>N; ll C; cin>>C;
  ll ans = 0;
  vector<ll> x(N+2,0LL), v(N+2,0LL);
  vector<ll> ord(N+2), rev(N+2);
  REP(i,N) cin>>x[i+1]>>v[i+1];
  x[N+1] = C;
  ll work = 0LL;
  for(int i = 1; i <= N; i++) {
    work += (v[i]-(x[i]-x[i-1]));
    ans = max(ans, work);
    ord[i] = ans;
    //    cout << ord[i] << endl;                                                       
  }
  ll tmp = 0LL;
  work = 0LL;
  for(int i = N; i >= 1; i--) {
    work += (v[i]-(x[i+1]-x[i]));
    //    cout << i << " " << work << endl;                                             
    tmp = max(tmp, work);
    rev[i] = tmp;
    //    cout << rev[i] << endl;                                                       
  }
  ans =	max(ans, tmp);
  for(int via = 1; via < N; via++) {
    work = ord[via]+rev[via+1]-x[via];
    ans = max(ans, work);
  }

  for(int via =	N; via > 1; via--) {
    work = rev[via]+ord[via-1]-(C-x[via]);
    ans = max(ans, work);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

ull a;
double b;

int main()
{
  ull ans;
  ll bi;

  cin >> a >> b;

  b = b*100+0.5;
  bi = b;
  
  ans = a*bi/100;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include<set>
#include<cassert>
#include<cmath>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<lint,lint>pll;

// 連分数を使って、基本単数を求める。d は平方数でないことが要請される。
pll fundamental_unit(lint d){
  vi ans;
  lint x=0,z=1;//(x+sqrt(d))/z
  lint sqrtd=floor(sqrt(d));
  set<pll>seen;
  // invariants: x>=0, z|x*x-d
  while(1){
    if(seen.count(pll(x,z)))break;
    seen.insert(pll(x,z));
    lint q=(x+sqrtd)/z;
    ans.push_back(q);
    x=q*z-x;
    lint norm=x*x-d;
    z=-norm/z;
  }
  // recover
  lint num=0,den=1;
  for(int i=(int)ans.size()-2;i>=0;--i){
    lint z=num+ans[i]*den;
    num=den;den=z;
  }
  if(den*den-d*num*num==-1){
    lint x=den*den+d*num*num;
    lint y=2*den*num;
    den=x;num=y;
  }
  assert(den*den-d*num*num==1);
  return pll(den,num);
}

pll solve(lint n){
  for(int i=0;i<=200;++i)
    if(i*i==2*n)
      return pll(i,1);
  return fundamental_unit(2*n);
}

int main(){
  for(int t=1;;++t){
    lint n;
    cin>>n;
    if(n==0)break;
    pll ans=solve(n);
    cout<<"Case "<<t<<": "<<ans.first<<" "<<ans.second<<endl;
  }
}



Measured memory_bytes: 3076
import math

n, x = map(int, input().split())
lis = list(map(int, input().split()))

nlis = []

for i in range(n):
    nlis.append(abs(lis[i]- x))

ans = nlis[0]

for j in range(1, n):
    ans = math.gcd(ans, nlis[j])

print(ans)

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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debp(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)

int32_t main() { fastio;
	int n, k;
	cin >> n >> k;
	vector<int> arr(n + 1);
	for (int i = 0; i <= n; i++) {
		arr[i] = i;
	}
	int left = 0, right = 0;
	for (int i = 0; i < k; i++) {
		left += arr[i];
	}
	for (int i = n; i > n - k; i--) {
		right += arr[i];
	}
	int res = right - left + 1;
	int low = k, high = n - k;
	while (low <= n) {
		left += arr[low++];
		right += arr[high--];
		res = (res + right - left + 1 + HELL) % HELL;
	}
	cout << res << endl;
 	return 0;
}


Measured memory_bytes: 4784
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>


using namespace std;


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

    bool ok = false;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == '7') {
            ok = true;
            break;
        }
    }

    if(ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }



    return 0;

}

Measured memory_bytes: 3576
#include <stdio.h>
#include <string.h>


int main(void)
{
	char a[101],b[101];
	scanf("%s%s",a,b);
	int lena,lenb,len;
	lena=strlen(a);
	lenb=strlen(b);
	if(lena>lenb){printf("GREATER");}
	else if(lena<lenb){printf("LESS");}
		
	fprintf(stderr,"A=%s\nB=%s\n",a,b);	/* case:lena=lenb */
	int i;
	if(a != b && lena==lenb)
	{
	for(i=0;i<=lena-1;i++)
		{
		if(a[i]>b[i]){printf("GREATER"); break;}
		else if(a[i]<b[i]){printf("LESS"); break;}
		if(i==lena-1 && a[i]==b[i]){printf("EQUAL");}
		}
	}

	return 0;
}





Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 INF = 1LL << 40;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N, Z, W;
  cin >> N >> Z >> W;
  vector<i64> A(N);
  REP(i, N) cin >> A[i];

  i64 res = abs(A[N - 1] - W);
  if (N > 1) {
    res = max(res, abs(A[N - 1] - A[N - 2]));
  }
  cout << res << endl;
}


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

using namespace std;
#define ll  long long
#define ld  long double

#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;

int freq[26];
bool vis[26];
int main()
{
int n,k;
cin>>n>>k;
int arr[n];
for(int i=0;i<n;i++)
    cin>>arr[i];
    sort(arr,arr+n);
    ll sum=0;
    for(int i=n-1;i>=(n-k);i--)
        sum+=arr[i];
        cout<<sum<<endl;


    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> p(n),q(n);
    for(int i = 0; i < n; i++)cin >> p[i];
    for(int i = 0; i < n; i++)cin >> q[i];
    vector<int> a(n);
    for(int i = 0; i < n; i++)a[i] = i + 1;
    map<vector<int>, int> mp;
    do{ 
        mp[a] = mp.size();
    }while(next_permutation(a.begin(),a.end()));
    int ans = abs(mp[p] - mp[q]);
    cout << ans << endl;
}

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

int main(){
  
  int N;
  cin >> N;
  
  if (N % 2 == 0){
    
    cout << N / 2 << endl;
    return 0;
  } else {
    cout << N / 2 + 1 << endl;
    return 0;
  }    
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String str1 = sc.next();
            String str2 = sc.next();
            if("H".equals(str1) && "H".equals(str2) || "D".equals(str1) && "D".equals(str2)){
              System.out.println("H");
            } else {
              System.out.println("D");
            }
            }
}

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

typedef struct {
    int x;
    int y;
} Point;

int main (void) {
    Point   a, b;
    int     dx, dy;

    scanf("%d%d%d%d", &a.x, &a.y, &b.x, &b.y);

    dx = b.x - a.x;
    dy = b.y - a.y;
    printf("%d %d %d %d\n",
           b.x-dy, b.y+dx, a.x-dy, a.y+dx);

    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
int main()
{
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if(e-a <= k){
    cout << "Yay!";
  }else{
    cout << ":(";
  }
 
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int A,B;
    cin >> A >> B;
    
    int C = 1;
    int cont = 0;
    while(true){
        if(C>=B)break;
        C += A-1;

        //cout << C << endl;
        cont++;
        
        
    }
    cout << cont << endl;
}


Measured memory_bytes: 256
K, S = map(int, input().split())
count = 0
for a in range(K+1):
    for b in range(K+1):
        # **3の全探索は間に合わないため、S-a-bの値が0からKの間である組を数えれば良い。
        # for c in range(K+1):
        #     if a+b+c == S:
        c = S - a - b
        if 0<=c<=K:
            count += 1
print (count)

Measured memory_bytes: 2940
N = gets.to_i

cand = []
0.upto(N) do |t|
  cnt = 0
  i = t
  while i > 0
    cnt += i % 6
    i /= 6
  end
  j = N - t
  while j > 0
    cnt += j % 9
    j /= 9
  end
  cand.push(cnt)
end

puts cand.min

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

int	main()
{
	int	N, X;
	cin >> N >> X;
	int	m;
	cin >> m;
	int	min_m = m, sum_m = m;
	for (int i = 1; i < N; ++i) {
		cin >> m;
		sum_m += m;
		if (min_m > m) min_m = m;
	}
	cout << (X - sum_m) / min_m + N << endl;
}


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

using namespace std;
typedef long long int lli;
typedef vector<int> iv;
typedef vector<bool> bv;
typedef vector<string> sv;
typedef vector<long long int> llv;
typedef vector<double> dv;

#define sor_(vec) sort(vec.begin(),vec.end())
#define rev_(vec) reverse(vec.begin(),vec.end())
#define rep(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define reps(i,n,s) for(int i=static_cast<int>(s);i<static_cast<int>(n);i++)
#define isposi(num) if(num>0)
const long long mod = 1000000007;

void printm(char const *format,...){
    va_list arguments;
    va_start(arguments,format);
    unsigned index=0;
    while (format[index]!='\0') {
        if(format[index]=='%'){
            index++;
            if(format[index]=='d')printf("%d",va_arg(arguments, int));
            else if(format[index]=='c')printf("%c",va_arg(arguments, int));
            else if(format[index]=='x')printf("%x",va_arg(arguments,int));
            else if(format[index]=='o')printf("%o",va_arg(arguments,int));
            else if(format[index]=='f')printf("%f",va_arg(arguments, double));
            else if(format[index]=='s')printf("%s",va_arg(arguments, char const *));
            else if(format[index]=='p')printf("%p",va_arg(arguments,void*));
            else if(format[index]=='y')printf("Yes");
            else if(format[index]=='n')printf("No");
            else if(format[index]=='%')printf("%%");
            else assert(!"Unknown format with %.");
        }
        else printf("%c",format[index]);
        index++;
    }
    va_end(arguments);
    return;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    unsigned n,m,buf,all=0;
    std::vector<int>c;
    std::cin>>n>>m;
    for(size_t i = 0;i<n;i++){
        std::cin>>buf;
        all+=buf;
        c.push_back(buf);
    }
    std::sort(c.begin(),c.end(),std::greater<unsigned>());
    if(c[m-1]<all*(double)1/(4*m))printf("No");
    else printf("Yes");
    return 0;
}


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

using namespace std;

const int N = 1e3+7;

int h, w, a, b;
int r[N], c[N];

int main()
{
    cin >> h >> w >> a >> b;
    /*
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            if (r[i] < a && c[j] < b) {
                cout << 0 << " ";
                ++r[i];
                ++c[j];
            } else {
                cout << 1 << " ";
            }
        }
        cout << endl;
    }
    */
    for (int i = 1; i <= b; ++i) {
        for (int j = 1; j <= a; ++j) {
            cout << 0;
        }
        for (int j = a+1; j <= w; ++j) {
            cout << 1;
        }
        cout << endl;
    }
    for (int i = b+1; i <= h; ++i) {
        for (int j = 1; j <= a; ++j) {
            cout << 1;
        }
        for (int j = a+1; j <= w; ++j) {
            cout << 0;
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
  int n,cnt=0;
  cin >> n;
  while (n>=1) {
    if ((n<100000 && n>=10000) || (n<1000 && n >=100) || (n<10 && n>= 1)) cnt++;
    n--;
  }
  cout << cnt << endl;
}

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

sa = 0
sb = 0
for i in range(N):
  if A[i] < B [i]:
    sa += (B[i] - A[i] + 1) // 2
  else:
    sb += A[i] - B[i]
s = sum(B) - sum(A)
if s < 0 or sa > s or sb > s:
  print('No')
  exit()
print('Yes')

Measured memory_bytes: 41584
A,B=map(int,input().split())
maxi = max(A,B)
mid = maxi
mini = min(A,B)
res = 0
if A % B ==0 or B % A ==0:
  res = maxi
while res ==0:
  if maxi % mini == 0:
    res = maxi
  maxi += mid
print(res)

Measured memory_bytes: 9120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int sum = calSumOfDigits(x);

		if(x % sum== 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	//各桁の和を計算
	public static int calSumOfDigits(int n) {
		int sum =0;
		while(n>0) {
			sum += n % 10;
			n /= 10;
		}
		return sum;
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

int main(){

    ll n;
    cin >> n;

    ll ans = LLONG_MAX;

    function<ll(ll)> next = [](ll x) -> ll{

        int digit = 0;
        ll tmp = x;

        while(tmp > 0){
            tmp = tmp /10;
            digit++;
        }

        digit--;

        ll k = 1;

        rep(i,digit) k = k * 10;

        return x % k;
    };

    while(n >= 100){

        ll tmp = n;

        while(tmp >= 1000){
            tmp = tmp / 10;
        }

        ans = min(ans,abs(tmp - 753));

        n = next(n);
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
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-'0'; ch=getchar();} return x*f; }
int n,c,L[100],ps[100],Cnt,Ans; int F[310][40];
inline int solve() {
	memset(F,0,sizeof F); F[n*L[n-1]][0]=1;
	for(int i=0;i<n*c;i++) for(int j=i;j<=n*c;j++) for(int k=0;k<(1<<(n-1));k++) if(i%n&&!((k>>ps[i%n-1])&1)) F[min(c*n,max(j,i+n*L[ps[i%n-1]]))][k|(1<<ps[i%n-1])]+=F[j][k];
	return F[n*c][(1<<(n-1))-1];
}
signed main() {
	n=read(); c=read(); for(int i=0;i<n;i++) L[i]=read(),ps[i]=i; sort(L,L+n);
	while(1) { Cnt++; Ans+=solve(); if(!next_permutation(ps,ps+n-1)) break; }
	for(int i=1;i<n;i++) Cnt*=c; printf("%.12Lf",(long double)1.0*Ans/(Cnt*1.0)); puts("");
	return 0;
}

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

int main(){
    int a=0;
    int b=0;
    int n;
    while(true){
    cin >> n;
    int a=1;
    int b=1;
    if(n==0)return 0;
    int ans=0;
    while(n!=ans){
        if(ans>n){
            ans-=b;
            b++;
        }
        if(ans<n){
            ans+=a;
            a++;
        }
    }
    cout << b << ' ' << a-b << endl;
}
}


Measured memory_bytes: 3096
n = int(input())
m = int(n**0.5)+2
is_prime = [1]*m
is_prime[0] = is_prime[1] = 0
for p in range(2,m):
    for q in range(2*p,m,p):
        is_prime[q] = 0
primes = [p for p, c in enumerate(is_prime) if c]

print(str(n)+': ', end='')
ans = []
for p in primes:
    while n % p == 0:
        ans.append(p)
        n //= p
if n > 1:
    ans.append(n)
print(*ans)


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

typedef long long ll;

int main() {
    ll A, B;
    cin >> A >> B;
    if (A == B) {
        cout << "0\n";
        return 0;
    }
    ll c = A + B;
    if (c % 2 == 0) {
        cout << (c / 2) << "\n";
    } else {
        cout << "IMPOSSIBLE" << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

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

#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define md(l, r) l + (r - l) / 2
#define ll long long
#define btw(a, l, r) a.begin() + l, a.begin() + r + 1
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int(x.size()))
#define sqr(x) (x) * (x)
#define endl '\n'

#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define clr(x, y) memset((x), (y), sizeof (x))
#define ld long double

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<vector<pair<int, int> > > vvpii;
typedef pair<int, pair<int, int> > piii;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef vector<pair<ll, pair<ll, ll> > > vplll;

const ld eps = -1e9;
const long long N = 200001, P = 1e9 + 7, P1 = 1e9 + 13, iINF = INT_MAX, INF = 2e9, K = 73, K1 = 79;

ll dstF(ll x, ll y, ll xx, ll yy) {
    return (sqr(x - xx) + sqr(y - yy));
}

ld dstSqrtF(ll x, ll y, ll xx, ll yy) {
    return (sqrt(sqr(x - xx) + sqr(y - yy)));
}

ll _bp(ll val, ll st, ll p) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2, p);
    temp = sqr(temp);
    temp %= p;
    if (st % 2 == 1) {
        temp *= val;
        temp %= p;
    }
    return temp;
}

ll _bp(ll val, ll st) {
    if (st == 0) {
        return 1;
    }
    ll temp = _bp(val, st / 2);
    temp = sqr(temp);
    if (st % 2 == 1) {
        temp *= val;
    }
    return temp;
}

ll nok(ll a, ll b) {
    return (a / __gcd(a, b) * b);
}

/*
ll fact[N];

void buildFacts(ll n, ll p) {
    fact[0] = 1;
    for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}

ll C(ll n, ll k, ll p = -1) {
    if (p == -1) {
        ll x = fact[n];
        ll y = (fact[k] * fact[n - k]);
        return (x / y);
    } else {
        ll x = fact[n];
        ll y = (fact[k] * fact[n - k]) % p;
        x = (x * _bp(y, p - 2, p)) % p;
        return x;
    }
}
*/

long long k;

void solve() {
    string s, s1;
    cin >> s >> s1;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != s1[i]) {
            k++;
        }
    }
    cout << k;
}

signed main() {
    fast_io;
    int q;
    q = 1;
    //cin >> q;
    while (q != 0) {
        solve();
        --q;
    }
}

/*
adsdads
*/



Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

main()
{
  int N, M;
  int ans = 0;
  cin >> N >> M;

  int tmp = min(N, M/2);  
  ans = tmp;
  N -= tmp;
  M -= tmp * 2;

  ans += M / 4;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	unsigned long X, Y;
	cin >> X >> Y;
	int counter = 0;
	unsigned long num = X;
	while (true) {
		counter++;
		num *= 2;
		if (Y < num) break;
	}
	cout << counter << 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 all(v) v.begin(), v.end()
typedef long long ll;

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x * y / GCD(x, y);
}
int main(){
    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1; i<= x + k -1; i++) cout << i << ' ';
    cout << endl;
}
   

Measured memory_bytes: 256
from itertools import product
n, a, b, c = map(int, input().split())
parts = [int(input()) for _ in range(n)]

usage = [['a', 'b', 'c', '_'] for _ in range(n)]

ans = 1e9
for cmb in product(*usage):
    if not ('a' in cmb and 'b' in cmb and 'c' in cmb):
        continue
    cost_a, cost_b, cost_c = 0, 0, 0
    len_a, len_b, len_c = 0, 0, 0
    for i in range(n):
        if cmb[i] == 'a':
            cost_a += 10 if len_a > 0 else 0
            len_a += parts[i]
        elif cmb[i] == 'b':
            cost_b += 10 if len_b > 0 else 0
            len_b += parts[i]
        elif cmb[i] == 'c':
            cost_c += 10 if len_c > 0 else 0
            len_c += parts[i]
    cost_a += abs(a - len_a)
    cost_b += abs(b - len_b)
    cost_c += abs(c - len_c)
    ans = min(ans, sum((cost_a, cost_b, cost_c)))

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N;
	cin >> N;
	int sum = 0;
	rep( i, 1, N + 1 ){
		int input;
		cin >> input;
		if (input == i){
			sum++;
			if (i == N)
				continue;
			i++;
			cin >> input;
		}
	}
	cout << sum << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main() 
{
    IOS;
    string s;
    cin>>s;
    if(s=="RRR")
        print(3);
    else if(s=="RRS" || s=="SRR")
        print(2);
    else if(s=="RSS" || s=="SRS" || s=="SSR" || s=="RSR")
        print(1);
    else
        print(0);
}

Measured memory_bytes: 3640
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod = 1000000007;
const int inf = 0x3f3f3f3f;
const ll inff = 0x7ffffffffff;
ll read()
{
	ll 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-'0';ch=getchar();}
	return x*f;
}
//head
const int N = 3010;
int n, m, k;
ll g[N][N];
ll f[N][N][4], ans;
int main() {
	n = read(), m = read(); k = read();
	rep(i, 1, k) {
		int x = read(), y = read(); g[x][y] = read();
	}
	rep(i, 1, n) {
		rep(j, 1, m) {
			rep(o, 0, 3) {
				if(g[i][j] && o) f[i][j][o] = max(f[i][j - 1][o - 1] + g[i][j], f[i][j][o]);
				f[i][j][o] = max(f[i][j - 1][o], f[i][j][o]);
				f[i][j][0] = max(f[i][j][0], f[i - 1][j][o]);
				if(g[i][j]) f[i][j][1] = max(f[i][j][1], f[i - 1][j][o] + g[i][j]);
			}
			ans = max(ans, f[i][j][0]);
			ans = max(ans, f[i][j][1]);
			ans = max(ans, f[i][j][2]);
			ans = max(ans, f[i][j][3]);
		}
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 356284
n = int(input())
h = list(map(int, input().split()))
dp = [float("inf")] * (100000+1)

dp[1] = 0
for i in range(1, 100000+1):
    for j in range(1, 3):
        if i + j > n:
            break
        elif dp[i+j] > dp[i] + abs(h[i-1] - h[i+j-1]):
            dp[i+j] = dp[i] + abs(h[i-1] - h[i+j-1])

print(dp[n])

Measured memory_bytes: 13976
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;


int main() {

	string s; cin >> s;

	int l = s.find('A');
	int r = s.rfind('Z');

	cout << r - l + 1 << endl;


}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int x=in.nextInt();
		int ans=0;
		int i;
		for(i=0;i<n;i++)
		{
			int l=in.nextInt();
			ans=ans+l;
			if(ans>x)
			{
				break;
			}
		}
		System.out.println(i+1);
	}
}
	

Measured memory_bytes: 22100
str = input("")
q = int(input())

for i in range(q):
    line = input().split()
    c = line[0]
    a = int(line[1])
    b = int(line[2]) + 1

    if c == 'replace':
        str = str[:a] + line[3] + str[b:]
    elif c == 'reverse':
        str = str[:a] + str[a:b][::-1] + str[b:]
    else:
        print(str[a:b])


Measured memory_bytes: 5616
#include <bits/stdc++.h>
            using namespace std;
            int main()
            {
                int n,k;
                cin>>n>>k;
                int a[n];
                for(int i=0;i<n;i++)
                {
                    cin>>a[i];
                }
                int ans[n]={0};
                ans[0]=0;
                for(int i=1;i<n;i++)
                {
                    ans[i]=INT_MAX;
                    for(int j=1;j<=k;j++)
                    {
                        if(i-j>=0)
                        ans[i]=min(ans[i],ans[i-j]+abs(a[i]-a[i-j]));
                    }
                }
                    cout<<ans[n-1];
                return 0;
            }


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,max,ans;
	cin >> a >> b >> c;

	if(a>=b&&a>=c) {max=a;}
	else if(b>=a&&b>=c) {max=b;}
	else if(c>=a&&c>=b) {max=c;}

	if((3*max)%2==(a+b+c)%2){
		ans=(3*max-(a+b+c))/2;
	}
	else{
		ans=(3*max-(a+b+c-1))/2;
		ans++;
	}

	cout << ans << endl;	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 100010
#define PI 3.141592653589793238462643

int main(){
	IOS;
	tihs;

	ll a,b,h,m;cin>>a>>b>>h>>m;
	ld val=(30*h-(5.50)*m)*PI/180.00;
	// cosC=(a*a+b*b-c*c)/2ab
	ld c=a*a+b*b-2*a*b*cos(val);
	c=sqrt(c);
	cout<<setprecision(20)<<c;

	return 0;
}

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

int gg;
int mx;

main()
{
	int n,k;
	scanf("%d %d %d",&n,&k,&gg);
	mx=gg;
	for(int i=1;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		gg=__gcd(gg,a);
		mx=max(mx,a);
	}
	if(k%gg==0)
	{
		if(k>mx)printf("IMPOSSIBLE\n");
		else printf("POSSIBLE\n");
	}
	else
		printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

float absf(float a){
    if(a>=0){
        return a;
    }
    else{
        return -a;
    }
}

int main(){
    int n, mni=-1;
    float t, a, mn=10000;
    cin >> n >> t  >>a;
    for(int i=1;i<=n;i++){
        float h;
        cin >> h;
        float tmp = absf(a-(t- h*0.006));
        if(tmp<mn){
            mni = i;
            mn = tmp;
        }
    }
    cout << mni << endl;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    double now = 0;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < K; i++) now += A[i]+1;
    double ma = now;
    for (int i = K; i < N; i++) {
        now = now + A[i] - A[i-K];
        if (ma < now) ma = now;
    }
    printf("%.10lf\n", (double)ma/2);
    return 0;
}


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

const int MAXN = 100005;

int bit[MAXN];

void update(int a, int b) {
    for (; a < MAXN; a += (a & -a))
        bit[a] += b;
}

int sum(int a) {
    int r = 0;
    for (; a; a -= (a & -a))
        r += bit[a];
    return r;
}

int main() {
    int n, q; cin >> n >> q;
    for (int i = 0; i < q; i++) {
        int o, a, b; cin >> o >> a >> b;
        if (o == 0) {
            update(a, b);
        } else {
            cout << sum(b) - sum(a - 1) << endl;
        }
    }
}


Measured memory_bytes: 3484
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<numeric>
#include<algorithm>
#include<string>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int pri[10001];
int ps;
int p[10001];
int saiki(int u){
	if(u<2)
		return true;
	if(p[u]!=-1)
		return p[u];
	bool f=false;
	for(int i=0;i<ps&&pri[i]<=u;i++){
		f|=!saiki(u-pri[i]);
	}
	p[u]=f;
	return f;
}
signed main(){
	int a,b;
	cin>>a>>b;
	if(a==1)
		a=14;
	if(b==1)
		b=14;
	if(a>b)
		cout<<"Alice"<<endl;
	else if(b>a)
		cout<<"Bob"<<endl;
	else
		cout<<"Draw"<<endl;

}

Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#define ll long long
#define vi vector<int>
#define vs vector<string>
#define fr(i, k, n) for (ll i = k; i < n; i++)
#define rep(i, n) fr(i, 0, n)
#define aintl(v) v.begin(), v.end()
#define mp(a, b) make_pair(a, b)
#define rdd(a) int a; cin >> a
#define rrd rdd(a); rep(i, a)
//min({a,b,c,d})などの記法
using namespace std;
template <class X> void pr(X x) { cout << x << endl; }
template <class X> void prr(X x) { for (auto it : x) { cout << it<<" ";}cout<<endl; }


int main(int argc, const char * argv[]) {
    string s;
    cin>>s;
    if (s[0]==s[2]) {pr("Yes");
    }
    else{pr("No");}
    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<ll> num(5,0);
    ll ans = 0;

    rep(i,n){
        string s; cin >> s;
        if(s[0] == 'M') num[0]++;
        if(s[0] == 'A') num[1]++;
        if(s[0] == 'R') num[2]++;
        if(s[0] == 'C') num[3]++;
        if(s[0] == 'H') num[4]++;
    }

    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans += num[i] * num[j] * num[k];
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
require 'pp'

A,B=gets.chomp.split(' ').map{|n| n.to_i}

sum = 0
A.upto(B){|i|
	a_5 = i%10
	a_4 = i/10%10
	a_3 = i/100%10
	a_2 = i/1000%10
	a_1 = i/10000%10
	if(a_5 == a_1 && a_4 == a_2)
		sum += 1
	end
}
puts sum


Measured memory_bytes: 2044
K=int(input())
queue=[1,2,3,4,5,6,7,8,9]
count=0
for i in range(K-1):
    t=queue[i]
    if t%10!=0:
        queue.append(t*10+pow(t,1,10)-1)
    queue.append(t*10+pow(t,1,10))
    if t%10!=9:
        queue.append(t*10+pow(t,1,10)+1)
print(queue[K-1])

Measured memory_bytes: 15764
#include<bits/stdc++.h>
#define ll long long 
//#define inf 1000000000000000000
using namespace std;
ll mod=1000000000000000001;
vector<ll> primeFactors(ll n)  
{  
    vector<ll> fact;
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        fact.push_back(2);
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            fact.push_back(i);
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        fact.push_back(n);
    return fact;
}  

int main(){
    ll n;
    cin>>n;
    vector<ll>fac=primeFactors(n);
    ll ans=0;
    for(int i=0; i<fac.size(); i++){
        int j=i;
        ll count=0;
        while(j<fac.size() && fac[i]==fac[j]){
            count++;
            j++;
        }
        ll y=1;
        y+=8*count;
        y=sqrt(y);
        y-=1;
        y/=2;
        ans+=y;
        i=j-1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3724
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] -= i; // B[i] = A[i] - i , A[i] = B[i] + i -> min sum_i abs(B[i] - b)
  }
  sort(A.begin(), A.end());
  vector<ll> acc(N + 1);
  for (int i = 0; i < N; i++) {
    acc[i + 1] = acc[i] + A[i];
  }


  ll ans = 1LL << 62;
  for (int i = 0; i < N; i++) {
    ans = min(ans, abs(acc[i] - A[i] * i) + abs(acc[N] - acc[i + 1] - A[i] * (N - i - 1)));
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
const ll INFTY=1ll<<61;

template<typename T>
void chmin(T& a,const T& b){
	a=min(a,b);
}

int main()
{
	for(int n,m,l;cin>>n>>m>>l;){
		vector<int> ks(n),ss(m);
		for(int& k:ks) cin>>k,k--;
		for(int& s:ss) cin>>s;
		
		sort(begin(ks),end(ks));
		
		vector<ll> sum(m+1);
		for(int i=0;i<m;i++) sum[i+1]=sum[i]+ss[i];
		
		vector<vector<ll>> dp(n,vector<ll>(n,INFTY));
		dp[0][0]=0;
		for(int i=1;i<n-1;i++) for(int j=0;j<i;j++){
			chmin(dp[i][j],dp[i-1][j]+(sum[ks[i]+1]-sum[ks[i-1]])/l);
			chmin(dp[i][i-1],dp[i-1][j]+(sum[ks[i]+1]-sum[ks[j]])/l);
		}
		ll res=INFTY;
		for(int i=0;i<n-1;i++)
			chmin(res,dp[n-2][i]+(sum[ks[n-1]+1]-sum[ks[n-2]])/l+(sum[ks[n-1]+1]-sum[ks[i]])/l);
		
		cout<<res<<endl;
	}
}

Measured memory_bytes: 33468
N = int(input())
S = input()

R = 0
G = 0
B = 0
ans = 0
for i in range(N):
    if S[i] == 'R':
        R += 1
        ans += G * B
    elif S[i] == 'G':
        G += 1
        ans += R * B
    elif S[i] == 'B':
        B += 1
        ans += R * G


L = 1
while L * 2 + 1 <= N:
    for i in range(N - L * 2):
        Q = [S[i], S[i + L], S[i + L + L]]
        if len(set(Q)) == 3:
            ans -= 1
    L += 1

print(ans)

Measured memory_bytes: 68344
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 10000
#define MAX_R 5000

int
main(int argc, char **argv)
{
	bool f[MAX_N];
	int bins[MAX_R];

	while(true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
		{
			f[i] = false;
			if (i < MAX_R)
				bins[i] = 0;
		}

		for (int i = 1; i < n; ++i)
			f[i * i % n] = true;

		int m = (n - 1) / 2;
		for (int i = 0; i < n; ++i)
		{
			if (f[i])
			{
				for (int j = 0; j < n; ++j)
				{
					if (f[j])
					{
						int d = (i - j + n) % n;
						if (d > m)
							d = n - d;

						bins[d]++;
					}
				}
			}
		}

		for (int i = 1; i <= m; ++i)
			printf("%d\n", bins[i]);
	}

	return 0;
}

Measured memory_bytes: 1808
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
def main():
  N, K = map(int, input().split())
  p = 10**9 +7
  for i in range(K):
    print((comb(N-K+1,i+1,p)*comb(K-1,i,p))%p)

if __name__ == '__main__':
  main()  


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main()
{
	string s;
	int k, l, ans = 0, tmp;

	cin >> s;
	cin >> k;

	l = s.length();

	tmp = 0;
	rep (i, l)
	{
		tmp++;
		if (i == l - 1 || s[i] != s[i + 1])
		{
			ans += tmp / 2;
			tmp = 0;
		}
	}

	ans *= k;

	if (s[0] == s[l - 1])
	{
		tmp = 1;
		rep (i, l - 1)
		{
			if (s[i] != s[i + 1]) break;
			tmp++;
		}
		if (tmp == l)
		{
			cout << l * k / 2 << endl;
			return 0;
		}
		if (tmp % 2)
		{
			tmp = 1;
			rep (i, l - 1)
			{
				if (s[l - 1 - i] != s[l - 2 - i]) break;
				tmp++;
			}
			if (tmp % 2) ans += k - 1;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;

/**
 *
 * @author must
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int X = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int choco = X;
        for(int i=0;i<N;i++){
            choco  += ((D -1) / A[i]) + 1;
        }
        System.out.println(choco);
    }
    
}


Measured memory_bytes: 23124
# coding: utf-8
# Your code here!
# coding: utf-8
import sys
sys.setrecursionlimit(200000000)


# my functions here!

#入力

def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    N,M=pin()
    ans=0
    red=[False]*N
    red[0]=True
    balls=[1]*N
    
    for i in range(M):
        x,y=pin()
        x,y=x-1,y-1
        #ボールの持ち出し
        if red[x]==True:
            red[y]=True
            if balls[x]==1:
                red[x]=False
        balls[x]-=1
        balls[y]+=1    
    print(sum(red))
    
    
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例1(self):
        input = """3 2
1 2
2 3"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例2(self):
        input = """3 3
1 2
2 3
2 3"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例3(self):
        input = """4 4
1 2
2 3
4 1
3 4"""
        output = """3"""
        self.assertIO(input, output)

if __name__=="__main__":resolve()

Measured memory_bytes: 7248
#include <stdio.h>

int main(void){
  int a,b,c,i,x;
  scanf("%d %d %d", &a,&b,&c);
  x = 0;

  for(i=a; i <=b; i++){
    if( c % i == 0){
      x++;
    }
  }
  printf("%d\n",x); 

return 0;
}

Measured memory_bytes: 596
n,k=map(int,input().split())
a=[int(x)-1 for x in input().split()]
b=[0]*n
b[0]=1
p=0
for c in range(k):
    p=a[p]
    if b[p]==1:
        break
    b[p]=1
if c==k-1:
    print(p+1)
else:
    q=p
    for d in range(n):
        q=a[q]
        if p==q:
            break
    m=(k-c-1)%(d+1)
    for e in range(m):
        p=a[p]
    print(p+1)

Measured memory_bytes: 32332
l=[str(i) for i in range(10)]
n,m=map(int,input().split())
w=input()
for i in range(n):
  if w[i] in l:
    pass
  else:
    print("No")
    exit()
if w[n]!="-":
  print("No")
  exit()
for i in range(m):
  if w[i+1+n] in l:
    pass
  else:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 38512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main () {
    int k;
    cin >> k;
    
    ll sum = 0;
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= k; j++) {
            for(int l = 1; l <= k; l++) {
                int ij = gcd(i,j);
                int ijl = gcd(ij, l);
                sum += ijl;
            }
        }
    }


    cout << sum << endl;

}

 


Measured memory_bytes: 3636
#include <stdio.h>

int dp[50];

int fib(int n){
  if( n == 0 || n == 1)
    return dp[n] = 1;
  if( dp[n] != -1)
    return dp[n];
  return dp[n] = fib( n - 1) + fib(n -2);
}

int main(){
  int n,i;
  for ( i = 0;i < 50; i++)
    dp[i] = -1;
  scanf("%d",&n);
  printf("%d\n",fib(n));
  return 0;
}


Measured memory_bytes: 2732
#include <iostream>

using namespace std;

char table[10][10] = {

  "* = ****",
  "* =* ***",
  "* =** **",
  "* =*** *",
  "* =**** ",
  " *= ****",
  " *=* ***",
  " *=** **",
  " *=*** *",
  " *=**** "

};

int main() {

  int n;

  char abacus[10][10];
  int digit[5];
 
  int flag=0;

  while(cin >> n) {

    if(flag==1) {

      cout << endl;

    }

    else flag=1;

    digit[0]=n%100000/10000;

    digit[1]=n%10000/1000;

    digit[2]=n%1000/100;

    digit[3]=n%100/10;

    digit[4]=n%10;

    for(int i=0;i<5;i++) {

      for(int j=0;j<8;j++) {

	abacus[i][j]=table[digit[i]][j];

      }

    }

    for(int i=0;i<8;i++) {

      for(int j=0;j<5;j++) {

	cout << abacus[j][i];

      }

      cout << endl;

    }

  }

  return 0;

}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>

const long long INF = 1LL<<60;
const int inf = 1 << 30;
const int mod = 1e9+7;


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 h, n;
  cin >> h >> n;
  int ab[n][2];
  rep(i, 0, n){
    int a, b;
    cin >> a >> b;
    ab[i][0] = a;
    ab[i][1] = b;
  }

  long long dp[20010];

  for (int i=0; i<20010; i++){
    dp[i] = INF;
  }
  dp[0] = 0;
  for (int i=0; i<=20010; i++){
    for (int j =0; j<n; j++){
      if(i-ab[j][0] >= 0){
        dp[i] = min(dp[i], dp[i - ab[j][0]] + ab[j][1]);
      }
    }
  }
  long long ans = INF;
  for(int i = h; i<20010; i++){
    ans = min(ans, dp[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
n,c=map(int,input().split())
diff=[list(map(int, input().split())) for _ in range(c)]
color=[list(map(int, input().split())) for _ in range(n)]

dic=[[0]*c for _ in range(3)]

for i in range(n):
    for j in range(n):
        dic[(i+j)%3][color[i][j]-1]+=1

result=10**9

for aa in range(c):
    #%0の色をaaにする
    a_cost=0
    for j in range(c):
        a_cost+=dic[0][j]*diff[j][aa]


    for bb in range(c):
        if aa!=bb:
            #%1の色をbbにする
            b_cost=0
            for j in range(c):
                b_cost+=dic[1][j]*diff[j][bb]

            for cc in range(c):
                if aa!=bb and bb!=cc and cc!=aa:
                    #%2の色をccにする
                    c_cost=0
                    for j in range(c):
                        c_cost+=dic[2][j]*diff[j][cc]
                    result=min(result,a_cost+b_cost+c_cost)

print(result)



Measured memory_bytes: 5620
#include<iostream>   //AA06( 05/ 07/ 20) If u see my code, Have a Good Day! (^_^)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)


using namespace std;

int main()
{
    fastio;

    int N;

    double X, Y;

    cin >> N;

    X = N / 1000.00;

    Y = X - (int)X;

    if(N % 1000 == 0)
        cout << "0" << endl;

    else
        cout << (1 - Y) * 1000 << endl;

    return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

int main() {
  int n;
  cin >> n;
  map<ll, ll> a;

  ll tmp_a;
  ll s = 0;
  rep(i, n) {
    cin >> tmp_a;
    a[tmp_a] += 1;
    s += tmp_a;
  }

  int q;
  cin >> q;
  vector<ll> b(q), c(q);
  rep(i, q) cin >> b[i] >> c[i];

  ll cnt_b, cnt_c;
  ll prev_s = s;
  rep(i, q) {
    cnt_b = a[b[i]];
    cnt_c = a[c[i]];
    s = prev_s - cnt_b * b[i];
    s += c[i] * cnt_b;
    cout << s << endl;
    a.erase(b[i]);
    a.erase(c[i]);
    a.insert({c[i], cnt_b + cnt_c});
    prev_s = s;
  }
  return 0;
}

Measured memory_bytes: 8656