akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk(a , b) { min((a) , (b)) , max((a) , (b)) }
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353
#define meme(x) memset((x), 0, sizeof((x)))
#define memo(x) memset((x),-1, sizeof((x)))
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

// #define int ll

ll egcd(ll a, ll b, ll &x, ll &y){
    if (a == 0LL){  
        x = 0LL;  
        y = 1LL;  
        return b;  
    }
    ll xx, yy;
    ll val = egcd(b % a, a, xx, yy);  
    x = yy - (b / a) * xx;  
    y = xx;  
    return val;
}

ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

//  ==========     //\\       //||     ||====//||
//      ||        //  \\        ||     ||   // ||
//      ||       //====\\       ||     ||  //  ||
//      ||      //      \\      ||     || //   ||
//  ========== //        \\  ========  ||//====|| 
//  code

vector<int> dp;
vector< vector<int> > adj;
vector< bool > vis;

int dfs(int node){
    if(adj[node].size() == 0)
        return 0;

    if(dp[node])
        return dp[node];

    for(auto i : adj[node]){
        if(!vis[i]){
            vis[i] = true;
            dfs(i);
        }
        dp[node] = max(dp[node], 1 + dfs(i));
    }
    return dp[node];
}

void solve(){
    int n,m,i,j,k,l,p;
    cin >> n >> m;
    adj.resize(n + 1);
    vis.resize(n + 1, false);
    dp.resize(n + 1, 0);

    for(i = 0; i < m; i++){
        cin >> j >> k;
        adj[j].pb(k);
    }

    for(i = 1; i <= n; i++){
        if(!vis[i]){
            vis[i] = true;
            dfs(i);
        }
    }

    cout << *max_element(all(dp)) << endc;
}

