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

using namespace std;

int main() {
    int n = 0, c = 0, k = 0;
    int a[100000];
    cin >> n >> c >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 1, base = 0;
    int passenger = 0;
    int p = 0;
    while (p != n){
        if (passenger < c && (a[p] - a[base] <= k)){
            p++;
            passenger++;
        } else {
            ans++;
            base = p;
            p++;
            passenger = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	long double a,b,x;
  	cin>>a>>b>>x;
  
  	cout<<fixed<<setprecision(10);
  	if(x<a*a*b/2){
     	cout<<atan(a*b*b/(2*x))*180.0/M_PI; 
    }else{
     	cout<<atan((2*a*a*b-2*x)/(a*a*a))*180.0/M_PI; 
    }
  	
  	
}

Measured memory_bytes: 3792
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    long long n, p;
    cin >> n >> p;

    if (n == 1) {
        cout << p << endl;
        return 0;
    }

    vector<pair<long long, long long> > v;

    for (long long i = 2; i * i <= p; i++) {
        long long count = 0;
        while (p % i == 0) {
            count++;
            p /= i;
        }
        if (count) {
            v.push_back(make_pair(i, count));
        }
        if (i != 2) {
            i++;
        }
    }

    long long ans = 1;
    for (long long i = 0; i < v.size(); i++) {
        ans *= pow(v[i].first, v[i].second / n);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
s = input()
t = input()
index = -1
Wrap = 0

for a in t:
  index = s.find( a, index+1)
  if index != -1:
    continue
  Wrap += 1
  index = s.find(a)
  if index == -1:
    print(-1)
    exit()
print(len(s)*Wrap + index +1)

Measured memory_bytes: 3316
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> P;

ll dist[210][210];

int main()
{
  REP(i, 210) REP(j, 210) {
    dist[i][j] = LLINF;
    if (i == j) dist[i][j] = 0;
  }

  int N, M, R;
  cin >> N >> M >> R;
  vector<ll> r(R);
  REP(i, R) {
    cin >> r[i];
    r[i]--;
  }
  REP(i, M) {
    int A, B, C;
    cin >> A >> B >> C;
    A--; B--;
    dist[A][B] = dist[B][A] = C;
  }

  REP(k, N) REP(i, N) REP(j, N) dist[i][j] = min(dist[i][k] + dist[k][j], dist[i][j]);
  sort(ALL(r));
  ll ans = LLINF;
  do {
    ll cost = 0;
    for (int i = 1; i < R; i++)
      cost += dist[r[i - 1]][r[i]];
    ans = min(cost, ans);
  } while (next_permutation(r.begin(), r.end()));

  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	vector<vector<int>> G(N + 1);
	for (auto i = 0; i < M; ++i)
	{
		int A, B;
		cin >> A >> B;
		G[A].push_back(B);
		G[B].push_back(A);
	}

	vector<int> list[2];
	bool used[100001];
	memset(used, 0, sizeof(used));
	used[1] = true;
	
	list[0].push_back(1);
	auto index = 0;
	for (auto i = 0; i < G[1].size(); ++i)
	{
		auto next = G[1][i];
		if (used[next])
		{
			continue;
		}

		while (true)
		{
			list[index].push_back(next);
			used[next] = true;

			auto& g = G[next];
			auto found = false;
			for (auto temp : g)
			{
				if (!used[temp])
				{
					found = true;
					next = temp;
					break;
				}
			}

			if (!found)
			{
				break;
			}
		}

		++index;
		if (index >= 2)
		{
			break;
		}
	}

	cout << list[0].size() + list[1].size() << endl;
	for (auto i = (int)list[0].size() - 1; i >= 0; --i)
	{
		cout << list[0][i];
		if (i > 0)
		{
			cout << " ";
		}
	}
	for (auto i = 0; i < list[1].size(); ++i)
	{
		cout << " " << list[1][i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 6904
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

void merge(vector<int> tree[], int treeNode) { 
    int len1 = 
    tree[2 * treeNode].size(); 
    int len2 = 
    tree[2 * treeNode + 1].size(); 
    int index1 = 0, index2 = 0; 
    while (index1 < len1 && index2 < len2) { 
        if (tree[2 * treeNode][index1] > 
            tree[2 * treeNode + 1][index2]) { 

            tree[treeNode].push_back( 
                tree[2 * treeNode + 1][index2] 
                ); 
            index2++; 
        } 
        else { 
            tree[treeNode].push_back( 
                tree[2 * treeNode][index1] 
                ); 
            index1++; 
        } 
    } 
    while (index1 < len1) { 
        tree[treeNode].push_back( 
            tree[2 * treeNode][index1] 
            ); 
        index1++; 
    } 
    while (index2 < len2) { 
        tree[treeNode].push_back( 
            tree[2 * treeNode + 1][index2] 
            ); 
        index2++; 
    } 
    return; 
} 

void build(vector<int> tree[], 
    int* arr, int start, int end, 
                int treeNode) 
{ 
    // Base case 
    if (start == end) { 
        tree[treeNode].push_back( 
            arr[start]); 
        return; 
    } 
    int mid = (start + end) / 2; 

    // Building the left tree 
    build(tree, arr, start, 
        mid, 2 * treeNode); 

    // Building the right tree 
    build(tree, arr, mid + 1, end, 
                2 * treeNode + 1); 

    // Merges the right tree 
    // and left tree 
    merge(tree, treeNode); 
    return; 
} 

// Function similar to query() method 
// as in segment tree 
int query(vector<int> tree[], int treeNode, int start, int end, int left, int right) { 
    // Current segment is out of the range 
    if (start > right || end < left) { 
        return 0; 
    } 
    if (start >= left && end <= right) { 
        return tree[treeNode].end() - 
        upper_bound(tree[treeNode].begin(), 
            tree[treeNode].end(), right); 
    } 

    int mid = (start + end) / 2; 

    // Query on the left tree 
    int op1 = query(tree, 2 * treeNode, 
            start, mid, left, right); 
    // Query on the Right tree 
    int op2 = query(tree, 2 * treeNode + 1, 
            mid + 1, end, left, right); 
    return op1 + op2; 
} 

int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q; cin>>n>>q;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int next_right[n]; 
    vector<int> tree[4 * n]; 

    map<int, int> ump; 
    for (int i = n - 1; i >= 0; i--) { 
        if (ump[arr[i]] == 0) { 
            next_right[i] = n; 
            ump[arr[i]] = i; 
        } 
        else { 
            next_right[i] = ump[arr[i]]; 
            ump[arr[i]] = i; 
        } 
    } 
    build(tree, next_right, 0, n - 1, 1);  

    while(q--){
        int l,r; cin>>l>>r;
        cout<<query(tree, 1, 0, n-1,l-1, r-1) <<"\n";
    }
    return 0;
} 


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

int gcd(int a, int b) { return (b == 0)? a: gcd(b, a % b); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int A; cin >> A;
  int B; cin >> B;
  int C; cin >> C;

  int D = gcd(A, B);
  string ans = "NO";
  if (C % D == 0) ans = "YES";
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

const int MAX = 50;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){

    ll n;
    cin>>n;

    ll ans;
    ans = n/1.08;

    if(floor((ans -1)*1.08) == n) cout<<ans-1<<endl;
    else if(floor((ans + 1)*1.08) == n) cout<<ans+1<<endl;
    else if(floor(ans*1.08) == n) cout<< ans<<endl;
    else{
        cout<<":("<<endl;
        return 0;
    }
        return 0;

}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(long long i=(l);i<(r);i++)
#define dec(i, l, r)   for(long long i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int h, w;
string c[50];
int d[50][50];

int main() {
    std::ios::sync_with_stdio(false);
    cin >> h >> w;
    int ans = h*w;
    inc(i, 0, h){
        cin >> c[i];
        inc(j, 0, w){
            if(c[i][j] == '#') ans--;
            d[i][j] = INF;
        }
    }

    queue<pair<pair<int, int>, int>> q;
    q.push({{0, 0}, 0});
    while(!q.empty()){
        auto n = q.front();q.pop();
        int i = n.fi.fi;
        int j = n.fi.se;
        int dist = n.se;

        if(d[i][j] != INF) continue;
        d[i][j] = dist;

        inc(k, 0, 4){
            int ni = i + di[k];
            int nj = j + dj[k];
            if(ni >= 0 && ni < h && nj >= 0 && nj < w){
                if(c[ni][nj] == '#') continue;
                q.push({{ni, nj}, dist+1});
            }
        }
    }

    if(d[h-1][w-1] == INF){
        cout << -1 << endl;
        return 0;
    }

    cout << ans - d[h-1][w-1] -1 << endl;

    return 0;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())
C = [0] * N
A = []
ans = []
for i in range(N):
    tmp = [int(i) for i in input().split()]
    C[i] = tmp[0]
    A.append(tmp[1:])

for i in range(1 << N):
    tmp = [0] * M
    money = 0
    flag = True
    for j in range(N):
        if i & (1 << j):
            money += C[j]
            for k in range(M):
                tmp[k] += A[j][k]
    for j in range(M):
        if tmp[j] < X:
            flag = False
            break
    if flag:
        ans.append(money)

if not ans:
    print(-1)
else:
    print(min(ans))

Measured memory_bytes: 74000
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>

using namespace std;

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

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

int trim(int v, int p, int k, const vector<vector<int>>& e, vector<int>& ans) {
    ans[v] = 0;
    for (auto u : e[v]) {
        if (u != p) ans[v] += trim(u, v, k - 1, e, ans);
    }
    if (k < 0) ans[v]++;
    return ans[v];
}

int Solve(int v, const vector<vector<int>>& e, int K) {
    if (e[v].size() == 1) {
        vector<int> ans(e.size());
        return trim(v, -1, min(K, 1 + K / 2), e, ans);
    }
    if (K % 2 == 0) {
        vector<int> ans(e.size());
        return trim(v, -1, K / 2, e, ans);
    }
    vector<int> trim_short(e.size());
    trim(v, -1, K / 2, e, trim_short);
    vector<int> trim_long(e.size());
    trim(v, -1, (K + 1) / 2, e, trim_long);

    /*
    if (v == 0) {
        cout << trim_short << trim_long;
    }
    */

    int short_ans = 0;
    for (auto u : e[v]) short_ans += trim_short[u];
    int min_ans = short_ans;
    for (auto u : e[v]) {
        int cur_ans = short_ans - trim_short[u] + trim_long[u];
        min_ans = min(min_ans, cur_ans);
    }
    return min_ans;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int N, K;
    cin >> N >> K;
    vector<vector<int>> e(N);
    for (int i = 1; i < N; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int ans = N;
    for (int i = 0; i < N; ++i) {
        ans = min(ans, Solve(i, e, K));
    }
    cout << ans;
}


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

int main()
{
    std::size_t numberOfFruit = 0;
    std::size_t numberOfFruitKind= 0;
    std::cin >> numberOfFruit >> numberOfFruitKind;

    std::vector<int> priceList;
    priceList.reserve(numberOfFruitKind);
    for (std::size_t index = 0; index < numberOfFruitKind; ++index)
    {
        int inPrice = 0;
        std::cin >> inPrice;
        priceList.emplace_back(inPrice);
    }
    std::sort(priceList.begin(), priceList.end(), [](int lhs, int rhs)
        {
            return lhs < rhs;
        });

    for (std::size_t index = numberOfFruitKind; index < numberOfFruit; ++index)
    {
        int inPrice = 0;
        std::cin >> inPrice;

        if (inPrice < priceList[numberOfFruitKind - 1])
        {
            priceList[numberOfFruitKind - 1] = inPrice;
            std::sort(priceList.begin(), priceList.end(), [](int lhs, int rhs)
                {
                    return lhs < rhs;
                });
        }
    }

    const int totalPrice = [&priceList]()
    {
        int ret = 0;
        for (int price : priceList)
        {
            ret += price;
        }
        return ret;
    }();
    std::cout << totalPrice << std::endl;
}


Measured memory_bytes: 3152
//                          VIVEK UPADHYAY
//                         MANIT, BHOPAL(M.P)
/**********************************************************************************************/
/**********************************************************************************************/
//                        $$ JAB-TAK TODEGA NHI,
//                           TAB -TAK CHODEGA NHI :D
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<"\n" ;
#define ok cout<<"ok\n" ;
#define dbg(x) cout<<#x<<" = "<<(x)<<"\n";
typedef long long ll;
const int MAXN = 2*1e3 + 10 ;
const int MAX = 1e7 + 1 ;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e18 ;
ll mod = 1e9 + 7;
ll powr(ll a , ll b){ if(b==0) return 1LL ; ll x = powr(a,b/2) ; x = (x*x)%mod ; if(b%2) return ((a%mod)*x)%mod ; return x ;}
ll gcd(ll a , ll b){if(a==0) return b ; return gcd(b%a,a);}
int main () {
    
    int N , K ;
    cin >> N >> K ;
    ll a[N] ;
    for(int i =0 ; i < N ;i++)
        cin >> a[i] ;
    ll dp[N] ;
    dp[0] =0 ;
    for(int i =1 ; i < N ;i++)
    {
        dp[i] = 1e10 ;
        for(int j = i - 1;j>=max(0,i-K);j--)
            dp[i] = min(dp[i] , abs(a[i]-a[j]) + dp[j]) ;
    }
    cout<<dp[N-1]<<endl;
    return 0 ;
}


Measured memory_bytes: 1792
import java.util.*;					
					
public class Main{					
	  public static void main(String[] args) {				
	      Scanner sc = new Scanner(System.in);				
		  int n = sc.nextInt();        //n			
		  int m = sc.nextInt();        //m			
		  int l = sc.nextInt();        //l			
		  long[][] a = new long[n][m];			
		  long[][] b = new long[m][l];			
		  long[][] c = new long[n][l];			
		  			
		  //行列 A			
		  for(int i = 0; i < n; i++){			
		        for(int j = 0; j < m; j++){			
			    a[i][j] = sc.nextInt();		
			    //System.out.print(a[i][j] +" ");		
		        }			
		        //System.out.println(" ");			
		  }			
		  			
		//行列 B			
		  for(int i = 0; i < m; i++){			
		        for(int j = 0; j < l; j++){			
		        b[i][j] = sc.nextInt();			
		        //System.out.print(b[i][j] +" ");			
		        }			
		        //System.out.println(" ");			
		  }			
		  			
		  			
		  //行列 C			
		  for(int i = 0; i < n; i++){			
		        for(int j = 0; j < l; j++){			
		        	for(int k = 0; k < m; k++){		
		        	c[i][j] += a[i][k] * b[k][j];		
		        	//System.out.print(c[i][j] +" ");		
		        	}		
		        	//System.out.println(" ");		
		        }			
		  }			
		  			
		  			
		  //結果出力			
		  for(int i = 0; i < n; i++){			
		        for(int j = 0; j < l; j++){			
		        	if(j == l-1){		
		        	    System.out.print(c[i][j]);		
		        	}else {		
		        		System.out.print(c[i][j] +" ");	
		        	}		
		        }			
		        System.out.println("");			
		  }			
	  }				
}



Measured memory_bytes: 53404
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int H, W, h, w; cin>>H>>W>>h>>w;

    vector<vector<int>> a(H, vector<int>(W, -1000));
    if(H % h != 0){
        cout << "Yes" << endl;
        for(int i=0; i<H; i+=h){
            for(int j=0; j<W; j++){
                a[i][j] = 1000 * h - 1001;
            }
        }

        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout << a[i][j] << " \n"[j == W-1];
            }
        }
    }
    else if(W % w != 0){
        cout << "Yes" << endl;
        for(int i=0; i<W; i+=w){
            for(int j=0; j<H; j++){
                a[j][i] = 1000 * w - 1001;
            }
        }

        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cout << a[i][j] << " \n"[j == W-1];
            }
        }
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long ans;
    ans = 0;
    if(b>0){
        if(d>0){
        if(a>0) ans = b*d;
        else if(c>0) ans = b*d;
        else ans = max(a*c, b*d);
        }
        else{
            if(a<0) ans = a*c;
            else ans = a*d;
        }
    }
    else{
        if(c>0) ans = c*b;
        else ans = a*c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
main(){
  int n,a,b,ans=0;
  cin>>n>>a>>b;
  for(int i=1;i<=n;i++){
    int x=i;
    int sum=0;
    while(x)sum+=x%10,x/=10;
    if(a<=sum&&sum<=b)ans+=i;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t a,b;
  cin>>a>>b;
  int64_t x;
  if(a%2==0){
    if(b%2==0)
      x=b^((b-a)/2%2);
    else
      x=(b-a+1)/2%2;
  }else{
    if(b%2==0)
      x=a^b^((b-a-1)/2%2);
    else
      x=a^((b-a)/2%2);
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <cstdlib>
#define R register
#define IN inline
#define W while
#define gc getchar()
#define ls son[now][0]
#define rs son[now][1]
#define dls dis[now][0]
#define drs dis[now][1]
#define MX 200500
#define ll long long 
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	for (; !isdigit(c); c = gc);
	for (;  isdigit(c); c = gc)
	x = (x << 1) + (x << 3) + c - 48;
}
template <class T> IN T max(T a, T b) {return a > b ? a : b;}
template <class T> IN T min(T a, T b) {return a < b ? a : b;}
FILE* fl;
int n, cnt;
ll bd;
struct INFO {ll din, dout;};
IN bool cmp1(const INFO &x, const INFO &y) {return x.dout < y.dout;}
IN bool cmp2(const INFO &x, const INFO &y) {return x.din == y.din ? x.dout < y.dout : x.din < y.din;}
struct Edge {int to, len, nex;} edge[MX << 1];
std::vector <INFO> stat[MX];
int head[MX], son[MX][2], dis[MX][2];
ll mn[MX];
IN void add(R int from, R int to, R int len)
{edge[++cnt] = {to, len, head[from]}, head[from] = cnt;}
void DFS(R int now, R int fa)
{
	for (R int i = head[now]; i; i = edge[i].nex)
	{
		if (edge[i].to == fa) continue;
		if (!ls) DFS(ls = edge[i].to, now), dls = edge[i].len;
		else if (!rs) DFS(rs = edge[i].to, now), drs = edge[i].len;
	}
}
void solve(std::vector <INFO> &l, std::vector <INFO> &r, std::vector <INFO> &res, R int id)
{
	if (l.size() > r.size()) std::swap(l, r);
	int lsiz = l.size(), rsiz = r.size(), cur;
	if (!lsiz) return;
	std::sort(l.begin(), l.end(), cmp1);//dout inc
	std::sort(r.begin(), r.end(), cmp2);//din inc
	mn[0] = r[0].dout; cur = rsiz - 1;
	for (R int i = 1; i < rsiz; ++i) mn[i] = min(mn[i - 1], r[i].dout);
	for (R int i = 0; i < lsiz; ++i)
	{
		W ((~cur) && l[i].dout + r[cur].din > bd) --cur;
		if (~cur) res.push_back({l[i].din, mn[cur]});
	}
	for (R int i = 0; i < lsiz; ++i) std::swap(l[i].din, l[i].dout);
	for (R int i = 0; i < rsiz; ++i) std::swap(r[i].din, r[i].dout);
	std::sort(l.begin(), l.end(), cmp1);
	std::sort(r.begin(), r.end(), cmp2);
	mn[0] = r[0].dout; cur = rsiz - 1;
	for (R int i = 1; i < rsiz; ++i) mn[i] = min(mn[i - 1], r[i].dout);
	for (R int i = 0; i < lsiz; ++i)
	{
		W ((~cur) && l[i].dout + r[cur].din > bd) --cur;
		if (~cur) res.push_back({mn[cur], l[i].din});
	}
}
void DFS(R int now)
{
	stat[now].clear();
	if (!ls) return stat[now].push_back({0, 0}), void();
	DFS(ls); DFS(rs);
	for (R int i = stat[ls].size() - 1; ~i; --i) stat[ls][i].din += dls, stat[ls][i].dout += dls;
	for (R int i = stat[rs].size() - 1; ~i; --i) stat[rs][i].din += drs, stat[rs][i].dout += drs;
	solve(stat[ls], stat[rs], stat[now], now);
}
IN bool check(R ll v)
{
	bd = v; DFS(1);
	return stat[1].size();
}
int main(void)
{
	in(n); int foo, bar;
	ll lef = 0, rig = 1e10, mid, ans;
	for (R int i = 2; i <= n; ++i)
	in(foo), in(bar), add(foo, i, bar), add(i, foo, bar);
	DFS(1, 0);
	W (lef <= rig)
	{
		mid = lef + rig >> 1;
		if (check(mid)) ans = mid, rig = mid - 1;
		else lef = mid + 1;
	}
	printf("%lld", ans);
}

Measured memory_bytes: 35316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, max_val, val;
  max_val = 0;
  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++){
    cin >> blue.at(i);
  }
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++){
    cin >> red.at(i);
  }
  
  for (int b_i = 0; b_i < N; b_i++){
    val = 0;
    string s = blue.at(b_i);
    for (int p = 0; p < N; p++){
      if (s == blue.at(p)){
        val++;
      }
    }
    for (int p = 0; p < M; p++){
      if (s == red.at(p)){
        val--;
      }
    }
    if (max_val < val){max_val = val;}
  }
  cout << max_val << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1e9+7;
ll a[105], dp[maxn];
void dodaj(ll& a, ll b){
    a+=b;
    if(a>=mod)a-=mod;
}
void oduzmi(ll& a, ll b){
    a-=b;
    if(a<0)a+=mod;
}
int main()
{
    ll n, k;
    cin >> n >> k;
    for(ll i=0;i<n;i++)cin >> a[i];
    dp[0]=1;
    for(ll i=0;i<n;i++){
        vector<ll> cnt(k+1,0);
        for(ll j=k;j>=0;j--){
            ll l=j+1, r=j+min(a[i],k-j);
            if(l<=r){
                dodaj(cnt[l],dp[j]);
                if(r+1<=k)oduzmi(cnt[r+1],dp[j]);
            }
        }
        ll ps=0;
        for(int j=0;j<=k;j++){
            dodaj(ps,cnt[j]);
            dodaj(dp[j],ps);
        }
    }
    cout << dp[k] << endl;
    return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

count = [0 for _ in range(n)]
for i in reversed(range(1, n + 1)):
    tmp = 0
    for j in range(i, n+1, i):
        tmp += count[j-1]
    #print(tmp)
    if a[i-1] % 2 != tmp % 2:
        count[i-1] += 1
#print(count)
m = sum(count)
ans = []
for i in range(n):
    if count[i] == 1:
        ans.append(str(i+1))

print(m)
print(' '.join(ans))


Measured memory_bytes: 17212
let rec check num min_num x y =
  if num = min_num then "War"
  else if x < num && num <= y then "No War"
  else check (num-1) min_num x y
let () =
  let (n, m, x, y) = Scanf.scanf "%d %d %d %d\n" (fun a b c d -> (a, b, c, d)) in
  let xlst = Array.to_list (Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x))) in
  let ylst = Array.to_list (Array.init m (fun _ -> Scanf.scanf "%d " (fun x -> x))) in
  let max_x = List.fold_left max min_int xlst in
  let min_y = List.fold_left min max_int ylst in
  Printf.printf "%s\n" (check y (x+1) max_x min_y)

Measured memory_bytes: 4480
package main

import "fmt"

func myMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	sum := 0
	for _, x := range xs {
		sum += 2 * myMin(x, k - x)
	}
	fmt.Println(sum)
}



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

using ll = long long;
using namespace std;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);

#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}


void init();
void solve();

signed main()
{
	init();
	solve();
}

void init()
{
	ll N, M;
	cin >> N >> M;
	vector<pair<ll, ll>> A;
	rep(i, N) {
		ll a, b;
		cin >> a >> b;
		A.PB(MP(a, b));
	}
	sort(all(A));
	ll cnt = 0;
	ll res = 0;
	rep(i, N) {
		cnt += A[i].second;
		if (cnt >= M) {
			cnt -= A[i].second;
			cout << res + (M - cnt) * A[i].first << endl;
			return;
		}
		res += A[i].first * A[i].second;
	}
}


void solve()
{
}




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

int n, m, c;
int B[30];
bool func(int A[30]) {
    int sum = c;
    rep(i, m)  sum += A[i] * B[i];
    if (sum > 0) return true;
    else return false;
}

int main() {
    cin >> n >> m >> c;
    rep(i, m) cin >> B[i];
    
    int A[30][30];
    rep(i, n) rep(j, m) cin >> A[i][j];
    
    int cnt = 0;
    rep(i, n) {
        if (func(A[i])) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
/// Created by Arsenii Kirillov
 
#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#ifndef LOCAL
#  define cerr __get_ce
#endif
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
 
/*
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
//*/
 
int const INF = (int)1e9 + 1e3;
ll const INFL = (ll)1e18 + 1e6;
#ifdef LOCAL
	mt19937 tw(9450189);
#else
	mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }
 
 
void solve() {
	int n;
	cin >> n;
	vector<pair<int, int>> a(n), inter(n);
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first >> a[i].second;
		ans = max(ans, a[i].second - a[i].first + 1);
	}
	for (int qwe = 0; qwe < 2; qwe++)
	{
		sort(all(a));
		inter[n - 1] = a[n - 1];
		for (int i = n - 2; i >= 0; i--)
		{
			inter[i].first = max(inter[i + 1].first, a[i].first);
			inter[i].second = min(inter[i + 1].second, a[i].second);
		}
		int le = a[0].first, ri = a[0].second;
		for (int i = 0; i + 1 < n; i++)
		{
			le = max(le, a[i].first);
			ri = min(ri, a[i].second);
			ans = max(ans, max(0, ri - le + 1) + max(0, inter[i + 1].second - inter[i + 1].first + 1));
			if (i + 2 < n)
				ans = max(ans, a[i + 1].second - a[i + 1].first + 1 + max(0, min(ri, inter[i + 2].second) - max(le, inter[i + 2].first) + 1));
		}
		for (int i = 0; i < n; i++)
		{
			a[i].first *= -1;
			a[i].second *= -1;
			swap(a[i].first, a[i].second);
		}
	}
	cout << ans << endl;
}
 
 
int main() {
#ifdef LOCAL
	clock_t start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	cout << setprecision(15) << fixed;
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int test_count = 1;
	//cin >> test_count;
	for (int test = 1; test <= test_count; ++test) {
		solve();
	}
 
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}

Measured memory_bytes: 1792
H, W = map(int, input().split())
s = [input() for i in range(H)]
cs = []
count = 0

dx = [1, 1, 0, -1, -1, -1, 0, 1]
dy = [0, 1, 1, 1, 0, -1, -1, -1]

for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            for k in range(8):
                if 0 <= i+dy[k] < H and 0 <= j+dx[k] < W:
                    if s[i+dy[k]][j+dx[k]] == '#':
                        count += 1
                    else:
                        pass
                else:
                    pass
            cs.append(str(count))
            count = 0
        else:
            cs.append('#')

for i in range(1, H*W+1):
    print(cs[i-1], end='')
    if i % W == 0 and i % (H*W) != 0:
        print('\n')


Measured memory_bytes: 3572
#include<stdio.h>
int main(void){
	int H, W;
	int i, j;
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			break;
		}
		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				if(j == (W - 1)){
					printf("#\n");
				}else{
					printf("#");
				}
			}
		}
		printf("\n");
	}
	return 0;
}

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

