akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc070/tasks/abc070_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b, d) - max(a, c)) << endl;

    return 0;
}


Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int n;
vector<int> g[200020];
int part[200020];
ll power_2[200020];
long long P,Q;
const int mod = 1e9 + 7;

ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

long long modinv(long long a, long long m = mod) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

void init(){
    for(int i = 0;i < 200020;i++){
        if(!i)power_2[i] = 1;
        else power_2[i] = (power_2[i-1] * 2) % mod;
    }
}
int dfs(int x,int p){
    int res = 1;
    for(int to : g[x]){
        if(to == p)continue;
        else res += dfs(to,x);
    }
    return part[x] = res;
}
void dfs2(int x,int p){
    ll res = 0;
    vector<ll> parts;
    for(int to : g[x]){
        if(to == p)parts.push_back(n-part[x]);
        else parts.push_back(part[to]);
    }
    if(parts.size() > 1){
      res = (res + power_2[n-1]+ mod) % mod;
      res = (res - 1 + mod) % mod;
      for(int s : parts){
        res = (res + mod - power_2[s] + 1) % mod;
      }
    }
    P = (P + res + mod) % mod;
    for(int to : g[x]){
      if(to != p)dfs2(to,x);
    }
}
int main(void){
    scanf("%d",&n);
    init();
    Q = power_2[n];

    for (int i = 0; i < n-1; ++i)
    {
        int a,b;scanf("%d %d",&a,&b);a--,b--;
        g[a].push_back(b);g[b].push_back(a);
    }

    dfs(0,-1);
    dfs2(0,-1);
    cout << (P * (modinv(Q))) % mod << endl;

}


Measured memory_bytes: 36352
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
pair<int ,int >p[N];
int main()
{
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int k,n;
	cin>>k>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int min1=a[n-1]-a[0];
	for(int i=1;i<n;i++)
	{
		min1=min(min1,a[n-1]-a[i]+(k-a[n-1])+a[i-1]);
		//if(a[n-1]-a[i]+(k-a[n-1])+a[i-1]<min1)//k-an-1绕环距离  再加上 前面的0到ai-1
	}
	cout<<min1;

    return 0;
}


Measured memory_bytes: 1024
# https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_b
# B - fLIP

# ボタンを押す順番と最後のマスの結果は関係ない
# あるボタンを2回押すと0回押した状態になる
# どの行、列のボタンを押しても黒マスの数は同じ
# 行のボタン、列のボタンを何回押したか見る

# 行のボタンをr回、列のボタンをc回押したとき、黒マスの数は
# r*M + c*N - 2*r*c


# N,M <= 1000 だし全探索

n, m, k = map(int, input().split())

can = False


def func(r, c):
    return r * m + c * n - 2 * r * c


for r in range(n + 1):
    for c in range(m + 1):
        can |= func(r, c) == k

print("Yes" if can else "No")


Measured memory_bytes: 2940
N,A,B,C = map(int,input().split())
mod = 10**9+7