int32_t main(){
    init;
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 12344
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	function<void(int,int)> tensi_no_3p=[&](int v,int d){
	};
	string S;
	cin >> S;
	int len = S.size();
	if (len < 26) {
		vint app(26);
		rep(i, len) app[S[i] - 'a']++;
		rep(i, 26) if (app[i] == 0) {
			cout << S;
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	else {
		string T = S;
		if (! next_permutation(T.begin(), T.end())) {
			cout << -1 << endl;
			return 0;
		}
		rep(i, 26) if (S[i] != T[i]) {
			T.resize(i + 1);
			cout << T << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> P1;
typedef pair<P,P> P2;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define INF 1000000000
#define mod 1000000007
#define MAX5 100001

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

// cout << setfill('0') << setw(5) << number < endl;
// while(getline(cin, s)) { .. } | `s` is a string


const int N = 10000000;
// int lp[N+1];
// vector<int> pr;

// void si() {
// 	for (int i=2; i<=N; ++i) {
// 	    if (lp[i] == 0) {
// 	        lp[i] = i;
// 	        pr.push_back (i);
// 	    }
// 	    for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
// 	        lp[i * pr[j]] = pr[j];
// 	}
// }

// bool notPrime(int n) {
// 	auto iter = lower_bound(pr.begin(), pr.end(), n);
// 	return !(iter != pr.end() && *iter == n);
// }

// vector<int> pr;

// void sivOld() {
// 	std::vector<bool> primes(N, true);
// 	vector<char> is_prime(N+1, true);
// 	is_prime[0] = is_prime[1] = false;
// 	for (int i = 2; i <= N; i++) {
// 	    if (is_prime[i] && (long long)i * i <= N) {
// 	    	pr.push_back(i);
// 	        for (int j = i * i; j <= N; j += i)
// 	            is_prime[j] = false;
// 	    }
// 	}
// }

// int gcd(int a, int b) {
// 	while (b != 0) {
// 		int old_a = a;
// 		int old_b = b;

// 		a = old_b;
// 		b = old_a % old_b;
// 	}

// 	return a;
// }

// int returnPrime(int num, int a) {
// 	// cout << "?" << endl;
// 	for (int i = 0; i < pr.size(); ++i) {
// 		if (gcd(num, pr[i]) == 1 && gcd(a, pr[i]) == 1)
// 			return pr[i];
// 	}
// 	return -1;
// }


void solve() {
	const auto PI = std::acos(-1);
	double a, b, h, m;
	cin >> a >> b >> h >> m;

	double angle = abs(((h + m/60) * (360/12)) - (m * (360 / 60)));
	// cout << "angle : " << angle << endl;
	cout << setprecision(18) << sqrt(a * a + b * b - 2 * a * b * cos(angle*PI/180)) << endl; 


}

int main(){
	IOS;
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif
	    // return 0;
	    // cout << "gcd(10, 15) : " << gcd(1, 1) << endl;
	
	int t;
	solve();
}

/*
11 
4 4 
-2 -2 
-3 -4 
-1 3 
2 3 
-4 0 
1 1 
-1 -1 
3 -1 
-4 2 
-2 4
*/

















Measured memory_bytes: 4180
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        cout << n << " ";  
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
   
    long long int n1,m1,t;
 //  cin>>t;
   t=1;
    while(t--)
    {
   long long int i,j;
 //long long int b[1000000];
 //set<long long int >s;
       long long int f=1,p=0,z,o=0;
       double pie=3.141592653589793238;
    long long int c=0,n,m,l=0,r=0,k,min1=10000000000000,max2=-100;
 cin>>n>>m>>k;
 p=k;
 while(k<=m)
 {
     if(k>=n)
     c++;
     k=k+p;
 }
 cout<<c;
 /*long long int a[n];
 for(i=0;i<n;i++)
 cin>>a[n];
 */
 
 
 }
 return 0;
}


Measured memory_bytes: 3556
///
// File:  1346.cpp
// Author: ymiyamoto
//
// Created on Sun Nov 26 02:53:16 2017
//

#include <cstdint>
#include <iostream>
#include <stack>
#include <string>

using namespace std;

uint32_t mult_first(string exp)
{
  stack<int32_t> stack;
  for (uint32_t i = 0; i < exp.size(); i++) {
    if (i % 2 == 0) {
      uint32_t val = exp[i] - '0';
      stack.push(val);
    } else {
      char op = exp[i];
      if (op == '*') {
        i++;
        uint32_t val1 = stack.top();
        stack.pop();
        uint32_t val2 = exp[i] - '0';
        stack.push(val1 * val2);
      }
    }
  }

  uint32_t result = 0;
  while (!stack.empty()) {
    result += stack.top();
    stack.pop();
  }
  return result;
}

uint32_t left_to_right(string exp)
{
  uint32_t result = exp[0] - '0';

  uint32_t index = 1;
  while (index < exp.size()) {
    uint32_t val = exp[index + 1] - '0';
    if (exp[index] == '+') {
      result += val;
    } else {
      result *= val;
    }
    index += 2;
  }
  return result;
}

int32_t main()
{
  string exp;
  cin >> exp;
  uint32_t n;
  cin >> n;

  uint32_t result1 = mult_first(exp);
  uint32_t result2 = left_to_right(exp);

  if (result1 == n && result2 == n) {
    cout << "U" << endl;
  } else if (result1 == n) {
    cout << "M" << endl;
  } else if (result2 == n) {
    cout << "L" << endl;
  } else {
    cout << "I" << endl;
  }
  return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;

ll N;
ll A[200000];
map<ll,ll> cnt;
map<ll,ll> m;

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];
    rep(i,N) cnt[A[i]]++;

    sort(A,A+N);

    ll ans=0;
    rep(i,N){
        if(cnt[A[i]]==1 && m[A[i]]==0){
            ans++;
            for(int j=1;j*A[i]<=A[N-1];j++){
                m[j*A[i]]++;
            }
        }else if(cnt[A[i]]>1 && m[A[i]]==0){
            for(int j=1;j*A[i]<=A[N-1];j++){
                m[j*A[i]]++;
            }
        }
    }

    cout<<ans<<endl;
}

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

using namespace std;

#define INF 1e9
typedef pair<int,int> pii;

int N,C[4][4];
pii stamp[16];

inline int stp(int x,int y,int px,int py,int c,int S){
  for(int i = max(0,py) ; i < min(py+y,4) ; i++){
    for(int j = max(0,px) ; j < min(px+x,4) ; j++){
      int b = i*4+j;
      if(C[i][j] == c){
        if((S >> b) & 1) continue;
        S |= (1<<b);
      }else{
        if((S >> b) & 1){
          S -= (1<<b);
        }
      }
    }
  }
  return S;
}

int solve(){
  queue<int> Q;
  Q.push(0);
  int dist[1<<16];
  fill(dist,dist+(1<<16),INF);
  dist[0] = 0;

  while(!Q.empty()){
    int S = Q.front(); Q.pop();
    if(S == (1<<16)-1){
      return dist[S];
    }
    for(int i = 0 ; i < N ; i++){
      pii p = stamp[i];
      int x = p.second, y = p.first;
      for(int j = 0 ; j < 3 ; j++){
        for(int px = -x+1 ; px < 4 ; px++){
          for(int py = -y+1 ; py < 4 ; py++){
            int nS = stp(x,y,px,py,j,S);
            if(dist[S]+1 < dist[nS]){
              dist[nS] = dist[S] + 1;
              Q.push(nS);
            }
          }
        } 
      }
    }
  }
  return -1;
}

int change(char ch){
  if(ch == 'R') return 0;
  if(ch == 'B') return 1;
  return 2;
}

int main(){
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> stamp[i].first >> stamp[i].second;
  }
  char in;
  for(int i = 0 ; i < 4 ; i++){
    for(int j = 0 ; j < 4 ; j++){
      cin >> in;
      C[i][j] = change(in);
    }    
  }
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 1608
# coding:utf-8
n,m,l = map(int, raw_input().split())
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for i in range(l)] for j in range(m)]
c = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
    a[i] = map(int, raw_input().split())
for i in range(m):
    b[i] = map(int, raw_input().split())
for i in range(len(a)):
    for j in range(len(b[0])):
        for k in range(len(b)):
            c[i][j] += a[i][k] * b[k][j]
        else:
            print c[i][j],
    else:
        print



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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W));
    rep(i, H) {
        rep(j, W) {
            cin >> A[i][j];
        }
    }

    vector<int> B;
    vector<pair<int, int>> X;
    for (int i = 0; i < H; i++) {
        // 右から左に移動する
        if (i % 2 == 0) {
            for (int j = 0; j < W; j++) {
                B.push_back(A[i][j]);
                X.push_back(make_pair(i, j));
            }
        }
        // 左から右に移動する
        else {
            for (int j = W - 1; j >= 0; j--) {
                B.push_back(A[i][j]);
                X.push_back(make_pair(i, j));
            }
        }
    }

    int cnt = 0;
    vector<string> ans;
    rep(i, H * W - 1) {
        if (B[i] % 2 != 0) {
            B[i]--;
            B[i + 1]++;
            cnt++;

            ans.push_back(
                to_string(X[i].first + 1) + " " + to_string(X[i].second + 1) + " " + to_string(X[i + 1].first + 1) + " " + to_string(X[i + 1].second + 1)
            );
        }
    }

    cout << cnt << endl;
    rep(i, ans.size()) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 11436
