akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#define F first
#define S second
#define PB push_back
#define MP make_pair


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vii;
typedef set<int> si;
typedef map<string, int> msi;

#define INF 2000000000

const int maxn=10000009;
const ll mod=1e9+7;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    if(n%2==0){
        double p;
        p=1.0/2.0;
        cout<<setprecision(9)<<p;
    }
    else {
        double q;
        int c=n/2;
        q=((c+1)*1.0/n)*1.0;
        cout<<setprecision(9)<<q;
    }

}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,str,end) for(int i=str;i<end;++i)
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  int P[N];
  rep(i,0,N) cin >> P[i];
 
  int left = N, ans = 0;
  rep(i,0,N) {
    left = min(left, P[i]);
    if (P[i] <= left) ans++;
  }
 
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n;
  int a[210];
  cin >> n ;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  bool dividable = true;
  while (dividable == true) {
    for (int i = 0; i < n; i++) {
      if(a[i] % 2 == 0) {
        a[i] = a[i] / 2;
      }else {
        dividable = false;
        break;
      }
    }
    if(dividable == true) {
      ++count;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0;i < N;i++)  cin >> vec.at(i);

int count = 0;
for (int i = 0;i <N-1;i++) {
    for (int j = i+1;j < N;j++) {
        count += vec.at(i) * vec.at(j);
    }
}
cout << count << endl;


return 0;
}

Measured memory_bytes: 256
import queue
N, E = map(int, input().split(" "))
adj = [ [] for _ in range(N) ]  
for _ in range(E) :
    u,v = map(int, input().split(" "))
    adj[u-1].append(v-1)
    adj[v-1].append(u-1)
ans = [""]*N
q = queue.Queue() 
q.put( (0, -1 ) )

visited = [False]*N
visited[0] = True
while not q.empty() :
    u, p = q.get()
    ans[u] = p+1
    for v in adj[u] :
        if visited[v] :
            continue
        q.put( (v, u) ) 
        visited[v] = True

for a in ans :
    if a==0 :
        print("Yes")
    else :
        print(a)