using namespace std;

#define N 420000
#define LL long long

const LL mod=998244353;
LL n,m,ans,pw[N],f[N],g[N],fac[N],ifac[N];
char a[N],b[N],c[N],d[N];
bool chk;

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

LL C(LL x,LL y){if (y<0){if (x<0) return 1; return 0;} return fac[x]*ifac[y]%mod*ifac[x-y]%mod;}

void solve(LL n,LL m,char a[],char b[],char c[],char d[]){
	memset(f,0,sizeof f); memset(g,0,sizeof g);
	LL l=0,r=0,sum=0,sum2=0,cnt=0,cnt2=0,tmp=0;
	for (LL i=1;i<=m;i++){
		if (c[i]=='1') l++;
		if (d[i]=='1') r++;
	}
	for (LL i=1;i<=n;i++){
		if (a[i]=='1') sum++;
		if (b[i]=='1') sum++;
		if (a[i]=='1' && b[i]=='1') sum2++;
	}
	if (a[1]=='1'||b[1]=='1') f[0]=1;
	if (a[n]=='1'||b[n]=='1') tmp=g[n+1]=pw[sum2];
	for (LL i=1;i<=n;i++){
		if (i>1&&(a[i-1]=='1'||b[i-1]=='1')) g[i]=C(sum-cnt+r-1,r-1)*pw[cnt2]%mod;
		tmp=(tmp+g[i])%mod;
		if (a[i]=='1') cnt++;
		if (b[i]=='1') cnt++;
		if (a[i]=='1' && b[i]=='1') cnt2++;
		if (i<n&&(a[i+1]=='1'||b[i+1]=='1')) f[i]=C(cnt+l-1,l-1)*inv(pw[cnt2])%mod;
	}
	for (LL i=1;i<=n;i++){
		tmp=(tmp-g[i]+mod)%mod;
		ans=(ans+f[i-1]*tmp)%mod;
	}
}