#include <stdio.h>

int main(void){
  int N, L, sum=0, max;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&L);
    sum+=L;
    if(L>max) max=L;
  }
  if(sum - max > max) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
n = int(input())
points = 0
sides = 0
for i in range(1,n+1):
    points += i*(n-i+1)
for _ in range(n-1):
    u,v = map(int,input().split())
    if u > v:
        u,v = v,u
    sides += u*(n-v+1)
print(points-sides)    

Measured memory_bytes: 9124
// 挿入ソートをC++で実装する
#include<iostream>
using namespace std;

void trace(int A[], int N)
{
    for(int i = 0; i < N; i++)
    {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void InsersionSort(int A[], int N)
{
    int i, j, v;
    for (i = 1; i < N; i++)
    {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A, N);
    }
}

int main()
{
    int N, j;
    int A[100];

    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    trace(A, N);
    InsersionSort(A, N);

    return 0;
}


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

int main()
{
    long long h;
    cin >> h;

    long long sum = 0;
    long long prevMonsterNum = 1;
    while (h > 0)
    {
        h /= 2;
        sum += prevMonsterNum;

        prevMonsterNum *= 2;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#include <random>
#include <map>
#include <math.h>
#pragma warning(disable : 4996)

int main(void) {
	long long x;
	scanf("%lld", &x);
	long long op = (long long)(x / 11 + 0.5)*2;
	if (x % 11 != 0) {
		if (x % 11 > 6) {
			op += 2;
		} else{
			op += 1;
		}
	}
	printf("%lld", op);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
#include<complex>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;
// typedef complex<double, double> Complex;
//実部も虚部もdoubleとなる複素数型を使う
typedef complex<double> Complex;
// したの方を利用

const double PI = acos(-1);

vector<Complex> fft(vector<Complex> A, int n, int sgn = 1) {
        //係数の列Aを受け取って、1の(2^n)乗根の0乗から((2^n)-1)乗根までを、
        //列Aを係数とした多項式に代入した答えを返す
        //1のN乗根は複素数になるので、係数は複素数になる　たとえ最終的な答えが実数であったとしても

	if (n == 1)return A;
        //前での説明通り、1つしか係数がない式は定数なので、それを返す

        vector<Complex> f0, f1;
	for (int i = 0; i < (n / 2); i++) {
		f0.push_back(A[i * 2 + 0]);
		f1.push_back(A[i * 2 + 1]);
	}
        //奇数番目と偶数番目に係数を分けて、二つのサイズが半分の係数列に分ける。

	f0 = fft(f0, n / 2, sgn), f1 = fft(f1, n / 2, sgn);
        //解説通り、二つの係数列となるものを再帰的に求める。DFSの順番で(再帰関数を使ってるのでそれはそう)
        //もともとf0, f1は係数列だけど、それを関数の答え、つまり二つの半分のサイズの列に代入した答えの配列に再利用

	Complex zeta = Complex(cos(2.0 * PI / n), sin(2.0 * PI / n) * sgn);
	Complex pow_zeta = 1;
        //(2^n)-1次の式となるので、(2^n)個の1のn乗根を用意して計算しなければならない。

	for (int i = 0; i < n; i++) {
		A[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
		pow_zeta *= zeta;
        }
        //あらかじめ再帰して求めた二つのサイズ半分の係数列の関数に、1のn乗根を代入して、f(x)=f_0(x^2)+x*f_1(x)のとおりに計算する。
        //再帰で求めた配列は2^(n - 1)の長さで、Atcoder社のスライドの考察通り、後半部分は前半部分と同じなので、このように計算してる。
	return A;
}

vector<Complex> inv_fft(vector<Complex> A, int n) {
	auto ret = fft(A, n, -1);
	for (int i = 0; i < n; i++) {
		ret[i] /= n;
	}
	return ret;
}

vector<Complex> multiply(vector<Complex> &X, vector<Complex> &Y) {
	int n = 1;
	while (n < (X.size() + Y.size() + 1)) n *= 2;

	vector<Complex> ret;

	X.resize(n), Y.resize(n);
	X = fft(X, n, 1),
	Y = fft(Y, n, 1);

	for (int i = 0; i < n; i++) {
		ret.push_back(X[i] * Y[i]);
	}
	return inv_fft(ret, n);
}


int main(){
  ll N, M; cin >> N >> M;
  vector<Complex> A ,B;
  A.pb(Complex()); B.pb(Complex());
  map<ll,ll> m;
  ll amax = 0;
  rep(i,N){
    ll a; cin >> a;
    amax = max(amax , a);
    m[a]++;
  }
  repn(i,amax){
    A.pb(Complex(m[i])); B.pb(Complex(m[i]));
  }
  ll ans = 0;
  auto tmp = multiply(A , B);
  for(ll i = amax * 2 ; i > 0 ; i--){
    if(M <= 0) break;
    ll cnt = (ll)(tmp[i].real() + 0.5);
    if(cnt > 0){
      ans += i * min(cnt , M);
      M -= cnt;
    }
  }
  cout << ans << endl;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


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



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

  int l = stoi(s.substr(0, 2));
  int r = stoi(s.substr(2, 2));

  bool lm = 1 <= l && l <= 12;
  bool rm = 1 <= r && r <= 12;


  if(lm && rm){
    cout << "AMBIGUOUS" << endl;
  }
  else if(lm){
    cout << "MMYY" << endl;
  }
  else if(rm){
    cout << "YYMM" << endl;
  }
  else{
    cout << "NA" << endl;
  }
  



  
  return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		String s = "";
		while(in.hasNext()) s += in.next()+" ";

		int ans = 0;
		for (int i=s.length()-1; i>=0; i--) {
			int d = 1, t = 0;
			while (i>=0 && '0' <= s.charAt(i) && s.charAt(i) <= '9') {
				t += (s.charAt(i)-'0')*d;
				d *= 10;
				i--;
			}
			ans += t;
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 26344
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BStringPalindrome solver = new BStringPalindrome();
        solver.solve(1, in, out);
        out.close();
    }

    static class BStringPalindrome {
        PrintWriter out;
        InputReader in;

        boolean is_palin(String s) {
            int n = s.length();
            boolean ok = true;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) != s.charAt(s.length() - i - 1))
                    ok = false;
            }
            return ok;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            String st = n();
            int n = st.length();
            boolean ok = is_palin(st.substring(0, (n - 1) / 2));
            ok &= is_palin(st.substring((n + 3) / 2 - 1));
            ok &= is_palin(st);
            pn(ok ? "Yes" : "No");

        }

        String n() {
            return in.next();
        }

        void pn(String zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 22612
#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<algorithm>

using namespace std;
using ll = long long;

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

	vector<int> L(M), R(M);
	for (int i = 0; i < M; i++) cin >> L[i] >> R[i];

	int maxL = 1;
	int minR = N;

	for (int i = 0; i < M; i++) {
		maxL = max(maxL, L[i]);
		minR = min(minR, R[i]);
	}

	int ans = minR - maxL + 1;
	ans = max(ans, 0);

	cout << ans << endl;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  string s;
  cin >> s;
  int ans=0, p=0, q=0;
  rep(i,s.size()) {
    if(s.at(i) == '1') p++;
    else q++;
  }
  ans = min(p,q);
  cout << ans * 2;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

class Graph {
private:
  vector<vector<ull>> g;
  ull n;

public:
  Graph(ull size) : g(size), n(size) {}

  void addEdge(ull from, ull to) { g[from].push_back(to); }

  void dfs(ull node, vector<bool> &visited, vector<ull> &dp) {
    visited[node] = true;

    for (auto &i : g[node]) {
      if (!visited[i]) {
        dfs(i, visited, dp);
      }

      dp[node] = max(dp[node], 1 + dp[i]);
    }
  }

  ull longestPath() {
    vector<bool> visited(n, false);
    vector<ull> length(n, 0);

    for (auto i = 0; i < n; ++i) {
      if (!visited[i]) {
        dfs(i, visited, length);
      }
    }

    return *max_element(length.begin(), length.end());
  }
};

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

  Graph g(n);

  for (auto i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    g.addEdge(x, y);
  }

  cout << g.longestPath() << endl;
}

Measured memory_bytes: 7808
#include <iostream>
#include <string>

using namespace std;

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

  for(int i = 0; i < (s.size()-1); i++){
    if(s[i] == s[i+1]){
      cout << "Bad";
      return 0;
    }   
  }

  cout << "Good";
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int nam = in.nextInt();
		String s = in.next();
		int s_len = s.length();
		char[] s_chars = s.toCharArray();
        
        if(nam <  s_len ){
             for(int i = 0 ; i < nam;i++){
            System.out.print(s_chars[i]);
        }
        System.out.print("...");
        }else{
            System.out.println(s);
        }

      
	}
}


Measured memory_bytes: 35748
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	in.pb(in[n-1]+1);
	n++;
	int l;cin>>l;
	vvi dp(40,vi(n));
	rep(i,n){
		int t=upper_bound(all(in),in[i]+l)-in.begin()-1;
		dp[0][i]=t;
	}
	rep(i,39)rep(j,n)dp[i+1][j]=dp[i][dp[i][j]];
//	rep(i,n)cout<<" "<<dp[0][i];cout<<endl;
	int q;cin>>q;
	while(q--){
		int a,b;
		cin>>a>>b;
		a--;b--;
		if(a>b)swap(a,b);
		ll sum=0,out=inf;
		for(int i=39;i>=0;i--){
//			cout<<a<<" "<<b<<endl;
			int t=dp[i][a];
//			cout<<t<<endl;
			if(t==b){
				sum+=1<<i;
				cout<<sum<<endl;
				goto end;
			}else if(t<b){
				sum+=1<<i;
				a=t;
			}else out=min(out,(1ll<<i)+sum);
		}
		cout<<out<<endl;
		end:;
	}
}










Measured memory_bytes: 17272
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> v[111111];
int vst_fn[111111], vst_sn[111111], fn[111111], sn[111111];

void dfs_fn(int nd, int dst)
{
	int i;

    if (vst_fn[nd])
		return;

	vst_fn[nd] = 1;
	fn[nd] = dst;

	for (i = 0; i < v[nd].size(); i++)
		dfs_fn(v[nd][i], dst + 1);
}

void dfs_sn(int nd, int dst)
{
	int i;

    if (vst_sn[nd])
		return;

	vst_sn[nd] = 1;
	sn[nd] = dst;

	for (i = 0; i < v[nd].size(); i++)
		dfs_sn(v[nd][i], dst + 1);
}

int main(void)
{
	int n, i;

	scanf("%d" ,&n);
	for (i = 1; i < n; i++)
	{
        int x, y;
        scanf("%d %d" ,&x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
	}

	dfs_fn(1, 0);
	dfs_sn(n, 0);

	int fn_cl = 0, sn_cl = 0, same = 0;

	for (i = 1; i <= n; i++)
        if (fn[i] <= sn[i])
			fn_cl++;
		else if (fn[i] > sn[i])
			sn_cl++;

	printf("%s" ,fn_cl > sn_cl ? "Fennec" : "Snuke");
	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    vector<pair<iint, int>> xy(N);
    for (int i = 0; i < N; i++) {
        cin >> xy[i].first.first >> xy[i].first.second;
        xy[i].first.first--;
        xy[i].first.second--;
        xy[i].second = i;
    }
    sort(ALL(xy));

    vector<int> ans;
    ans.push_back(-1);
    int tmpmin = N;

    for (int i = 0; i < N; i++) {
        tmpmin = min(tmpmin, xy[i].first.second);
        if(tmpmin + i == N - 1){
            ans.push_back(i);
        }
    }
    vector<int> answer(N);
    for (int i = 0; i < ans.size()-1; i++) {
        for (int j = ans[i]+1; j <= ans[i+1]; j++) {
            answer[j] = ans[i+1] - ans[i];
        }
    }

    vector<int> anss(N);
    for (int i = 0; i < N; i++) {
        anss[xy[i].second] = answer[i];
    }
    for (int i = 0; i < N; i++) {
        printf("%d\n", anss[i]);
    }


}

Measured memory_bytes: 7156
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int P = 1e9 + 7;
typedef long long ll;
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN];
int dp[MAXN], pre[MAXN], lst[MAXN][3], trans[MAXN][3];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	memset(lst[0], -1, sizeof(lst[0]));
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'a') pre[i] = (pre[i - 1] + 1) % 3;
		else pre[i] = (pre[i - 1] + 2) % 3;
		memcpy(lst[i], lst[i - 1], sizeof(lst[i - 1]));
		lst[i][pre[i - 1]] = i - 1;
	}
	memset(trans[0], -1, sizeof(trans[0]));
	for (int i = 1; i <= n; i++) {
		if (i != 1 && s[i - 1] == s[i]) memcpy(trans[i], lst[i], sizeof(lst[i]));
		else memcpy(trans[i], trans[i - 1], sizeof(trans[i - 1]));
	}
	if (trans[n][0] == -1) {
		cout << 1 << endl;
		return 0;
	}
	dp[n] = 1;
	for (int i = n; i >= 1; i--) {
		update(dp[i - 1], dp[i]);
		if (s[i] == 'a') {
			if (trans[i][(pre[i] + 1) % 3] != -1) update(dp[trans[i][(pre[i] + 1) % 3]], dp[i]);
		} else {
			if (trans[i][(pre[i] + 2) % 3] != -1) update(dp[trans[i][(pre[i] + 2) % 3]], dp[i]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= n - 1; i++)
		if (pre[i] == 0) ans = (ans + dp[i]) % P;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5632
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod//i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD


@mt
def slv(H, W, A, B):
    MOD = 10**9+7
    cmb = Combination(H+W, MOD)
    ans = 0
    for i in range(W-B):
        w1 = cmb(i+(A-1), i)
        w2 = cmb((W-i-1)+(H-A-1), (H-A-1))
        ans += w1*w2
        ans %= MOD

    return ans % MOD


def main():
    H, W, A, B = read_int_n()

    print(slv(H, W, A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 29260
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		HashMap<Character, String> hmap=new HashMap<>();
		hmap.put('S', "Cloudy");
		hmap.put('C', "Rainy");
		hmap.put('R', "Sunny");
		
		String str=scn.next();
		if(str.charAt(0)=='S') {
			System.out.println(hmap.get('S'));
		}else if(str.charAt(0)=='C') {
			System.out.println(hmap.get('C'));

		}else if(str.charAt(0)=='R'){
			System.out.println(hmap.get('R'));

		}
	}

}

Measured memory_bytes: 20692
#include<stdio.h>
#include<algorithm>
#define INF 50000000000LL
using namespace std;
int s[2000];
long long r[100001];
long long dp[2][2][2000];//直前に使わなかった方がiでその一つ前がjの最小値
long long min(long long a,long long b){return a<b?a:b;}
int main(){
	int n,m,k;
	int i,j;
	scanf("%d %d %d",&n,&m,&k);
	for(i=0;i<n;i++)scanf("%d",&s[i]);
	sort(s,s+n);
	r[0]=0;
	for(i=1;i<=m;i++){
		scanf("%lld",&r[i]);
		r[i]+=r[i-1];
	}
	for(j=0;j<n;j++){
		dp[1][0][j]=INF;
		dp[1][1][j]=INF;
	}
	dp[1][0][0]=0;
	dp[1][1][0]=0;
	for(i=1;i<n-1;i++){
		for(j=0;j<n;j++){
			dp[(i+1)%2][0][j]=INF;
			dp[(i+1)%2][1][j]=INF;
		}
		for(j=0;j<i;j++){
			dp[(i+1)%2][0][j]=min(dp[(i+1)%2][0][j],dp[i%2][0][j]+(r[s[i]]-r[s[i-1]-1])/k);
			dp[(i+1)%2][1][i-1]=min(dp[(i+1)%2][1][i-1],dp[i%2][0][j]+(r[s[i]]-r[s[j]-1])/k);
			dp[(i+1)%2][0][i-1]=min(dp[(i+1)%2][0][i-1],dp[i%2][1][j]+(r[s[i]]-r[s[j]-1])/k);
			dp[(i+1)%2][1][j]=min(dp[(i+1)%2][1][j],dp[i%2][1][j]+(r[s[i]]-r[s[i-1]-1])/k);
		}
	}
	long long ans=INF;
	for(i=0;i<n;i++){
		long long res=min(dp[(n-1)%2][0][i],dp[(n-1)%2][1][i]);
		res+=(r[s[n-1]]-r[s[i]-1])/k+(r[s[n-1]]-r[s[n-2]-1])/k;
		ans=min(ans,res);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1896
#include <stdio.h>
#include <math.h>

int main(void)
{
    int c, n, cnt = 0;
    scanf("%d", &c);
    int i;
    for(i = 0; i < c; i++){
        scanf("%d", &n);
        if(isPrimeNumber(n) == 1){
            cnt++;
        }
    }
    printf("%d\n", cnt);

    return 0;
}

int isPrimeNumber(int n)
{
        if(n == 2){
            return 1;
        }else{
            int i;
            for(i = 2; i <= sqrt((double)n); i++){
                if(n % i == 0) return 0;
            }
            return 1;
        }
}




Measured memory_bytes: 2052
def main():
    N = int(input())
    pn = list(map(int, input().split()))

    sorted_pn = sorted(pn)

    diff = 0
    for (p, sp) in zip(pn, sorted_pn):
        if (p != sp):
            diff += 1

    if diff in (0, 2):
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<cstdio> 
#include<cmath> 

using namespace std;

long long n,cnt; 
int ws;

int main(){
    scanf("%lld",&n); 
    for(int i=sqrt(n);i>=1;--i) 
        if(n%i==0)
        {
            cnt=n/i;
            break;
        }
    while(cnt>0)
    { 
        ++ws;
        cnt/=10;
    }
    printf("%d\n",ws); 
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int arr[26];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin>>s;
    int ans=1;
    for(int i=0;i<s.length();i++){
        char c=s[i];
        int k=c-'a';
        if(arr[k]>=1){
            ans=0;
            break;
        }
        else{
            arr[k]+=1;
        }
    }
    if(ans){
        cout<<"yes"<<endl;
    }
    else{
        cout<<"no"<<endl;
    }
    return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define EPS             1e-9

void gogeta()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int MEX(int arr[], int n) {
    set<int> s;
    for (int i = 0; i <= n; i++)  s.insert(i);
    for (int i = 0; i < n; i++)  s.erase(arr[i]);
    return *(s.begin());
}

bool isinc(int arr[], int n) {
    for (int i = 0; i < n - 1; i++) {
        if (arr[i] > arr[i + 1]) return false;
    }
    return true;
}

int32_t main()
{
    gogeta();
    int arr[4] = {0};
    w(t) {
        string s; cin >> s;

        if (s == "AC")   arr[0]++;
        if (s == "WA")   arr[1]++;
        if (s == "TLE")  arr[2]++;
        if (s == "RE")   arr[3]++;
    }
    cout << "AC x " << arr[0] << endl;
    cout << "WA x " << arr[1] << endl;
    cout << "TLE x " << arr[2] << endl;
    cout << "RE x " << arr[3] << endl;
}

Measured memory_bytes: 3640
input()
ms = list(map(int,input().split()))
ms_abs = [abs(m) for m in ms]
ms_minus = [m for m in ms if m < 0]
if len(ms_minus) % 2 == 0:
    print(sum(ms_abs))
else:
    print(sum(ms_abs) - 2*min(ms_abs))

Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl


namespace atcoder {
	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	lli k, a, b;
	cin >> k >> a >> b;
	if (a+1 >= b || k <= a) {
		cout << k + 1 << endl;
		return 0;
	}
	k -= (a - 1);
	lli c = a;
	while(k>1){
      k-=2;
      c-=a;
      c+=b;
    }
  	c+=k;
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

def main():
    n,x,d=map(int,input().split())
    events_map={}
    if d==0:
        if x== 0:
            print(1)
        else:
            print(n+1)
        return
    for k in range(n+1):
        l=(k*x if d > 0 else -k*x)+(k-1)*k//2*abs(d)
        r=(k*x if d > 0 else -k*x)+(n-k+n-1)*k//2*abs(d)
        row=l%abs(d)
        if row not in events_map:
            events_map[row]=[]
        events_map[row].append((l,-1))
        events_map[row].append((r,1))
    ans=0
    for q in events_map.items():
        events=q[1]
        events.sort()
        bal=0
        total=0
        curL=-1
        for event in events:
            if bal==0 and event[1]==-1:
                curL=event[0]
            if bal==1 and event[1] ==1:
                curr=event[0]
                total+=(curr-curL)//abs(d)+1
            bal -= event[1]
        ans+=total
    print(ans)

main()


Measured memory_bytes: 84876
N = int(input())
li = list(map(int, input().split(" ")))

ans = {}

for i in range(N)[::-1]:
    cnt = 0
    a = N // (i+1)
    b = [((j+1)*(i+1)) for j in range(a)]

    if len(b) > 1:
        for n in b[1:]:
            cnt += ans[n-1]
        tmp = cnt % 2
        if tmp == 0:
            ans[i] = li[i]
        else:
            ans[i] = (li[i] + 1)%2 
    else:
        ans[i] = li[i]
        
print(sum(ans.values()))
answer = [ str(i+1) for i in ans.keys()  if ans[i] == 1]
print(" ".join(answer))

Measured memory_bytes: 41412
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
	int A,B,C,X,Y;
	cin >> A >> B >> C >> X >> Y;
	int cost=0;

	if(2*C < A+B){
		if(X<Y){
			cost += 2*C*X;
			Y=Y-X;
			if(2*C < B){
				cost += 2*C*Y;
			}else{
				cost += B*Y;
			}
		}else{
			cost += 2*C*Y;
			X=X-Y;
			if(2*C < A){
				cost += 2*C*X;
			}else{
				cost += A*X;
			}
		}
	}else{
		cost += A*X+B*Y;
	}
	cout << cost << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

ll H,W;
ll dp[1010][1010];
vector<string> a;
const ll MOD = 1000000007LL;
const int dx[2] = {0, 1};
const int dy[2] = {1, 0};
bool used[1010][1010];

int main ()
{
    cin >> H >> W;
    a.resize(H);
    REP(i,H) cin >> a[i];

    dp[0][0] = 1LL;
    queue<tuple<int,int>> que;
    que.push(make_tuple(0, 0));

    while (!que.empty()) {
        int x,y;
        tie(x,y) = que.front();
        que.pop();
        REP(i,2) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || ny < 0 || nx >= H || ny >= W) {
                continue;
            }
            if (a[nx][ny] == '#') {
                continue;
            }
            dp[nx][ny] += dp[x][y];
            dp[nx][ny] %= MOD;
            if (!used[nx][ny]) {
                que.push(make_tuple(nx, ny));
                used[nx][ny] = true;
            }
        }
    }
    
    cout << dp[H - 1][W - 1] << endl;

    return 0;
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int H,W;
        cin>>H>>W;
        if(H==0 && W==0)break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if((i+j)%2==0)cout<<"#";
                else cout<<".";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


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

vector< int > heap;

int getParent(int node) {
  return node/2;
}

int getLeft(int node) {
  return node*2;
}

int getRight(int node) {
  return node*2+1;
}

void maxHeapify(int i) {
  int l = getLeft(i), r = getRight(i), largest;
  if (l <= heap.size() && heap[l-1] > heap[i-1])
    largest = l;
  else
    largest = i;
  if (r <= heap.size() && heap[r-1] > heap[largest-1])
    largest = r;
  if (largest != i) {
    int holder = heap[i-1];
    heap[i-1] = heap[largest-1];
    heap[largest-1] = holder;
    maxHeapify(largest);
  }
}

void buildMaxHeap(void) {
  for (int i = heap.size()/2; i >= 1; i--) {
    maxHeapify(i);
  }
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  heap = vector< int > (n, 0);
  for (int i = 0; i < n; i++)
    cin >> heap[i];
  buildMaxHeap();  
  for (int i = 0; i < heap.size(); i++)
    cout << ' ' << heap[i];
  cout << endl;
  return 0;
}



Measured memory_bytes: 6796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define loop(i,a,b) for(int i=a;i<b;i++)
int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    int n;
    cin>>n;
    map<string,string> m;
    string a,b;
    loop(i,0,n){
        cin>>a;
        m.insert(pair<string,string>(a,a));
    }
    cout<<m.size()<<endl;

}


Measured memory_bytes: 25404