Measured memory_bytes: 39892
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)((n>>m)&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll n,c,ans;
ll xx[4][99];
ll cc[99][99];
int main(){
	scanf("%lld%lld",&n,&c);
	rep(i,1,c+1)rep(j,1,c+1)scanf("%lld",&cc[i][j]);
	rep(i,0,n)rep(j,0,n){
		ll t;
		scanf("%lld\n",&t);
		xx[(i+j)%3][t]++;
	}
		
	ll ans=INF;
	rep(i,1,c+1)rep(j,1,c+1)if(i!=j)rep(k,1,c+1)if(i!=k&&j!=k){
		ll temp=0;
		rep(x,1,c+1){
			temp+=xx[0][x]*cc[x][i];
			temp+=xx[1][x]*cc[x][j];
			temp+=xx[2][x]*cc[x][k];
		}
		ans=min(ans,temp);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    ll ans=0;
    ll k=1;
    while(n>0){
        n/=2;
        ans+=k;
        k*=2;
    }
  out(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

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

signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  int m=0;
  REP(i,n){
    cin>>a[i];
    if(m<a[i])m=a[i];
  }
  if(m<k){
    cout<<"IMPOSSIBLE"<<endl;
  }else{
    int tmp=0;
    REP(i,n){
      tmp=gcd(tmp,a[i]);
    }
    if(k%tmp==0){
      cout<<"POSSIBLE"<<endl;
    }else{
      cout<<"IMPOSSIBLE"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long n,a,b;

int main(){
	cin>>n>>a>>b;
	if(a%2==b%2) cout<<(b-a)/2<<endl;
	else cout<<min(a,n-b+1)+(b-a)/2<<endl;

	return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  arep(i, a) cin >> i;
  int ans = 0, now = a[0];
  rep(i, 1, n) {
    if (now > a[i]) {
      ans += now - a[i];
    } else
      chmax(now, a[i]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4684
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  map<int, int> cnt;
  int n;
  scanf("%d", &n);
  while (n--) {
    int x;
    scanf("%d", &x);
    cnt[x - 1]++;
    cnt[x]++;
    cnt[x + 1]++;
  }
  int ret = 0;
  for (auto& it : cnt) {
    ret = max(ret, it.second);
  }
  printf("%d\n", ret);
  return 0;
}


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

using Graph = std::vector<std::vector<uint32_t>>;

uint32_t dfs(const Graph& G, uint32_t node, std::vector<bool>& visit) {
  visit[node] = true;
  if (std::all_of(visit.begin(), visit.end(), [](bool v) { return v; })) {
    visit[node] = false;
    return 1;
  }

  uint32_t count = 0;
  for (auto&& to : G[node]) {
    if (visit[to]) continue;
    count += dfs(G, to, visit);
  }

  visit[node] = false;
  return count;
}

int main() {
  uint32_t N = 0, M = 0;
  std::cin >> N >> M;
  Graph G(N);
  for (size_t i = 0; i < M; i++) {
    uint32_t a = 0, b = 0;
    std::cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }

  std::vector<bool> visit(N, false);
  std::cout << dfs(G, 0, visit) << std::endl;

  return 0;
}

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

public class Main {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		solve();
	}

	static void solve() {
		String[] n = in.nextLine().split("");
		long x = 0l;
		for(int i = 0; i < n.length; i++)
		{
			x += Integer.valueOf(n[i]);
			x %= 9;
		}
		System.out.println(x % 9 == 0 ? "Yes" : "No");
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readarr(int abc) {
			int[] a = new int[abc];
			for (int i = 0; i < abc; i++)
				a[i] = nextInt();
			return a;
		}
	}
}





Measured memory_bytes: 49604
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int main(){
    int N ; cin >> N ;
    int arr[N+2] ;
    arr[0] = 0 ;
    for( int i = 1 ; i <= N ; i++ ){
        cin >> arr[i] ;
        arr[i] += arr[i-1] ;
    }
    int ans = INT_MAX ;
    for( int i = 1 ; i < N ; i++ ){
        ans = min( ans , abs( arr[N] - arr[i] - arr[i]) ) ;
    }
    cout << ans << endl ;
    return 0 ;
}


Measured memory_bytes: 3608
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] array = new long[n];
        array[0] = sc.nextInt();
        for (int i = 1; i < n; i++) {
            array[i] = array[i - 1] + sc.nextLong();
        }
        long target = array[n - 1] / 2;
        long nearest = Long.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            long gap = Math.abs(target - array[i]);
            if (nearest < gap) {
                long d = array[n - 1] - array[i - 1];
                System.out.println(Math.abs(d -  array[i - 1]));
                return;
            } else {
                nearest = gap;
            }
        }
    }
}

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

int main()
{
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    int64_t ac = a * c, ad = a * d, bc = b * c, bd = b * d;
    cout << max(max(ac, ad), max(bc, bd)) << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n,a,b,c;
	while(1){
		cin>>a>>b>>c;
		n=a+b+c;
		if(n==0) break;
		int m;
		cin>>m;
		vi d(n+1,2),x(m),y(m),z(m),f(m);
		rep(i,0,m){
			cin>>x[i]>>y[i]>>z[i]>>f[i];
			if(f[i]==1){
				d[x[i]]=1;
				d[y[i]]=1;
				d[z[i]]=1;
			}
		}
		rep(i,0,m){
			if(f[i]==0){
				if(d[x[i]]==1 && d[y[i]]==1) d[z[i]]=0;
				else if(d[z[i]]==1 && d[y[i]]==1) d[x[i]]=0;
				else if(d[x[i]]==1 && d[z[i]]==1) d[y[i]]=0;
			}
		}
		rep(i,1,n+1){
			o(d[i]);
		}
	}
}

Measured memory_bytes: 1228
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;

ll N;
int a[200010]={};
bool f[200010]={};
int main(){
    cin>>N;
    ll M=0;
    for(int i=1;i<=N;i++){
        cin>>a[i];
    }
    for(int i=N;i>=1;i--){
        int cnt=0;
        for(int j=N/i*i;j>=i*2;j-=i){
            if(f[j])cnt++;
        }
        if((cnt%2)!=a[i]){
            f[i]=true;
            M++;
        }
    }
    cout<<M<<endl;
    for(ll i=1;i<=N;i++){
        if(f[i])cout<<i<<" ";
    }

    return 0;
}

Measured memory_bytes: 1920
import sys
from itertools import accumulate
import bisect

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, M, K = mi()
    A = list(mi())
    B = list(mi())

    Aacc = [0]+list(accumulate(A))
    Bacc = list(accumulate(B))
    Baccz = [0]+Bacc

    m = 0

    # print(Aacc)
    # print(Bacc)

    for i in range(N+1):
        t = Aacc[i]
        j = bisect.bisect_right(Bacc, K-t)
        if Aacc[i]+Baccz[j] <= K:
            m = max(m, i+j)

    print(m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 134424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

const ll MOD = 1e9 + 7;
const ll MAXC = 2 * 1e5;
void mainsolve(){
	ll n;
	cin >> n;
	vector<ll> c(n);
	rep(i,n) cin >> c[i];
	vector<vector<ll>> memo(MAXC);
	rep(i,n){
		memo[--c[i]].push_back(i);
	}

	vector<ll> dp(n);
	dp[n-1] = 1;

	for(ll i = n-2; i >= 0; i--){
		dp[i] = dp[i+1] % MOD;
		if(c[i] == c[i+1]) continue;
		if(memo[c[i]].empty()) continue;
		auto loc = upper_bound(memo[c[i]].begin(), memo[c[i]].end(), i+1);
		if(loc != memo[c[i]].end() && *loc <= n-1) dp[i] = (dp[i] + dp[*loc]) % MOD;
	}
	cout << dp[0] << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

pair<int, int> bfs(const vector<vector<int>>& g, int start){
    const int n = g.size();
    vector<int> step(n, 1000000007);
    queue<int> qu; qu.push(start);
    step[start] = 0;
    pair<int,int> res = make_pair(start, 0);
    while(!qu.empty()){
        int p = qu.front(); qu.pop();
        for(auto& dst : g[p]){
            if(step[p] + 1 < step[dst]){
                step[dst] = step[p] + 1;
                qu.push(dst);
                if(res.second < step[dst]){
                    res = make_pair(dst, step[dst]);
                }
            }
        }
    }
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<vector<int>> g(N);
        for(int i=0;i<N-1;i++){
            int a, b; cin >> a >> b;
            --a; --b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        cout << (bfs(g, bfs(g, 0).first).second % 3 == 1 ? "Second" : "First") << endl;
    }
}

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

int main() {
    long long n;
    cin >> n;
    string s = to_string(n);
    int ans, dig;
    dig = s.length();
    ans = 9 * (dig-1) + s[0]-'0';
    if ((s[0]-'0')*pow(10, dig-1)+pow(10, dig-1)-1 > n)
        ans--;
    cout << ans << endl;
}

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

int main() {
  
  string S,P;
  cin >> S;
  
  P = S;
  reverse(P.begin(),P.end());
  
  int count = 0;
  
  for ( int i = 0; i < S.size()/2; i++){
    if ( S.at(i) != P.at(i) ){
      count ++;
    }
  }
  
  cout << count << endl;
 
}

Measured memory_bytes: 256
/*There's a possibility*/
/*but stop sucking first*/
#define dbg(...) ; 
#define db(...) ; 
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define tst cout<<'*';
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define pf push_front
using namespace std;

int main()
{
    fast;
    int n,i;
    cin>>n;
    int h[n],dp[n+1];
    f(i,0,n)
        cin>>h[i];
    dp[0]=0,dp[1]=abs(h[1]-h[0]);
    f(i,2,n)
        dp[i]=min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
    cout<<dp[n-1];
}

Measured memory_bytes: 4436
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> x(n);
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  sort(x.begin(),x.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=x[n-1-i];
  }
  cout<<ans;
      
}

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

int main() {
 int N=0;
  cin >> N;
 int K=0;
  cin >> K;
  int total;
  	vector<int> num(N);//すぬけの何番目がお菓子何個もつか
		
   for (int i = 0; i < K; i++) {
     	int d=0;
     	cin >> d;
  		vector<int> vec(d);
			for (int j = 0; j < d; j++) {
         	cin >> vec.at(j);
              int owner=0;
              owner = vec.at(j)-1;
                num.at(owner)++;
			}	
   }
  for (int l = 0; l < N; l++) {
   	if (num.at(l) == 0) {
     	total++;
 		 }
   }
   cout << total << endl;
   }

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  ll x;
  cin >> x;
  ll ans = 0;
  ll sum = 0;
  ll key = 1;
  while(sum < x){
    sum += key;
    key++;
    ans++;
  }
  ll dis = x - sum;
  while(0 < dis){
    ans++;
    dis--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define int long long

int n;
int x[1010],y[1010];
int c[2];
int a[99];
main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",x+i,y+i);
		c[(x[i]+y[i])%2]++;
	}
	if(c[0]&&c[1]){
		puts("-1");
		return 0;
	}
	int flag=!!c[0];
	int N=39;
	printf("%d\n",N+flag);
	for(int i=0;i<N;i++)printf("%lld ",a[i]=1LL<<(N-1-i));
	if(flag)puts("1"),a[N]=1;
	else puts("");
	int cnt=N+flag;
	
	for(int i=0;i<n;i++){
		int xx=x[i]-y[i];
		int yy=x[i]+y[i];
		for(int i=0;i<cnt;i++){
			     if(xx>=0&&yy>=0)putchar('R'),xx-=a[i],yy-=a[i];
			else if(xx>=0&&yy<=0)putchar('D'),xx-=a[i],yy+=a[i];
			else if(xx<=0&&yy>=0)putchar('U'),xx+=a[i],yy-=a[i];
			else if(xx<=0&&yy<=0)putchar('L'),xx+=a[i],yy+=a[i];
		}
		puts("");
	}
}

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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n;
  cin >> n;
  vector<long long> cnt(1e5 + 7);

  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    cnt[a]++;
  }

  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= (long long)b * cnt[b];
    sum += (long long)c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}

Measured memory_bytes: 3976
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
    int a;cin >> a;
    int ans = 0;
    for(int i=1;i<=a;i++){
        if(i < 10){
            ans++;
        }else if(i >= 100 && i < 1000){
            ans++;
        }else if(i >= 10000 && i < 100000){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int 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<int,int,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;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

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

	int n;
	cin>>n;
	map<string,int>ma;
	int w=0;
	rep(i,n){
		string s;
		cin>>s;
		sort(all(s));
		w+=ma[s];
		ma[s]++;
	}
	cout<<w<<endl;
}


Measured memory_bytes: 11264
from operator import itemgetter

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

b = sorted(a, key=itemgetter(1))
#print(b)
removed = -1
ans = 0

for i in range(m):
  if b[i][0] > removed:
    removed = b[i][1] - 1
    ans += 1
    
print(ans)

Measured memory_bytes: 29444
#include <iostream>

using namespace std;

int main() {
    int n, f[200005]={}, x;
    cin >> n;
    for( int i = 2; i <= n; i++ ){
        cin >> x;
        f[x]++;
    }
    for( int i = 1; i <= n; i++ ){
        cout << f[i] << endl;
    }
}

Measured memory_bytes: 4428
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>

typedef long long ll;

using namespace std;

int main() {
    int a, b, ans;
	cin >> a >> b;

	if ((a - 2*b) > 0) {
		ans = a - 2*b;
	} else {
		ans = 0;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while('0'<=ch&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int main(){
	//freopen("a.in","r",stdin);
	int Q=read();
	while(Q--){
		int A=read(),B=read();
		LL C=1ll*A*B;
		LL wt=sqrt(C);
		if(wt*(wt+1)<C){
			printf("%lld\n",wt*2-1);
		}
		else if(wt*wt==C){
			if(A==B)printf("%lld\n",wt*2-2);
			else printf("%lld\n",wt*2-3);
		}
		else{
			printf("%lld\n",wt*2-2);
		}
	}
}

Measured memory_bytes: 384
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <list>
#include <queue>
using namespace std;

#define int long long
#define INF 1e18
#define EPS 1e-9

int dist(int x, int y) {
    return abs(x - y);
}

signed main() {
    int n, k; cin >> n >> k;
    vector<int> x(n); for(int i = 0; i < n; i++) cin >> x[i];

    int ans = INF;
    for(int i = 0; i < n - k + 1; i++) {
      int l = dist(0, x[i]) + dist(x[i], x[i + k - 1]);
      int r = dist(0, x[i + k - 1]) + dist(x[i + k - 1], x[i]);
      int tmp = min(l, r);
      ans = min(ans, tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int main(){
  long long int n,ans,i,t,a,h,tmp=1000000000;
  scanf("%lld%lld%lld",&n,&t,&a);
  for(i=0;i<n;i++){
    scanf("%lld",&h);
    if(tmp>llabs((1000*t-6*h)-1000*a)){
        tmp=llabs((1000*t-6*h)-1000*a);
      ans=i+1;
      }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

const int N=1e5+10;
const ll INF=1e9+7;
ll a[N<<4];
ll sum[11];
main(){
    ios
    int h,w,n;scanf("%d%d%d",&h,&w,&n);
    int x,y;
    int cnt=0;
    ll m=(ll)(h-2)*(w-2);
    rep(iii,n){
        scanf("%d%d",&x,&y);
        rep(i,3)rep(j,3)if( x-i>=1 && x-i<=h-2 && y-j>=1 && y-j<=w-2){
            a[cnt++]=INF*(x-i)+(y-j);
        }
    }
    sort(a,a+cnt);
    ll t=1;
    rep(i,cnt){
        if(a[i]==a[i+1])t++;
        else sum[t]++,t=1,m--;
    }
    cout<<m<<" ";
    rep2(i,1,9)cout<<sum[i]<<" ";
}



Measured memory_bytes: 8448
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<set>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

vll a(105);
vll ans(105);

int main() {
	ll n;
	cin >> n;

	REP(i, 1, n) {
		cin >> a[i];
	}
	REP(i, 1, n) {
		PER(j, n + 1 - i, 0) {
			if (j == 0) {
				cout << -1 << endl;
				return 0;
			}
			if (a[j] == j) {
				ans[i] = j;
				REP(k, j, n - i) {
					a[k] = a[k + 1];
				}
				break;
			}
		}
		
	}
	PER(i, n, 1) {
		cout << ans[i] << endl;
	}

}

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

int main() {
  uint64_t K,N;
  cin >> K >> N;
  vector<uint64_t> a(N);
  rep(i, N){
    cin >> a.at(i);
  }
  uint64_t win = 0;
  rep(i, N - 1){
    uint64_t cha = a.at(i + 1) - a.at(i);
    if(win < cha) win = cha;
  }
  uint64_t cha = K - a.at(N - 1) + a.at(0);
  if(win < cha) win = cha;
  cout << K - win << endl;
}


Measured memory_bytes: 1792
//パソコン甲子園2010 問題番号05 博士の愛した2進数
#include<stdio.h>

int main(void){

	int i1;
	double n, n1, s1, s2, s3;

	scanf("%lf",&n);
	while(n >= 0.0){

	s1 = 1.0;
	s2 = 0.0;
	s3 = 0.5;

	i1 = (int)n;
	n1 = n - (double)i1;

	while(i1 != 0){
		if(i1 % 2 !=0)	s2 += s1;
		s1 *= 10;
		i1 /= 2;
	}

	s1 = 0.1;

	while(n1 != 0.0 && s1 >= 0.0001){
		if(n1 - s3 >= 0.0){
			s2 += s1;
			n1 -= s3;
		}
		s1 /= 10;
		s3 /= 2;
	}

	if(i1 >= 256 || n1 != 0.0)
		printf("NA\n");
	else
		printf("%013.4f\n",s2);

	scanf("%lf",&n);
	}
	return 0;
}

Measured memory_bytes: 0
import collections
n=int(input())
v=list(map(int,input().split()))
odd=[v[i] for i in range(n) if i%2==0]
even=[v[i] for i in range(n) if i%2==1]
o=(collections.Counter(odd)).most_common()
e=(collections.Counter(even)).most_common()
o.append((0,0))
e.append((0,0))
if o[0][0]==e[0][0]:
  print(n-max(e[0][1]+o[1][1],e[1][1]+o[0][1]))
else:
  print(n-(e[0][1] +o[0][1]))

Measured memory_bytes: 21084
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define ll long long 
#define il inline
const int maxn=110;
int n,m;
char mp[maxn][maxn];
int f[maxn][maxn];
int main(){
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;++i){
        scanf("%s",mp[i]+1);
    }
    f[1][1]=(mp[1][1]=='#');
    for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            if (i==1&&j==1) continue;
            if (mp[i][j]=='.'){
                if (i==1) f[i][j]=f[i][j-1];
                else if (j==1) f[i][j]=f[i-1][j];
                else f[i][j]=min(f[i-1][j],f[i][j-1]);
            }else{
                if (i==1) f[i][j]=f[i][j-1]+(mp[i][j-1]=='.');
                else if (j==1) f[i][j]=f[i-1][j]+(mp[i-1][j]=='.');
                else f[i][j]=min(f[i-1][j]+(mp[i-1][j]=='.'),f[i][j-1]+(mp[i][j-1]=='.'));
            }
        }
    }
    printf("%d",f[n][m]);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by sonetsuyoshi on 2016/07/31.
 */
public class Main {

    static public void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] sts = sc.nextLine().split(" ");
        long ans = 0;
        if(sts[1].equals("+")) {
            ans = Long.parseLong(sts[0]) + Long.parseLong(sts[2]);
        } else {
            ans = Long.parseLong(sts[0]) - Long.parseLong(sts[2]);
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 9680
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    int n, m; cin >> n >> m;
    cout << (n == m ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3632
import sys
input = sys.stdin.buffer.readline

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    l = len(A)
    A.sort(reverse = True)
    if K >= l:
        print(0)
    else:
        print(sum(A[K:]))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 21988
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int i,d=0;
    for(i=0;i<s1.length();i++){

        if(s1[i]==s2[i]){
            d++;
        }

    }
    cout<< d <<endl;
    return 0;




}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int W,H,x,y,r;
	
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	
	if (r<=x && x <= W-r && r<=y && y <= H-r) printf("Yes\n");
	else printf("No\n");

return 0;
}

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

typedef long long int int64;

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  for(i=n-1;i>0;i--) if(a[i]>a[i-1]+1) break;
  if(i>0 || a[0]!=0){
    puts("-1");
    return;
  }
  int64 ans=0;
  i=n-1;
  while(i>0){
    ans+=a[i];
    while(i>0 && a[i]==a[i-1]+1) i--;
    i--;
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
vl ans;

int main(){
    int n;cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int cnt=0;
    for(int i=1;i<n;++i){
        bool b=true;
        for(int j=0;j<i;++j){
            if(a[i]<a[j]){
                b=false;
                break;
            }
        }
        if(b)cnt++;
    }
    cout<<cnt+1<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main (void){
  int item, weight;
  cin>>item>>weight;
  vector<int> weights(item, 0);
  vector<int> values(item, 0);
  long long int dp[item+1][weight+1];
  for(int i=0;i<=item;++i)
    for(int j=0;j<=weight;++j)
      dp[i][j] = 0;
  for(int i=0;i<item;++i)
    cin>>weights[i]>>values[i];
  for(int i=1;i<=item;++i){
  	for(int j=0;j<=weight;j++){
    	if(j<weights[i-1])
          dp[i][j] = dp[i-1][j];
      	else
          dp[i][j] = max(dp[i-1][j-weights[i-1]] + values[i-1], dp[i-1][j]);
    }
  }
  cout<<dp[item][weight];
return 0;
}

Measured memory_bytes: 79104
import io.StdIn._
object Main extends App {
  val res = readLine match {
    case "SUN" => 7
    case "MON" => 6
    case "TUE" => 5
    case "WED" => 4
    case "THU" => 3
    case "FRI" => 2
    case "SAT" => 1
  }
  println(res)
}


Measured memory_bytes: 27332
import sys, itertools
input = sys.stdin.readline

def main():
    N = int(input())
    S = [s.rstrip() for s in sys.stdin.readlines()]
    count = 0

    memo = sorted(S)

    for i in range(N - 1):
        if memo[i] == memo[i + 1]:
            count += 1
        
    print(N - count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 37296
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main()
{
	ll n, c;
	cin >> n >> c;
	vector<ll> x(n + 2), v(n + 2);
	for (int i = 1; i <= n; i++) {
		cin >> x[i] >> v[i];
	}
	x[0] = 0;
	x[n + 1] = c;
	ll cal = 0;
	vector<vector<ll>> dp(2, vector<ll>(100010, 0));
	for (ll i = 1; i <= n; i++) {
		cal -= x[i] - x[i - 1];
		cal += v[i];
		dp[0][i] = max(dp[0][i - 1], cal);
	}
	cal = 0;
	for (ll i = n; i >= 1; i--) {
		cal -= x[i + 1] - x[i];
		cal += v[i];
		dp[1][i] = max(dp[1][i + 1], cal);
	}
	ll mxcal = 0;
	for (ll i = 0; i <= n; i++) {
		cal = dp[0][i] + dp[1][i + 1] - x[i];
		mxcal = max(mxcal, cal);
		cal = dp[0][i] + dp[1][i + 1] + x[i + 1] - c;
		mxcal = max(mxcal, cal);
	}
	cout << mxcal << endl;
	return 0;
}

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

string s;
int k, up[105], n;
long long dp[105][2][4];

long long dfs(int pos, int lim, int cnt){
    if (pos == -1 && cnt == k) return 1;
    else if (pos == -1) return 0;
    if (cnt > k) return 0;
    if (dp[pos][lim][cnt] != -1) return dp[pos][lim][cnt];
    int upper;
    long long ret = 0;
    if (lim == 1) upper = up[pos];
    else upper = 9;
    for (int i = 0; i <= upper; i++){
        ret += dfs(pos-1, lim&&i==upper, cnt+(i!=0));
    }
    return dp[pos][lim][cnt] = ret;
}

long long solve(){
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++){
        up[i] = s[n-1-i]-'0';
    }
    return dfs(n-1, 1, 0);
}

int main() {
    cin >> s;
    cin >> k;
    n = s.length();
    cout << solve() << "\n";
}


Measured memory_bytes: 256
#include <cstdio>

const int MAXX=55560;
int prm[MAXX/5];

inline void Euler_prm(){
	static bool notP[MAXX];
	notP[1]=true;
	for(int i=2;i<MAXX;++i){
		if(!notP[i]) prm[++prm[0]]=i;
		for(int j=1;j<=prm[0] && i*prm[j]<MAXX;++j){
			notP[i*prm[j]]=true;
			if(i%prm[j]==0) break;
		}
	}
}

int main(){
	Euler_prm();
	int n;
	scanf("%d",&n);
	for(int i=1,j=0;i<=n;++i){
		for(++j;j<=prm[0];++j){
			if(prm[j]%5==1){
				printf("%d ",prm[j]);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
//Optional FAST

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

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(998244353);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work


int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READV(S);
    vector<ll> dp(S+1,0);
    dp[0]=power(2,N);
    ll z=modInverse(2);
    FORI(i,0,N)
    {
        vector<ll> dp_c(S+1,0);
        READV(x);
        FORI(i,0,S+1)
        {
            dp_c[i]+=dp[i];
            dp_c[i]%=MOD;
            if(i+x<=S)
            {
                dp_c[i+x]+=(dp[i]*z)%MOD;
                dp_c[i+x]%=MOD;
            }
        }
        dp=dp_c;
    }
    cout<<dp[S]<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3860
t=Hash.new 0
$<.map{a,b=_1.split.map &:to_r;b&&t[a*b==0?1[a]-1[b]:a/b]+=1}
M=10**9+7
z=1
t.map{w=t[_1==0?0:-1/_1]
w>0&&_1<=0||z=z*(2.pow(_2,M)+2**w-1)%M}
p (t[0]-1+z)%M

Measured memory_bytes: 38328
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;

    int max=0;

    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int sa=abs(a[i]-a[j]);
            if(sa>max){
                    max=sa;
            }
        }
    }
    cout<<max<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            double R = sc.nextDouble();

            double ans = R*2*Math.PI;
            
            System.out.println(ans);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}



Measured memory_bytes: 33272
#include<cstdio>
#define M 200005
#define P 1000000007
#define lowbit(x) x&-x
int val[M],Lst[M],Pre[M];
void check_max(int &x,int y){if(x<y)x=y;}
void Add(int &x,int y){x=(1ll*x+y)%P;}
struct Bit{
	int num[M];
	void Insert(int x,int d){
		x++;
		while(x<M){
			Add(num[x],d);
			x+=lowbit(x);
		}
	}
	int sum(int x){
		x++;
		int res=0;
		while(x){
			Add(res,num[x]);
			x-=lowbit(x);
		}
		return res;
	}
}B;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&val[i]);
	for(int i=1;i<=n;i++){
		if(!Pre[val[i]])Lst[i]=i,Pre[val[i]]=i;
		else{
			//printf("I%d\n",i);
			Lst[i]=Pre[val[i]];
		}
		for(int j=i+1;j<=n+1;j++){
			if(val[j]!=val[i]||j==n+1){
				Pre[val[i]]=j-1;
				i=j-1;
				break;
			}else {
				Lst[j]=j;
				/*if(Pre[val[j]])Lst[j]=Pre[val[j]];
				else Lst[j]=j;*/
			}
			//printf("j=%d\n",j);
		}
		//printf("Lst[%d]=%d\n",i,Lst[i]);
	}
	//for(int i=1;i<=n;i++)printf("Lst[%d]=%d\n",i,Lst[i]);
	//puts("!");
	B.Insert(0,1);
	for(int i=1;i<=n;i++){
		if(Lst[i]==i)continue;
		//printf("ls%d\n",Lst[i]-1);
		B.Insert(i,B.sum(Lst[i]));
		//printf("dp[%d]=%d\n",i,B.sum(i));
	}
	printf("%d\n",B.sum(n));
	return 0;
}

Measured memory_bytes: 3328
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int c5 = 0;
    int c7 = 0;
    String ans = "NO";
    for(int i = 0;i < 3;i++){
      int que = sc.nextInt();
      if(que == 5)c5++;
      if(que == 7)c7++;
    }
    if(c5 == 2&&c7 == 1)ans = "YES";
  System.out.println(ans);
  }
}

Measured memory_bytes: 21844