int main(){
	scanf("%lld%lld",&n,&m);
	scanf("%s%s%s%s",a+1,b+1,c+1,d+1);
	for (int i=1;i<=n;i++) chk|=(a[i]=='1')|(b[i]=='1');
	for (int i=1;i<=m;i++) chk|=(c[i]=='1')|(d[i]=='1');
	if (!chk){puts("1"); return 0;}
	pw[0]=1; for (LL i=1;i<N;i++) pw[i]=pw[i-1]*2%mod;
	fac[0]=1; for (LL i=1;i<N;i++) fac[i]=fac[i-1]*i%mod;
	ifac[N-1]=inv(fac[N-1]); for (LL i=N-2;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
	solve(n,m,a,b,c,d);
	solve(m,n,c,d,a,b);
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 17152
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
s=0
for i in range(1,n+1):
    if i%3!=0 and i%5!=0:
        s+=i
print(s)

Measured memory_bytes: 9212
import random as ra
import copy
import time

start_time = time.time()

D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]

### 得点計算用
#t = [int(input()) for i in range(D)]
def cal_point(t):
    score = 0
    last = [0]*26
    for d in range(D):
        score += s[d][t[d]-1]
        last[t[d]-1] = d+1
        for i in range(26):
            score -= c[i]*(d+1-last[i])
    #print(score)
    return score


t = []
last = [0]*26
for i in range(D):
    opt1 = s[i].index(max(s[i]))
    opt2 = last.index(min(last))
    if ra.random()<0.5:
        t.append(opt1+1)
        last[opt1] = i+1
    else:
        t.append(opt2+1)
        last[opt2] = i+1


#t = [ra.randint(1,26) for i in range(D)]
max_score = 0
optimal_t = copy.deepcopy(t)
#M = 10**5
while (time.time()-start_time)<1.95:
#for i in range(M):
    d = ra.randint(1,D)
    q = ra.randint(1,26)
    td = t[d-1]
    t[d-1] = q
    now = cal_point(t)
    if now > max_score:
        optimal_t = copy.deepcopy(t)
        max_score = now
    else:
        t[d-1] = td

print(*optimal_t,sep='\n')


Measured memory_bytes: 10072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 5;
int main() {
	int n, k;
	cin >> n >> k;
	vector<int> stones(n);
	for(int i = 0; i < n; ++i) {
		cin >> stones[i];
	}
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j <= i + k; ++j) {
			if (j < n) {
				dp[j] = min(dp[i] + abs(stones[i] - stones[j]), dp[j]);
			}
		}
	}
	cout << dp[n - 1] << '\n';
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

        int n = sc.nextInt();
        int a = n;
        int sn = 0;

        do{
            sn += a % 10;
            a /= 10;
        }while(a > 0);

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

    }
}