m = max(2*N+10,101)
fac = [1]*m
ninv = [1]*m
finv = [1]*m
for i in range(2,m):
    fac[i] = fac[i-1]*i%mod
    ninv[i] = (-(mod//i)*ninv[mod%i])%mod
    finv[i] = finv[i-1]*ninv[i]%mod

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod
def pow_mod(x,n):
    if n==0: return 1
    if n%2:return x*pow_mod(x,n-1)%mod
    a = pow_mod(x,n//2)
    return a*a%mod

M = A+B
a = A*ninv[M]%mod
b = B*ninv[M]%mod
aN = pow_mod(a,N)
bN = pow_mod(b,N)
ans = 0
for i in range(N):
    ans += (((N+i)*aN%mod)*pow_mod(b,i)%mod)*comb(N-1+i,i)%mod
    ans += (((N+i)*bN%mod)*pow_mod(a,i)%mod)*comb(N-1+i,i)%mod
    ans %= mod
ans = ans*100*ninv[100-C]%mod
print(ans)

Measured memory_bytes: 124376
def isprime(p):
    import math
    if p == 2:
        return True
    
    if p < 2 or p % 2 == 0:
        return False

    i = 3
    while i <= math.sqrt(p):
        if p % i == 0:
            return False
        i = i + 2

    return True

if __name__ == "__main__":
    num = int(input())
    p_cnt=0
    for i in range(num):
        p = int(input())
        if isprime(p):
            p_cnt += 1
    
    print(p_cnt)



Measured memory_bytes: 5680
# 2019 9.1
# Power Socket

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

# dp = [0] * (N + 1)

cnt = 0
max = 0

for i in range(1, N):
    if H[-i - 1] >= H[-i]:
        cnt += 1
    else:
        cnt = 0

    if cnt > max:
        max = cnt

print(max)

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

#define INF 1000000000000000005

long long a, b, c, d;
long long ans = -INF;

int main() {
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	ans = max(ans, a * c);
	ans = max(ans, b * d);
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3864
import java.text.NumberFormat;
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			double n = sc.nextDouble();
			double ans =0;

			double a[]= new double[11];
			a[1]=n;
			for(int i=2; i<=10; i++)
			{
				if(i%2==0)
					a[i] = a[i-1]*2;
				else
					a[i]= a[i-1]/3;
			}
			for(int i=1; i<=10; i++)
				ans+=a[i];

			NumberFormat d = NumberFormat.getInstance();
			d.setMaximumFractionDigits(8);
			System.out.println(d.format(ans));
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, m;
    cin >> n >> m;

    ll s = 0;
    multiset<int> st;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        s += a;
        st.insert(a);
    }

    for (int j = 0; j < m; j++) {
        auto it = --st.end();
        int a = *it;
        st.erase(it);
        st.insert(a / 2);
        s += a / 2 - a;
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 4992
n, k = map(int, input().split())
h = [0] * n
for i in range(n):
    x = int(input())
    h[i] = x

h.sort()

ans = 10 ** 10
for i in range(n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])
print(ans)


Measured memory_bytes: 13372
def main():
  n, k = map(int, input().split())
  mp1 = [[0] * k for _ in range(k)]
  mp2 = [[0] * k for _ in range(k)]
  for _ in range(n):
    x, y, c = input().split()
    t = int(x) // k + int(y) // k
    x = int(x) % k
    y = int(y) % k
    if c == "B":
      t += 1
    if t % 2:
      mp1[y][x] += 1
    else:
      mp2[y][x] += 1
  
  mp10 = mp1[0]
  mp20 = mp2[0]
  for x in range(1, k):
    mp10[x] += mp10[x - 1]
    mp20[x] += mp20[x - 1]
  
  for y in range(1, k):
    acc1 = 0
    acc2 = 0
    mp1y = mp1[y]
    mp2y = mp2[y]
    mp1y1 = mp1[y - 1]
    mp2y1 = mp2[y - 1]
    for x in range(k):
      acc1 += mp1y[x]
      mp1y[x] = acc1 + mp1y1[x]
      acc2 += mp2y[x]
      mp2y[x] = acc2 + mp2y1[x]
  
  ans = 0
  sum1 = mp1[k - 1][k - 1]
  sum2 = mp2[k - 1][k - 1]
  mp1k = mp1[k - 1]
  mp2k = mp2[k - 1]
  for y in range(k):
    mp1y = mp1[y]
    mp1yk = mp1y[k - 1]
    mp2y = mp2[y]
    mp2yk = mp2y[k - 1]
    for x in range(k):
      mp1yx = mp1y[x]
      mp2yx = mp2y[x]
      mp1kx = mp1k[x]
      mp2kx = mp2k[x]
  
      a1 = 2 * mp1yx + sum1 - mp1yk - mp1kx + mp2kx + mp2yk - 2 * mp2yx
      a2 = 2 * mp2yx + sum2 - mp2yk - mp2kx + mp1kx + mp1yk - 2 * mp1yx
  
      if ans < a1:
        ans = a1
      if ans < a2:
        ans = a2
  
  
  print(ans)

main()

Measured memory_bytes: 82036
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <functional>
#include <queue>
#include <tuple>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using vb = vector<char>;
using vvb = vector<vb>;

#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define RREP(i, a, b) for (int i = (int)(b) - 1; i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define mp(a, b) make_pair(a,b)

#define fi first
#define sn second
#define decpii(p) p.fi--,p.sn--;


#ifdef LOCAL
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define dumpn(c) cerr << "> " << #c << " = " << (c) << ", ";
#else
#define dump(c) ;
#define dumpn(c) ;
#endif


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, (int) a.size())os << (i ? " " : "") << a[i];
    return os << ']';
}

const int INF = 1 << 29;

int dxf[] = {1, 0, -1, 0};
int dyf[] = {0, -1, 0, 1};

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

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

inline vi uni(vi &vec) {
    sort(vec.begin(), vec.end());
    vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

struct ____ {
    ____() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} ________;


string solve() {
    string S, T;
    cin >> S >> T;

    int nS = S.size();
    int nT = T.size();
    rrep(i, nS - nT + 1) {
        string s = S.substr(i, nT);
        dump(s);
        bool hit = true;
        rep(j, s.size()) {
            dumpn(s[j]);
            dump(T[j]);
            if (!(s[j] == '?' || T[j] == s[j])) {
                hit = false;
                break;
            }
        }

        if (hit) {
            dump(i);
            stringstream ss;
            rep(j, i)ss << (S[j] == '?' ? 'a' : S[j]);
            ss << T;
            REP(j, i + nT, nS)ss << (S[j] == '?' ? 'a' : S[j]);
            return ss.str();
        }
    }

    return "UNRESTORABLE";
}

int main() {
//    cout << (solve() ? "Yes" : "No") << endl;
    cout << solve() << endl;
//    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LIM 1+2+4+8+16+32+64+128
using namespace std;
typedef long long int ll;
typedef struct{
  int per;
  int ko;
  int kyoda;
  int konoko;
}TRE;
typedef pair<int,int>P;
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  if((b+a)%2==0){
    cout<<"Alice"<<endl;
  }else{
    cout<<"Borys"<<endl;
  }
  return(0);
}


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

int main() {
	int N = 0, K = 0, X = 0, Y = 0;
	cin >> N; //泊数
	cin >> K;//X円の泊数
	cin >> X;//値段
	cin >> Y;//値段

	int ans = 0;

	if (N > K) ans = K * X + (N - K) * Y;
	else ans = N * X;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> l(N);
	vector<int> r(N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> l[i] >> r[i];
		ans += r[i] - l[i] + 1;
	}
	cout << ans << endl;
}

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

const int pow2[] = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071 };

int *a, y;

int sum(int k, int l, int r)
{
    if (y<l)  return 0;
    if (r<=y) return a[k];
    int t = (l+r)>>1;
    return sum(k<<1, l, t) + sum((k<<1)+1, t+1, r);
}

int main()
{
  int i, j, k, n, z, s, t, u, x;
  char buf[32], *p;
  buf[31] = 0;
  buf[30] = '\n';
  fgets(buf, 32, stdin);
  for (n=0,p=buf; *p!=' '; n=n*10+*(p++)-'0');
  n++;
  u = pow2[(int)ceil(log2(n))];
  a = (int*)malloc((u+n+1)*sizeof(int));
  
  while (fgets(buf, 32, stdin)) {
    p = buf + 2;
    if (buf[0]=='0') {
      for (s=0; *p!=' ';  s=s*10+*(p++)-'0');
      for (t=0, p++; *p!=' ';  t=t*10+*(p++)-'0');
      for (x=0, p++; *p!='\n'; x=x*10+*(p++)-'0');
      for (k=u+s,a[k]+=x; k>1; a[k]=a[j]+a[j+1]) {
        j=k&~1;  k>>=1;
      }
      for (k=u+t+1,a[k]-=x; k>1; a[k]=a[j]+a[j+1]) {
        j=k&~1;  k>>=1;
      }
    } else {
      for (y=0; *p!='\n'; y=y*10+*(p++)-'0');
      z = sum(1, 1, u+1);
      if (z==0) {
        putc_unlocked('0', stdout);
        putc_unlocked('\n', stdout);
      } else {
        for (k=1; k*10<=z; k*=10);
        for (;k>0; k/=10) {
          putc_unlocked('0'+z/k, stdout);
          z %= k;
        }
        putc_unlocked('\n', stdout);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2552
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int d = a/b;
		int r = a%b;
		String f = String.format("%.5f", 1.0*a/b); //?°???°?????\???5????????????
		System.out.println(d + " " + r + " " + f);
	}

}

Measured memory_bytes: 26292
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin>>N;
    vector<int> W(N);
    for(int i=0;i<N;i++){
        cin>>W[i];
    }
    int minimum=9999999;
    for(int i=1;i<N;i++){
        int S1=0,S2=0;
        for(int j=0;j<i;j++){
            S1=S1+W[j];
        }
        for(int k=i;k<N;k++){
            S2=S2+W[k];
        }
        int sa=abs(S1-S2);
        minimum=min(minimum,sa);
    }

    cout<<minimum;
    return 0;
}

Measured memory_bytes: 256
/**
 *      ABC 57 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-05 02:24:08
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int A, B; cin >> A >> B;
    cout << (A + B) % 24 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> S[20];
    for(int i = 0;i < M;i++) {
        int A;
        cin >> A;
        for(int j = 0;j < A;j++) {
            int B;
            cin >> B;
            S[B - 1].push_back(i);
        }
    }
    vector<int> vec(M);
    for(int i = 0;i < M;i++) {
        cin >> vec.at(i);
    }
    int ret = 0;
    for(int bit = 0;bit < (1 << N);bit++) {
        vector<int> on;
        for(int i = 0;i < N;i++) {
            if(bit & (1 << i)) {
                on.push_back(i);
            }
        }
        vector<int> cnt(M);
        for(int i = 0;i < on.size();i++) {
            for(int j = 0;j < S[on.at(i)].size();j++) {
                cnt.at(S[on.at(i)].at(j))++;
            }
        }
        bool ret2 = true;
        for(int i = 0;i < M;i++) {
            if(cnt.at(i) % 2 != vec.at(i)) {
                ret2 = false;
            }
        }
        if(ret2 == true) {
            ret++;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
	int r;
	cin >> r;
	int D;
	cin >> D;
	int x[11];
	cin >> x[0];

	for (int i = 1; i < 11; i++) {
		x[i] = x[i - 1] * r - D;
		cout << x[i]<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cassert>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<utility>
using namespace std;

int n,y,m,d;

bool input(){
	cin>>y>>m>>d;
	return true;
}


int solve(){
	int count=0;

	if(m%2==1||y%3==0){
		count=count+20-d+1;
	}else{
		count=count+19-d+1;
	}

		for(int j=m+1; j<=10; j++){
			if(j%2==1||y%3==0){
				count=count+20;
			}else{
				count=count+19;
			}
		}

		for(int i=y+1; i<1000; i++){
			if(i%3==0){
				count=count+20*10;
			}else{
				count=count+20*5+19*5;
			}
		}
  return count;
}


int main(){
  cin>>n;
  for(int i=0; i<n; i++){
	input();
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nk = Add.ar;
        var ar = Add.ar;
        var sum1 = new long[nk[0]+1];
        var sum2 = new long[nk[0]+1];
        sum1[0] = 0;
        sum2[0] = 0;
        for(var i = 1; i <= nk[0]; i++)
        {
            sum1[i] = sum1[i - 1] + ar[i-1];
            sum2[i] = sum2[i - 1] + Max(ar[i-1], 0);
        }
        var res = 0L;
        for(var i = 0; i < nk[0]-nk[1]+1; i++)
        {
            var bl = sum2[nk[0]] - (sum2[i + nk[1]] - sum2[i]);
            res = Max(res, bl);
            res = Max(res, bl + sum1[i + nk[1]] - sum1[i]);
        }
        WriteLine(res);
    }
}

public class Add
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 32732
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  vector<int> D1(n),D2(n);
  rep(i,n) cin>>D1[i]>>D2[i];
  
  bool b=false;
  for(int i=2;i<n;i++){
    if(D1[i-2]==D2[i-2] && D1[i-1]==D2[i-1] && D1[i]==D2[i]) b=true;
  }
  if(b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
 
  return 0; 
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int w[101],v[101];
int dp[101][10001]={};

int main() {

	int n,W;
	cin>>n>>W;
	rep(i,n){
		cin>>v[i]>>w[i];
	}
	rep(i,W+1){
		dp[0][i]=0;
	}
	rep(i,n){
		rep(j,W+1){
			if(j>=w[i])dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
			else dp[i+1][j]=dp[i][j];
		}
	}
	cout<<dp[n][W]<<endl;

	return 0;
}



Measured memory_bytes: 7060
#include "bits/stdc++.h"
using namespace std;

int N;

int main() {
    cin >> N;
    int digitn, answer = 0;
    digitn = (int)log10(N);
    for(int i = 0; i < digitn; i += 2) {
        answer += 9 * (int)pow(10, i);
    }
    if(digitn % 2 == 0) {
        answer += N - (int) pow(10, digitn) + 1;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}

signed main()
{   
    int a,b,c; cin>>a>>b>>c;
    if(c%gcd(a,b)==0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 256
import sys
import math
import functools
from collections import deque
sin = sys.stdin

n = int(sin.readline())
a = []
b = []
c = []
for i in range(n):
    values = sin.readline().split()
    a.append(int(values[0]))
    b.append(int(values[1]))
    c.append(int(values[2]))

dp = [[0 for i in range(n)] for i in range(3)]

dp[0][0] = a[0]
dp[1][0] = b[0]
dp[2][0] = c[0]

for i in range(1, n):
    dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + a[i]
    dp[1][i] = max(dp[2][i-1], dp[0][i-1]) + b[i]
    dp[2][i] = max(dp[1][i-1], dp[0][i-1]) + c[i]

print(max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1])))


Measured memory_bytes: 73820
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let n: usize = read!();
    let mut a = vec![0isize; 100001];
    for _ in 0..n {
        let ai: usize = read!();
        a[ai] += 1;
    }

    let mut now_sum = a
        .iter()
        .enumerate()
        .map(|(index, &amount)| index as isize * amount)
        .sum::<isize>();

    let q: usize = read!();
    for _ in 0..q {
        let b: isize = read!();
        let c: isize = read!();

        let change = a[b as usize];
        a[b as usize] = 0;
        a[c as usize] += change;
        now_sum += change * (c - b);
        println!("{}", now_sum);
    }
}


Measured memory_bytes: 2792
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int n, k;
ll h[310];

ll dp[310][310][310];
bool memo[310][310][310];
ll f(int x, int y, int z)
{
    if(x == n+1) return 0;
    if(memo[x][y][z]) return dp[x][y][z];
    ll ans = f(x+1, x, z) + max(0LL, h[x] - h[y]);
    if(z>0) ans = min(ans, f(x+1, y, z-1));
    memo[x][y][z] = 1;
    dp[x][y][z] = ans;
    return ans;
}

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> n >> k;
    Forn(i, n) cin >> h[i];
    cout << f(1, 0, k) << endl;
}


Measured memory_bytes: 254464
#include<bits/stdc++.h>
using namespace std;
int n;
double a[100];
multiset<double>st;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],st.insert(a[i]);
	for(int i=1;i<n;i++)
	{
		double x=*st.begin();
		st.erase(st.begin());
		double y=*st.begin();
		st.erase(st.begin());
		x=(x+y)/2;
		st.insert(x);
	}
	cout<<*st.begin();
}

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

int main() {
    string S;
    cin >> S;
    int front = stoi(S.substr(0, 2));
    int back = stoi(S.substr(2, 2));
    string messages;
    if((back <=12 && 0 < back) && (front <=12 && 0 < front)) {
        messages = "AMBIGUOUS";
    }else if((back <=12 && 0 < back)) {
        messages = "YYMM";
    } else if((front <=12 && 0 < front)) {
        messages = "MMYY";
    } else {
        messages = "NA";
    }
    cout << messages << endl;
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    long long N, S, x, A[200005], B[200005], i;
    scanf("%lld", &N);
    for (i=0; i<N; i++) scanf("%lld", &A[i]);
    for (i=1; i<=N; i++) B[i]=0;
    for (i=0; i<N; i++) B[A[i]]++;
    S=0;
    for (i=1; i<=N; i++) S+=B[i]*(B[i]-1)/2;
    for (i=0; i<N; i++) {
        x=B[A[i]];
        // printf("%lld", x);
        printf("%lld", S+(x-1)*(x-2)/2-x*(x-1)/2);
        if (i!=N-1) printf("\n");
    }
    return 0;
}


Measured memory_bytes: 5632
H,W=map(int,input().split())
graph = [list(input()) for _ in range(H)]
onesteps=((1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,1),(1,-1),(-1,-1))
for x in range(H):
    for y in range(W):
        count=0
        if graph[x][y]==".":
            for dx,dy in onesteps:
                if (0<=x+dx<H)and(0<=y+dy<W):
                    if graph[x+dx][y+dy]=="#":
                        count+=1
            graph[x][y]=str(count)
for line in graph:
    print("".join(line))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
int main()
{
    double n, ans=0.0;
    cin >> n;
    string a;
    long double b;
    for(int i=0; i<n; i++)
    {
        cin >> b >> a;
        if(a=="JPY")
            ans+=b;
        else
        {
            ans+=380000*b;
        }
    }
    cout << fixed << ans << '\n';
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        StringBuilder print=new StringBuilder();
        int n=Integer.parseInt(br.readLine());
        int mod=1000000007;
        long ans=modexp(10,n,mod);
        long temp=modexp(8,n,mod);
        ans=(ans-temp+mod)%mod;
        temp=1;
        long fact[]=new long[n+1];
        long inv[]=new long[n+1];
        fact[0]=1;
        for(int i=1;i<=n;i++){
            fact[i]=(fact[i-1]*i)%mod;
        }
        inv[n]=modexp(fact[n],mod-2,mod);
        long pow[]=new long[n+1];
        pow[0]=1;
        for(int i=1;i<=n;i++){
            pow[i]=(pow[i-1]*8)%mod;
        }
        for(int i=n-1;i>=1;i--){
            inv[i]=(inv[i+1]*(i+1))%mod;
        }
        for(int i=1;i<=n;i++){
            long num=pow[n-i];
            num=(num*fact[n])%mod;
            num=(num*inv[i])%mod;
            num=(num*inv[n-i])%mod;
//            System.out.println(num);
            temp=(temp+num)%mod;
        }
        temp=(temp*2)%mod;
//        System.out.println(ans+" "+temp);
        ans=(ans-temp+mod)%mod;
        System.out.println(ans);
    }
    public static long modexp(long a,long power,int mod){
        if(power==0){
            return 1;
        }
        if(power==1){
            return a;
        }
        long small=modexp(a,power/2,mod);
        long ans=(small%mod*small%mod)%mod;
        if(power%2!=0){
            ans=(ans%mod*a%mod)%mod;
        }
        return ans;
    }
}


Measured memory_bytes: 56080
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int r, g, b, n;
    std::cin >> r >> g >> b >> n;
    int ret = 0;
    for (int i = 0; i <= 3000; i++) for (int j = 0; j <= 3000; j++) {
        int m = n - r * i - g * j;
        if (m >= 0 && m % b == 0) ret++;
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
def solve(n, y):
    for x1 in range(n+1):
        x2 = ( y - 1000*n - 9000*x1) / 4000
        x3 = (-y + 5000*n + 5000*x1) / 4000
        if (x2 >= 0) and (x3 >= 0) and (x1 + x2 + x3 == n):
            return x1, x2, x3
    return -1, -1, -1

n, y = map(int, raw_input().split())
print " ".join(map(str, solve(n, y)))

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

counter = 0
for i in range(N):
    checker_1 = (i + 1) % 2 == 1
    checker_2 = A[i] % 2 == 1
    if checker_1 & checker_2:
        counter += 1
print(counter)


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

int main(){
  long long n;
  cin >> n;
  long long num = 1;
  for(long long i=1; i*i<=n; i++){
    if(n % i == 0) num = i;
  }
  long long res = n / num;
  long long count = 0;
  while(res > 0){
    res /= 10;
    count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

N = int(raw_input().split()[0])
M = []
for i in range(5):
    l = int(raw_input().split()[0])
    M.append(l)
# print(M, N)
a = min(M)
# print(a)
b = (N + a - 1) / a
print(b + 4)

Measured memory_bytes: 2568
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n; cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  rep(i, n) {
    cin >> s[i] >> t[i];
  }
  string x; cin >> x;
  bool sleep = false;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == x) sleep = true;
    if (sleep) ans += t[i];
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  int w,a,b;
  cin>>w>>a>>b;

  if((b+w-a<=2*w && b>a) || ((a+w-b<=2*w) && b<a) || (b==a))
    cout<<0<<endl;
  else
    cout<<min(abs(a+w-b),abs(b+w-a))<<endl;

	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,count=0,x;
  string S;
  map<string,int> mp;
  cin>>N;
  for(int i=0;i<N;i++){cin>>S;if(mp.count(S)==1)mp[S]++;else mp[S]=0;count=max(mp[S],count);}
  for(auto p:mp){auto key=p.first;auto value=p.second;if(value==count)cout<<key<<endl;}
}

Measured memory_bytes: 25216
def f(x):
    if x==2:
        return 1
    if x<2 or x%2==0:
        return 0
    i=3
    while i<=x**(1/2):
        if x%i==0:
            return 0
        i+=2
    return 1

n=int(input())
s=0
for i in range(n):
    x=int(input())
    s+=f(x)
print(s)


Measured memory_bytes: 5656
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
ll nob(ll x){ll s=0;while(x) s+=x%2,x/=2;return s;}
int main(){
	ll n,i,j,u,b,c=0,f;
	cin>>n;vi a(n);vvi x(n),y(n);
	for(i=0;i<n;i++){
		cin>>a[i];
		for(j=0;j<a[i];j++) cin>>u>>b,x[i].eb(u),y[i].eb(b);
	}for(i=0;i<(1<<n);i++){f=1;
		for(j=0;j<n;j++){
			if(!(i&(1<<j))) continue;
			for(u=0;u<a[j];u++) if((bool)(i&(1<<(x[j][u]-1)))!=y[j][u]) f=0;
		}if(f) c=max(c,nob(i));
	}cout<<c<<endl;
}


Measured memory_bytes: 256
def mk_tree(A,N):
    B = [None for _ in range(N+1)]
    B[0] = 1
    #B[i]:深さiの頂点の個数
    A_sum = [A[i] for i in range(N+1)]
    for i in reversed(range(N)):
        A_sum[i] += A_sum[i+1]

    for i in range(1,N+1):
        B[i] = min(2*(B[i-1]-A[i-1]),A_sum[i])

    if B[N] == A[N]:
        return sum(B)
    else:
        return -1

def main():
    N = int(input())
    A = list(map(int,input().split()))

    print(mk_tree(A,N))

if __name__ == "__main__":
    main()


Measured memory_bytes: 650896
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define IN freopen("in.txt", "r", stdin);
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define int long long
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;

const int N = 1e5+10;
VI g[N];
ll pro[N],MOD,dp[N];
VI pre[N],last[N];
map<int,int> mp;

void mul(ll &x,ll y){x=x*y%MOD;}
void dfs(int x,int fa){
    if(sz(g[x])==1&&g[x][0]==fa){
        pro[x]=1;
        return ;
    }
    ll res=1;
    for(auto it:g[x]){
        if(it==fa)continue;
        dfs(it,x);
        mul(res,pro[it]+1);
    }
    pro[x]=res;
}

void dfs2(int x,int fa){
    ll res=0;
    if(x==1){
        dp[x]=pro[x];
    }else{
        res=1LL*pre[fa][mp[x]-1]*last[fa][sz(pre[fa])-1-mp[x]]%MOD;
        dp[x]=(pro[x]+res*pro[x]%MOD)%MOD;
    }
    int rk=1,Pre=res+1,Last=1;
    pre[x].pb(res+1);
    last[x].pb(1);
    for(auto it:g[x]){
        if(it==fa)continue;
        Pre=1LL*Pre*(pro[it]+1)%MOD;
        pre[x].pb(Pre);
        mp[it]=rk++;
    }
    for(int i=sz(g[x])-1;i>=0;i--){
        int to=g[x][i];
        if(to==fa)continue;
        Last=1LL*Last*(pro[to]+1)%MOD;
        last[x].pb(Last);
    }
    for(auto it:g[x]){
        if(it==fa)continue;
        dfs2(it,x);
    }

}

int32_t main(){
    IOS;
    int n;cin>>n>>MOD;
    for(int i=1;i<n;i++){
        int u,v;cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1,0);
    dfs2(1,0);
    for(int i=1;i<=n;i++)cout<<dp[i]<<endl;
    return 0;
}

Measured memory_bytes: 34688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll gcd(ll a, ll b){
    ll r=a%b;
    while(r){
        a = b, b = r;
        r = a % b;
    }
    return b;
}
int main() {
    init();
    ll N,K;
    cin >> N >> K;
    vc<ll> A(N);
    rep(i, N) cin >> A[i];

    ll g = A[0];
    rep(i, N) g = gcd(g, A[i]);

    bool isok = false;
    rep(i,N){
        if(A[i]>=K and (A[i]-K)%g==0){
            isok = true;
            break;
        }
    }

    cout << (isok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int sum = 0;
	for (int x = a; x <= b; x++) {
		
		if (c%x == 0) {
			sum += 1;
		}
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3100
n = int(input())
s = list(input())
t_1 = list()
t_2 = list()
m = 1
if n % 2 == 0:
    for i in range(int(n / 2)):
        t_1.append(s[i])
        t_2.append(s[int(n / 2) + i])
else:
    m *= 0
    
for i in range(len(t_1)):
    if t_1[i] == t_2[i]:
        m *= 1
    else:
        m *= 0
        break
    
if m == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#define scanf_s scanf
#include<stdio.h>
#include<algorithm>

int main(void) {
	while (1) {
		int N, k, cou = 0, pl[10] = { 0 }, ba = 0;
		char card[101];
		bool flag = false;
		scanf_s("%d", &N);
		if (N == 0) break;
		scanf_s("%s", card);
		for (int i = 0; i < 100; ++i) {
			switch (card[i]) {
				//???
			case 'M':++pl[i % N]; break;
				//?\?
			case 'L': ++pl[i % N]; pl[i % N] += ba; ba = 0; break;
				//??????
			case 'S':ba += pl[i % N] + 1; pl[i % N] = 0; break;
			}
		}
		std::sort(pl, pl + N);
		for (int i = 0; i < N; ++i) {
			if(i != 0) printf(" ");
			printf("%d", pl[i]);
		}
		printf(" %d", ba);
		printf("\n");
	}
}

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

int main() {
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];
    vector<int> A(N);
    copy(all(P), A.begin());
    sort(all(A));

    int i = 0;
    map<vector<int>,int> m;
    do {
        i++;
        m[A] = i;
    } while (next_permutation(A.begin(), A.end()));

    cout << abs(m[P] - m[Q]) << endl;
}

Measured memory_bytes: 5248
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    // 問題番号, 正解したかどうか, WAの個数
    map<Int, pair<Int, Int> > mp;
    Int n, m;
    cin >> n >> m;

    for (Int i = 0; i < m; ++i) {
        Int p;
        string s;
        cin >> p >> s;
        --p;
        if (mp[p].first == 0) { 
            if (s == "AC") {
                mp[p].first = 1;
            } else {
                ++mp[p].second;
            }
        }
    }

    Int ac_num = 0;
    Int penalty_num = 0;
    for (Int i = 0; i < n; ++i) {
        if (mp[i].first != 0) {
            ac_num += mp[i].first;
            penalty_num += mp[i].second;
        }
    }
    cout << ac_num << " " << penalty_num << endl;

    return 0;
}



Measured memory_bytes: 9820
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define INFTY 1 << 21

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  ll numC, numD;

  // C,Dで割り切れる数
  if (A % C == 0)
    numC = B / C - A / C + 1;
  else
    numC = B / C - A / C;
  if (A % D == 0)
    numD = B / D - A / D + 1;
  else
    numD = B / D - A / D;

  ll c = C, d = D;

  // dを最小公倍数にする
  ll mod = c % d;
  while (mod != 0) {
    c = d;
    d = mod;
    mod = c % d;
  }
  d = (C * D) / d;

  //最小公倍数で割り切れる数、CかDで割り切れる数
  ll numCD;
  if (A % c == 0 && d <= A)
    numCD = B / d - A / d + 1;
  else
    numCD = B / d - A / d;

  ll ans = numC + numD - numCD;

  cout << ((B - A) + 1) - ans << endl;
}


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

using namespace std;

int main() {
  int n; cin >> n;
  int l; cin >> l;
  vector <string> s(n);
  for(int i = 0; i < n; i++) {
    //cout << x << '\n';
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  string ans = "";
  for(int i = 0; i < n; i++) {
    ans += s[i];
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;



#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#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(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;


int32_t main()
{

  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<int> p(a+1,0),pp(a+1,0);
  vector<int> q(b+1,0),qq(b+1,0);
  vector<int> r(c+1,0),rr(c+1,0);
  for(int i = 1;i<=a;i++){
    cin>>p[i];
  }
  for(int i = 1;i<=b;i++){
    cin>>q[i];
  }
  for(int i = 1;i<=c;i++){
    cin>>r[i];
  }
  sort(p.begin()+1,p.end(),greater<ll>());
  sort(q.begin()+1,q.end(),greater<ll>());
  sort(r.begin()+1,r.end(),greater<ll>());
  pp = p;
  qq = q;
  rr = r;
  for(int i = 1;i<=a;i++){
    pp[i]+=pp[i-1];
  }
  for(int i = 1;i<=b;i++){
    qq[i]+=qq[i-1];
  }
  for(int i = 1;i<=c;i++){
    rr[i]+=rr[i-1];
  }
  
  int i  = x,j = y;
  int ans = pp[x]+qq[y];
  int sum = ans;
  for(int cls = 1;cls<=min(c,x+y);cls++){
    if(i>=1&&j>=1){
      if(p[i]<q[j]){
        sum-=p[i];
        i--;

      }
      else {
        sum-=q[j];
        j--;
      }
    }
    else if(i>=1){
      sum-=p[i];
      i--;
    }
    else{
      sum-=q[j];
      j--;
    }
    sum+=r[cls];
    ans = max(sum,ans);

  }
  cout<<ans<<endl;







}


Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=4010;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int a[N][N],b[N][N],k;
inline int S(int a[N][N],int x,int y) { return a[x][y]-a[x+k/2][y]-a[x][y+k/2]+a[x+k/2][y+k/2]; }
int main()
{
	int n=gi(),i,j,x,y;char c;k=gi()*2;
	for (i=1;i<=n;i++) {
		x=gi()%k,y=gi()%k;
		while ((c=getchar())!='B'&&c!='W');
		if (c=='B') a[x][y]++,a[x][y+k]++,a[x+k][y]++,a[x+k][y+k]++;
		else b[x][y]++,b[x][y+k]++,b[x+k][y]++,b[x+k][y+k]++;
	}
	for (i=k*2-1;~i;i--)
		for (j=k*2-1;~j;j--) {
			a[i][j]+=a[i+1][j]+a[i][j+1]-a[i+1][j+1];
			b[i][j]+=b[i+1][j]+b[i][j+1]-b[i+1][j+1];
		}
	int ans=0;
	for (x=0;x<=k;x++)
		for (y=0;y<=k;y++)
			upmax(ans,S(a,x,y)+S(a,x+k/2,y+k/2)+S(b,x+k/2,y)+S(b,x,y+k/2));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 125696
#include <stdio.h>
#include <string.h>
int main()
{   
    int a = 0;  /* Sは回文である */
    int b = 0;  /* Sの前半は回文である */
    int c = 0;  /* Sの後半は回文である */
    int index;
    int index2;
    int size;
    char S[1000];
    char temp[1000];
    char temp2[1000];

    scanf("%s", &S);
    size = strlen(S);
    for(index = 0; index < strlen(S); ++index)
        temp[index] = S[size - index - 1];
    temp[index] = '\0';
  //printf("%s %s\n", S, temp);

    if(strcmp(S, temp) == 0)
        a = 1;

    for(index = 0; index < (strlen(S) - 1) / 2; ++index)
        temp[index] = S[index];
    temp[index] = '\0';

    for(index = 0; index < strlen(temp); ++index)
        temp2[index] = temp[strlen(temp) - 1 - index];
  temp2[index] = '\0';
   //printf("%s %s\n", temp, temp2);

    if(strcmp(temp, temp2) == 0)
        b = 1;
    
    for(index = ((strlen(S) + 1) / 2), index2 = 0; index < strlen(S); ++index, ++index2)
        temp[index2] = S[index];
    temp[index2] = '\0';

    for(index = 0; index < strlen(temp); ++index)
        temp2[index] = temp[strlen(temp) - 1 - index];
  temp2[index] = '\0';
  //printf("%s %s\n", temp, temp2);

    if(strcmp(temp, temp2) == 0)
        c = 1;

    if(a == 1 && b == 1 && c == 1)
        printf("Yes\n");
    else   
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){int A,B,C,X,Y,p;cin >> A >> B >> C >> X >> Y;
cout << min(min(A*X+B*Y,2*C*min(X,Y)+ ((X - Y) > 0 ? A * (X - Y) : B * (Y - X))),2 * C * ((X - Y) > 0 ? X : Y));
}

Measured memory_bytes: 256
import itertools
s=input()
li=["+",""]
lli=list(itertools.product(li,repeat=len(s)-1))
ans=0
for k in lli:
  val=""
  for i,j in zip(s,k):
    val+=i+j
  val+=s[-1]
  ans+=eval(val)
print(ans)

Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N;
    int data[N]; F0R(i, N) cin >> data[i];

    map<int, int> counts;
    F0R(i, N) {
        if (!counts.count(data[i])) counts.insert(mp(data[i], 0));
        counts[data[i]]++;
    }

    if (counts.count(0) && counts[0] == N) {
        cout << "Yes" << endl;
        return 0;
    } else if (N % 3 != 0) {
        cout << "No" << endl;
        return 0;
    }
    int xorSum = 0;
    for (auto it = counts.begin(); it != counts.end(); it++) {
        if (it-> s == N || it->s == N/3) {
            xorSum = xorSum ^ it->f;
        } else if (it->s != 2*N/3) {
            cout << "No" << endl;
            return 0;
        }
    }
    if (xorSum != 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 4224