Measured memory_bytes: 22100
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(4, 3), '3333')

    def test_2(self):
        self.assertEqual(think(7, 7), '7777777')


def solve():
    a, b = read()
    result = think(a, b)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b):
    s_a, s_b = str(a), str(b)
    canditate_a = str(a) * b
    canditate_b = str(b) * a
    return min(canditate_a, canditate_b)


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 51180
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 8005
#define eps 1e-8
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) { res = 0;char c = getchar();T f = 1; while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); } res *= f; }
template<class T>
void out(T x) { if(x < 0) {x = -x;putchar('-');} if(x >= 10) { out(x / 10); } putchar('0' + x % 10); }
const int MOD = 998244353,MAXL = 1 << 14;
int N,M,fac[MAXN * 2],invfac[MAXN * 2],inv[MAXN * 2];
int f[MAXL + 5],g[MAXL + 5],dp[2][MAXN],W[MAXL + 5];
int mul(int a,int b) { return 1LL * a * b % MOD; }
int inc(int a,int b) { return a + b >= MOD ? a + b - MOD : a + b; }
int C(int n,int m) { if(n < m) return 0; return mul(fac[n],mul(invfac[m],invfac[n - m])); }
int fpow(int x,int c) { int res = 1,t = x; while(c) { if(c & 1) res = mul(res,t); t = mul(t,t); c >>= 1; } return res; }
void update(int &x,int y) { x = inc(x,y); }
void FFT(int *p,int L,int on) {
    for(int i = 1 , j = L >> 1 ; i < L - 1 ; ++i) { if(i < j) swap(p[i],p[j]); int k = L >> 1; while(j >= k) { j -= k; k >>= 1; } j += k; }
    for(int h = 2 ; h <= L ; h <<= 1) {
    int wn = W[(MAXL + on * (MAXL / h)) % MAXL];
    for(int k = 0 ; k < L ; k += h) {
        int w = 1;
        for(int j = k ; j < k + h / 2 ; ++j) {
        int u = p[j],t = mul(w,p[j + h / 2]);
        p[j] = inc(u,t);
        p[j + h / 2] = inc(u,MOD - t);
        w = mul(w,wn);
        }
    }
    }
    if(on == -1) {
    int InvL = fpow(L,MOD - 2);
    for(int i = 0 ; i < L ; ++i) p[i] = mul(p[i],InvL);
    }
}
void Solve() {
    read(N);read(M);
    fac[0] = 1; for(int i = 1 ; i <= N + 10 ; ++i) fac[i] = mul(fac[i - 1],i);
    invfac[N + 10] = fpow(fac[N + 10],MOD - 2); for(int i = N + 9 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
    W[0] = 1;W[1] = fpow(3,(MOD - 1) / MAXL); for(int i = 2 ; i < MAXL ; ++i) W[i] = mul(W[i - 1],W[1]);
    int cur = 0; for(int i = 0 ; i <= N ; ++i) dp[cur][i] = 1; for(int i = 1 ; i <= N ; ++i) g[i] = invfac[i + 2];
    int L = 1; while(L <= 2 * N) L <<= 1;
    FFT(g,L,1);
    for(int i = 2 ; i <= M ; ++i) {
    memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1]));
    for(int j = 0 ; j <= N ; ++j) { update(dp[cur ^ 1][j],mul(dp[cur][j],inc(C(j + 1,2),1))); }
    memset(f,0,sizeof(f)); for(int j = 0 ; j <= N ; ++j) f[j] = mul(dp[cur][j],invfac[j]);
    FFT(f,L,1); for(int j = 0 ; j < L ; ++j) f[j] = mul(f[j],g[j]); FFT(f,L,-1);
    for(int j = 0 ; j <= N ; ++j) { update(dp[cur ^ 1][j],mul(f[j],fac[j + 2])); }
    cur ^= 1;
    }
    int ans = 0;
    for(int i = 0 ; i <= N ; ++i) { update(ans,mul(C(N,i),dp[cur][i])); }
    out(ans);enter;
}
int main() {
    Solve();
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <queue>

using namespace std;

int main() {
    int n;
    int ans = 0;
    priority_queue<int> que;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        que.push(a);
    }
    int i = 0;
    while(!que.empty()) {
        if (i % 2) {
            ans -= que.top();
            que.pop();
        } else {
            ans += que.top();
            que.pop();
        }
        i++;
    }
    printf("%d\n", ans);
    return 0;
}


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

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

  rep(i, 5) {
    int o100 = x / 100, u100 = x % 100;
    // cerr << i << " " << o100 << " " << u100 << endl;
    int num = min(o100, u100 / (5 - i));
    // cerr << i << 'b' << endl;
    x -= (105 - i) * num;
    // cerr << i << 'c' << endl;
  }
  if (x % 100 == 0)
    cout << '1' << endl;
  else
    cout << '0' << endl;
  return 0;
}


Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
long long
fMain(
)
{
	char lc1Buf[1024];

	// N - 取得
	long long llN;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld", &llN);

	// 奇数
	if (llN % 2 == 1) {
		return 0;
	}

	// 10の倍数の数
	long long llCnt = llN / 10;

	// 50の倍数以降
	long long llRate = 50;
	while (llN >= llRate) {
		llCnt += llN / llRate;
		llRate *= 5;
	}

	return llCnt;
}

// １回実行
int
fOne(
)
{
	long long llRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	llRet = fMain();

	// 出力
	sprintf(lc1Buf, "%lld\n", llRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1768
#include <stdio.h>
#include <math.h>
int nmax=50000;
int pr[50000]={0};
int comb[50001]={0};

int main(void) {
	int i,p,j,n;
	for(i=2;i<nmax;i++){
		if (i!=2 && i%2==0){
			pr[i-2]=0;
		}
		else{
			pr[i-2]=i;
		}
	}
	for (p=0;p<sqrt(nmax);p++){
		if(!pr[p]){continue;}
		for(i=p+1;i<nmax;i++){
			if (pr[i]%(p+2)==0){pr[i]=0;}
		}
	}
	for(j=0;j<nmax;j++){
		for(i=j;i<nmax;i++){
			if (pr[i]+pr[j]<=50000 && pr[i] && pr[j]){
				comb[pr[i]+pr[j]]++;
			}
		}
	}
	while(1){
		scanf("%d",&n);
		if(!n){break;}
		printf("%d\n",comb[n]);
	}
	return 0;
}


Measured memory_bytes: 2108
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Map<String, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			String s = br.readLine();
			if (map.containsKey(s)) {
				map.put(s, map.get(s) + 1);
			} else {
				map.put(s, 1);
			}
		}
		br.close();

		int max = 0;
		for (int i : map.values()) {
			max = Math.max(max, i);
		}

		List<String> list = new ArrayList<>();
		for (String s : map.keySet()) {
			if (map.get(s) == max) {
				list.add(s);
			}
		}
		Collections.sort(list);

		for (String s : list) {
			System.out.println(s);
		}
	}
}


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


using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  srand((unsigned)time(NULL));
  int d;
  int res = 0;
  cin >> d;
  vector<int> c(26);
  rep(i,26)cin >> c[i];
  vector<vector<int>> v(d,vector<int>(26));
  vector<int> contest(d,0);
  vector<int> last(26,0);
  vector<int> satisfy(26,0);
  rep(i,d)rep(j,26){
    int x;cin >> x;
    v[i][j] = x;
  }
  for(int i = 1;i <= d;i++){
    rep(j,26)if(v[i-1][contest[i-1]] < v[i-1][j])contest[i-1] = j;
    last[contest[i-1]] = i;
    res += v[i-1][contest[i-1]];
    rep(j,26)res -= c[j]*(i-last[j]),satisfy[j] += c[j]*(i-last[j]);
  }
  while(1.0*clock()/CLOCKS_PER_SEC <= 1.7){
    //int now_time = clock();
    //if(1.0*now_time/CLOCKS_PER_SEC > 1.7)break;
    int day = rand()%d,pos = rand()%26;
    vector<int> new_contest = contest;
    int res_ = res;
    int pre = new_contest[day];
    res_ += satisfy[pos];
    res_ += satisfy[pre];
    res_ -= v[day][pre];
    res_ += v[day][pos];
    int pos_satisfy = 0,pre_satisfy = 0;
    last[pos] = last[pre] = 0;
    new_contest[day] = pos;
    for(int i = 1;i <= d;i++)last[pos] = (new_contest[i-1] == pos ? last[pos] = i : last[pos]),pos_satisfy += c[pos]*(i-last[pos]);
    for(int i = 1;i <= d;i++)last[pre] = (new_contest[i-1] == pre ? last[pre] = i : last[pre]),pre_satisfy += c[pre]*(i-last[pre]);
    res_ -= (pos_satisfy+pre_satisfy);
    if(res < res_){
      res = res_;
      contest = new_contest;
      satisfy[pre] = pre_satisfy;
      satisfy[pos] = pos_satisfy;
    }
  }
  rep(i,d)cout << contest[i]+1 << endl;
  


  return 0;
}


Measured memory_bytes: 3716