akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, k;
li a[5050];

// a[x]がなくなってもOKか
inline bool check(li x) {
    if (a[x] >= k) {
        return true;
    }
    bitset<5050> bs(1);
    rep(i, n) {
        if (i == x) {
            continue;
        }
        if (a[i] >= k) {
            continue;
        }
        bitset<5050> next = bs << a[i];
        bs |= next;
    }
    repp(i, max(0ll, k - a[x]), k) {
        if (bs[i]) {
            return true;
        }
    }
    return false;
}

int main() {
    cin >> n >> k;
    li sum = 0;
    rin{
        cin >> a[i];
        sum += a[i];
    }
    if (sum < k) {
        cout << n << endl;
        return 0;
    }
    sort(a, a + n);

    li left = 0;
    li right = n - 1;

    if (check(0)) {
        cout << 0 << endl;
        return 0;
    }

    while (left + 1 < right) {
        li med = (left + right) / 2;
        if (check(med)) {
            right = med;
        } else {
            left = med;
        }
    }
    cout << right << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>


static void A_RegularTriangle();

int main()
{
	A_RegularTriangle();

	return 0;
}



static void A_RegularTriangle()
{
	int A, B, C;


	scanf("%d %d %d", &A, &B, &C);

	const char* ans = "No\n";
	if ((A == B) && (B == C)) {
		ans = "Yes\n";
	}

	printf(ans);
	fflush(stdout);

	return;
}


Measured memory_bytes: 256
s=input()
l=len(s)
bo =True
if l%2==1:
	print("No")
else:
	x=int(l/2)
	for i in range(x):
		if s[2*i]!="h" or s[2*i+1]!="i":
			bo=False
			break
	if bo==True:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
	int n;
	long long int sum=0;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		if(i%3==0 && i%5==0){
			continue;
		}else if(i%5==0){
			continue;
		}else if(i%3==0){
			continue;
		}else{
			sum+=i;
		}
	}
	printf("%lld", sum);
	
	return 0;
}

Measured memory_bytes: 1736
#include<stdio.h>
int main()
{
	int x,y,N,M,i,j,l,z[]={0,1,0,-1,0};
	char d;
	while(scanf("%d",&N),N)
	{
		int a[21][21]={0};
		for(i=0;i<N;++i)scanf("%d%d",&x,&y),a[y][x]=1;
		x=y=10;
		for(scanf("%d",&M),i=0;i<M;++i)
		{
			scanf(" %c%d",&d,&l);
			if(d=='E')d=0;
			if(d=='N')d=1;
			if(d=='S')d=3;
			if(d=='W')d=2;
			for(j=0;j<l;++j)if(a[y+=z[d]][x+=z[d+1]])a[y][x]=0,--N;
		}
		puts(N?"No":"Yes");
	}
	return 0;
}

Measured memory_bytes: 0
#include<sstream>
#include<iostream>
#include<vector>
#include <algorithm>

using namespace std;

int main() {

	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	int i;

	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> b(n);
	for (i = 0; i < n - 1; i++) {
		b[i] = a[i + 1] - a[i];
	}
	b[n - 1] = a[0] + (k - a[n - 1]);
	int x = 0;
	for (i = 0; i < n; i++) {
		x += b[i];
	}
	int y,z;
	y = 0;
	for (i = 0; i < n; i++) {
		y = max(y, b[i]);
	}
	z = x - y;
	cout << z << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
    string s;
   
    cin >> s; 
    int index = 0;   
    while(1){
        index = s.find("ST",index);

        if(index  == -1)break;

        s = s.erase(index,2);
        index -= 2;
        index = max(0,index);
    }
    P(sz(s));
	
	return  0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N, X;
    int sum = 0;
    int min;
    vector<int> list;
    cin >> N >> X;
    for (int i = 0; i < N; i++)
    {
        int in;
        cin >> in;
        list.push_back(in);
        sum += in;
        min = in;
    }
    for( auto a : list)
    {
        if (min > a)
            min = a;
    }

    X -= sum;

    N += X / min;
    cout << N << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        Deque<Character> que = new ArrayDeque<>();

        for(char ch: str.toCharArray()) {
            if(ch == 'T' && que.size() > 0 && que.peek().equals('S')) {
                que.pop();
            }else {
                que.push(ch);
            }
        }
        System.out.println(que.size());
    }
}

Measured memory_bytes: 28520
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << '\n';
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, k;
  cin >> n >> k;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  rep(i, n){
    ll j = i+k;
    if(j >= n) break;
    Pr(a[i] < a[j]);
  }
}


Measured memory_bytes: 4760
import sys

i = 0
for line in sys.stdin:
    a,b = map(int, line.rstrip().split())
    if a != 0 and b != 0:
        if i != 0:
                print ''
        flag = False
        for y in range(a, b+1):
            if (y % 4 == 0 and y % 400 == 0) or (y % 4 == 0 and y % 100 != 0):
                flag = True
                print y
        else:
            if not flag:
                print 'NA'
            flag = False
    i += 1

Measured memory_bytes: 4300
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define PRIM 3
#define INF (1 << 29)
#define LINF (1LL << 60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

Int ans = LINF;

Int n, x, y;
char u;

vector<P> rl[440000];
vector<P> ud[440000];
vector<P> lu[440000];
vector<P> ru[440000];
vector<P> ld[440000];
vector<P> rd[440000];

Int calc(vector<P> &vec)
{
    Int ans = LINF;
    sort(vec.begin(), vec.end());
    for (int i = 0; i + 1 < vec.size(); i++) {
        //        cout << vec[i].first << " " << vec[i + 1].first << endl;
        if (vec[i].second == 0 && vec[i + 1].second == 1) {
            ans = min(ans, (vec[i + 1].first - vec[i].first) * 5);
        }
    }
    return ans;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x >> y >> u;
        if (u == 'R') {
            rl[y].push_back(P(x, 0));
            rd[x - y + 200000].push_back(P(x + y, 0));
            ru[x + y].push_back(P(x - y, 0));
        }
        if (u == 'L') {
            rl[y].push_back(P(x, 1));
            ld[x + y].push_back(P(x - y, 1));
            lu[x - y + 200000].push_back(P(x + y, 1));
        }
        if (u == 'U') {
            ud[x].push_back(P(y, 0));
            lu[x - y + 200000].push_back(P(x + y, 0));
            ru[x + y].push_back(P(x - y, 1));
        }
        if (u == 'D') {
            ud[x].push_back(P(y, 1));
            ld[x + y].push_back(P(x - y, 0));
            rd[x - y + 200000].push_back(P(x + y, 1));
        }
    }

    for (int i = 0; i <= 400000; i++) {
        ans = min(ans, calc(rl[i]));
        ans = min(ans, calc(ud[i]));
        ans = min(ans, calc(ld[i]));
        ans = min(ans, calc(rd[i]));
        ans = min(ans, calc(lu[i]));
        ans = min(ans, calc(ru[i]));
    }
    if (ans == LINF)
        cout << "SAFE" << endl;
    else
        cout << ans << endl;
    return 0;
}

Measured memory_bytes: 83476
N, M = map(int, input().split())
parents = [i for i in range(N+1)]

def find(x):
    if x == parents[x]:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]
    
def same(A, B):
    x, y = find(A), find(B)
    if x==y:
        return
    else:
        parents[x] = y

for _ in range(M):
    A, B = map(int, input().split())
    same(A, B)
    
for i in range(N):
    find(i+1)

print(len(set(parents)) - 2)


Measured memory_bytes: 18208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
#define REP(i,n) for (int i = 1; i<= (n); i++)
const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    int a[n];
    int all = 0;
    int cnt = 0;
    rep(i,n) {
        cin >> a[i];
        all += a[i];
    }
    rep(i,n) {
        if (a[i]*4*m >= all) {
            cnt += 1;
        }
    }
    if (cnt >= m) cout << "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
  int m,n;
  for(;cin>>n>>m,m;)
    {
      int x=1,y=1;
      int dx[]={1,0,-1,0};
      int dy[]={0,1,0,-1};
      int lr=0;
      string move;
      for(;cin>>move,move!="STOP";)
	{
	  if(move=="FORWARD")
	    {
	      int tmp;
	      cin>>tmp;
	      for(;tmp--;)
		{
		  if(x+dx[lr]>0 && x+dx[lr]<=m &&
		     y+dy[lr]>0 && y+dy[lr]<=n )
		    {
		      x+=dx[lr];
		      y+=dy[lr];
		    }
		}
	    }

	  if(move=="BACKWARD")
	    {
	      int tmp;
	      cin>>tmp;
	      for(;tmp--;)
		{
		  if(x-dx[lr]>0 && x-dx[lr]<=m &&
		     y-dy[lr]>0 && y-dy[lr]<=n )
		    {
		      x-=dx[lr];
		      y-=dy[lr];
		    }
		}
	    }
	  if(move=="RIGHT")
	    {
	      lr++;
	      if(lr>3)
		lr=0;
	    }
	  if(move=="LEFT")
	    {
	      lr--;
	      if(lr<0)
		lr=3;
	    } 
	}
      cout<<y<<" "<<x<<endl;
    }

}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#include <string.h>
#include <iostream> 
#include <cmath>
#include <stdio.h>
#include <math.h>
#include <string>
#include <sstream> 
#include<algorithm>
#define int long long int
#define fi(i,n) for(int i=0;i<n;i++)
#define fd(i,n) for(int i=n-1;i>=0;i--)
typedef long long ll;
using namespace std;
int const mod = 1e9+7;
const int M=1e5+5;
bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 
 
int gcd(int a, int b)  
{  
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
}  
int findGCD(int arr[], int n) 
{ 
    int result = arr[0]; 
    for (int i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
} 
int lcm(int a, int b)  
{  
    return (a*b)/gcd(a, b);  
} 

/*int cost[M][8];
int dp[M][(1<<8)+1];
 
int solve(int i, int mask, int& n)
{
    if(i == n)
        return 0;
 
    if(dp[i][mask] != -1)
        return dp[i][mask];
 
    int answer = INT_MIN;
    for(int j = 0; j < n; j++)
    {
        if(mask&(1<<j))
            answer = max(answer, cost[j][i] + solve(i+1, (mask^(1<<j)), n));
    }
 
    return dp[i][mask] = answer; 
} */
 
int32_t main()
{    ios::sync_with_stdio(0);
cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
#endif                                   
    int n;cin>>n;
    fi(i,n) cout<<"ACL";
    return 0;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#define N 100
#define LARGE 10000

typedef struct edge{
	int cost;
	int u;
	int v;
}edge;

/*qsort用*/
int cmp(const void *p,const void *q){
	return ((edge*)p)->cost - ((edge*)q)->cost;
}


int find(int u,int par[]){
	if(par[u]==u){
		return u;
	}else {
		return par[u]=find(par[u],par);
	}
}

void merge(int u,int v,int par[]){
	if(par[u] < par[v]){
		if(v!=par[v])
			merge(u,par[par[v]],par);
		par[v]=par[u];
	}
	else {
		if(u!=par[u])
			merge(v,par[par[u]],par);
		par[u]=par[v];
	}
	return;
}



int main(){
	int i,j,n;
	int num=0;/*edgeの個数*/
	int ans=0;
	int a[N][N];
	edge E[LARGE];/*edge*/
	int par[N];/*親の配列*/
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)par[i]=i;
	
	
	/*隣接行列の読み込み*/
	for(i=0;i<n;i++){
	
		for(j=0;j<n;j++){
			scanf("%d",&a[i][j]);
			if(a[i][j]!=-1 && j>=i+1){
				E[num].cost=a[i][j];
				E[num].u=i;
				E[num++].v=j;
			}
		}
		
	}
	
	/*edgeのソート*/
	qsort(E,num,sizeof(edge),cmp);
	
	for(i=0;i<num;i++){
		if(find(E[i].u,par) != find(E[i].v,par)){
			merge(E[i].u,E[i].v,par);
			ans+=E[i].cost;
		}
	}
	
	printf("%d\n",ans);
	
	return 0;
	
}


Measured memory_bytes: 2104
N = input()
d = {}
for a in map(int, raw_input().split()):
  d[a] = d.get(a, 0) + 1
sorted_len_num = sorted(d.items(), key=lambda x:x[0])
REQUIRED_NUM = 2
remained = REQUIRED_NUM
s = 1
for l, n in reversed(sorted_len_num):
  if remained == 0:
    break
  if n < 2:
    continue
  s *= l
  remained -= 1
  if n > 3 and remained > 0:
    s *= l
    remained -= 1
    

if remained == 0:
  print s
else:
  print 0


Measured memory_bytes: 23376
#include<stdio.h>

int main()
{
   int N, i, j, temp, count=0;
   int A[100];

   scanf("%d", &N);

   for (i=0; i<N; i++)
      scanf("%d", &A[i]);

   for (i=0; i<N-1; i++){
      for (j=N-1; j>=i+1; j--){
         if (A[j]<A[j-1]){
            temp = A[j];
            A[j] = A[j-1];
            A[j-1] = temp;
            count++;
         }
      }
   }

   for (i=0; i<N; i++){
      if (i>0)
         printf(" ");
      printf("%d", A[i]);
   }
   printf("\n");

   printf("%d\n", count);

   return 0;
}

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

#define PI 3.14159265359

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> matrix(H, vector<char>(W));
  vector<vector<char>> mat(H, vector<char>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> matrix[i][j];
    }
  }
  int ans = 0;
  int all = 1 << (H + W);
  for (int mask = 0; mask < all; mask++){
    mat = matrix;
    int sum = 0;
    for (int i = 0; i < H; i++){
        if ((mask>>i)&1){
            for (int j = 0; j < W; j++){
                mat[i][j] = '.';
            }
        }
    }
    for (int i = 0; i < W; i++){
      if ((mask>>(i + H))&1){
          for (int j = 0; j < H; j++){
              mat[j][i] = '.';
          }
      }
    }
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        if (mat[i][j] == '#')sum++;
      }
    }
    if (sum == K) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun dprint(v: Any?, indent: Int = 0) {
    val indentStr = (1..indent).joinToString("") { " " }
    when (v) {
        is Iterable<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is Array<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is IntArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is LongArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is DoubleArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        else -> System.err.println(indentStr + v)
    }
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> min(vararg a: A) = a.reduce { acc, x -> min(acc, x) }
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b
fun <A : Comparable<A>> max(vararg a: A) = a.reduce { acc, x -> max(acc, x) }

////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solveMulti(sc: Scanner, pw: java.io.PrintWriter) {
        for (t in 1..sc.next().toInt()) {
            solve(sc, pw)
        }
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val A = sc.next().toInt()
        val B = sc.next().toInt()
        val C = sc.next().toInt()
        pw.println(max(C - (A - B), 0))
    }
}


Measured memory_bytes: 31272
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
//#include<array>
#include<algorithm>
//#include<queue>
#include<deque>
#include<vector>
//#include<utility>
//#include<set>
//#include<map>
//#include<list>
//#include<bitset>
//#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}
//long nHr(int n, int r) {
//	n = n + r - 1;
//	return nCr(n, r);
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI X;
	cin >> X;
	if (X == 5 || X == 3 || X == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
 
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		Main m = new Main();
		//*
		m.input();
		m.solve();
		m.output();
		/*/
		m.debug();
		//*/
	}
	
	public void debug() {
	}
	
	/*
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	/*/
	InputUtil in = new InputUtil();
	//*/
	PrintWriter out = new PrintWriter(System.out);
	//char[] S = null;
	int N = 0;
	int A = 0;
	int B = 0;
	String ans = "";
	
	public void input() throws IOException {
		/*
		S = br.readLine().toCharArray();
		/*/
		N = in.nextInt();
		A = in.nextInt();
		B = in.nextInt();
		//*/
		
	}

	public void solve() throws IOException {
		if(Math.abs(A-B)%2==0){
			ans = "Alice";
		} else {
			ans = "Borys";
		}
	}
	
	
	
	public void output() {
		out.println(ans);
		out.flush();
	}
}

//*
class InputUtil {
	//Static Fields
	private static final int BUFSIZ = 100000;
	
	//Fields
	protected InputStream in;
	private byte[] buf = null;
	private int ptr = 0;
	private int max = -1;
	private DataInputStream dis = null;
	//Constructors
	public InputUtil() {this(System.in,BUFSIZ);}
	public InputUtil(InputStream in, int bufsiz) {
		initBuf(bufsiz);
		initIn(in);
	}
	
	//Methods
	//Initializer
	protected void initIn(InputStream in) {dis = new DataInputStream(this.in = in);}
	protected void initBuf(int bufsiz) {buf = new byte[bufsiz];}
	
	//buffer operation
	private void next() throws IOException {ptr++; readBuf();}
	private void readBuf() throws IOException {
		if(ptr >= max && dis.available()>0) {
			if(max>0) Arrays.fill(buf,0,max,(byte)0);
			max = dis.read(buf);
			ptr = 0;
		}
	}
	
	//Number Input Reader/Parser
	private boolean isNum(byte b) {return '0' <= b && b <= '9'; }
	private boolean isMinus(byte b) {return b=='-'; }
 
	private int _nextInt() throws IOException {
		int sign = 1;
		int res = 0;
		byte c;
		while (!isNum(c=buf[ptr]) && !isMinus(c)) 
			next();
		if (isMinus(buf[ptr])) {
			sign = -1;
			next();
		}
		while (isNum(c=buf[ptr])) {
			res *= 10;
			res += c - '0' ;
			next();
		}
		next();
		return sign * res;
	}
	
	public int nextInt() throws IOException {
		readBuf();
		return _nextInt();
	}
 
	public int[] nextInt(int[] result) throws IOException {
		readBuf();
		for(int i=0; i<result.length; i++) {
			result[i] = _nextInt();
		}
		return result;
	}
	
	//Close 
	public void close() throws IOException {
		if(!this.in.equals(System.in)) 
			this.in.close();
	}
}
//*/


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

using namespace std;

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

int main()
{
  int64_t N;
  cin >> N;

  vector<int64_t> a(N);
  N_TIMES(n, N) {
    cin >> a[n];
  }
  sort(a.begin(), a.end());

  uint64_t n = *--a.end();

  int64_t m = n >> 1;
  if (n % 2 == 0) {
    auto itr = lower_bound(a.begin(), --a.end(), m);
    uint64_t d = distance(a.begin(), itr);
    if (itr == --a.end()) { --d; }
    
    if (d > 0) {
      if(abs(m - a[d - 1]) < abs(m - a[d])) {
        --d;
      }
    }
    
    cout << n << ' ' << a[d] << endl;
  } else {
    auto itr1 = lower_bound(a.begin(), --a.end(), m + 0);
    auto itr2 = lower_bound(a.begin(), --a.end(), m + 1);
    uint64_t d1 = distance(a.begin(), itr1);
    uint64_t d2 = distance(a.begin(), itr2);
    if (itr1 == --a.end()) { --d1; }
    if (itr2 == --a.end()) { --d2; }
    
    if (d1 > 0) {
      if(abs(m - a[d1 - 1]) < abs(m - a[d1])) {
        --d1;
      }
    }

    if (d2 < N) {
      if(abs(m - a[d2 + 1]) < abs(m - a[d2])) {
        ++d2;
      }
    }
    
    if (abs(m - a[d1]) < abs(m - a[d2])) {
      cout << n << ' ' << a[d1] << endl;
    } else {
      cout << n << ' ' << a[d2] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] h = new int[n];
		Arrays.setAll(h, i -> sc.nextInt());
		
		int[] dp = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(h[0] - h[1]);
		
		for (int i = 2; i < n; i++) {
			dp[i] = dp[i - 1] + Math.abs(h[i - 1] - h[i]);
			for (int j = 2; i - j >= 0 && j <= k; j++) {
				dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(h[i - j] - h[i]));
			}
		}
		
//		System.out.println(Arrays.toString(h));
//		System.out.println(Arrays.toString(dp));
		
		System.out.println(dp[n - 1]);
				
		sc.close();
	}

}




Measured memory_bytes: 51316
#include<stdio.h>
#include<iostream>
using namespace std;
int max(int a,int b)
{
	return a>b?a:b;
}
int a,b;
int main()
{
   scanf("%d%d",&a,&b);
   printf("%d",max(max(a+b,2*a-1),max(2*a-1,2*b-1)));	
   return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll H[205000];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> H[i];
    sort(H, H + N);
    ll ans = 0;
    for(int i = 0; i + K < N; i++) {
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	ll l, r;
	cin >> l >> r;
	int f = 2019;
	int len = r - l + 1;
	if(len >= f){
		cout << 0;
		return 0;
	}
	else{
		ll ans = 1e18;
		for(ll i = l; i <= r; i++){
			for(ll j = i + 1; j <= r; j++){
				ll res = (i % f) * (j % f);
				ans = min(ans, res % f);
			}
		}
		cout << ans;
	}
}

Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._


  val n = readInt
  val animals = readLine.trim.split(' ')

  println(
    animals.reduceLeft{(a, b) ⇒ if (a == "T" && b == "F") "F" else "T"}
  )
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 53460
#include<bits/stdc++.h>
#define N 200005

using namespace std;

vector<int> gr[N];
int n;

int fen[N];

int ch[N];
int num[N];
int nn;
int l[N], r[N];

void dfs(int x){
	ch[x]=1;
	l[x]=nn+1;
	for(auto j : gr[x]){
		if(!ch[j]) dfs(j);
	}
	r[x]=num[x]=++nn;
}

void update(int pos, int val){
//	printf("%d %d\n", pos, val);
	for(;pos<=n;pos+=(pos&(-pos))){
		fen[pos]+=val;
	}
}

int getSum(int pos){
	int ret=0;
	for(;pos;pos-=(pos&(-pos))){
		ret+=fen[pos];
	}
	return ret;
}

int main(){
	int q;
	scanf("%d %d", &n, &q);
	int t, u;
	int p, x;
	for(int i=0;i<n-1;i++){
		scanf("%d %d", &t, &u);
		gr[t].push_back(u);
		gr[u].push_back(t);
	}
	dfs(1);
//	for(int i=1;i<=n;i++) printf("aa %d %d\n", l[i], r[i]);
	for(int i=0;i<q;i++){
		scanf("%d %d", &p, &x);
//		printf("%d\n", x);
		update(l[p], x);
		update(r[p]+1, -x);
	}
	for(int i=1;i<=n;i++){
		printf("%d ", getSum(num[i]));
	}
	return 0;
}

Measured memory_bytes: 23424
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int main(){
  int n;
  cin >> n;
  map < string ,long long > mp;
  for(int i = 0 ; i < n ; i++){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  long long ans = 0;
  for(auto it : mp){
    ans += (it.second - 1) * it.second / 2;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main() {
    double a,b,th,S,L,h;
    cin >> a >> b >> th;
    S = a * b * sin(M_PI*th/180) / 2.0f;
    L = a + b + sqrt(a*a + b*b - 2.0f*a*b*cos(M_PI*th/180));
    h = b * sin(M_PI*th/180);
    printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);
    return 0;
}

Measured memory_bytes: 3472
A,B,C,D = map(int,input().split())
from fractions import gcd
CD = int(C*D/gcd(C,D))

B_both = B//(CD)
B_C = B//C
B_D = B//D
first_term = B-(B_C+B_D-B_both)
A -= 1
A_both = A//(CD)
A_C = A//C
A_D = A//D
second_term = A-(A_C+A_D-A_both)

print(first_term-second_term)




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

int main(){
  int n,a[26];
  cin>>n;
  for(int i=0;i<26;++i)a[i]=1e9;
  for(int i=0;i<n;++i){
    string s;
    cin>>s;
    int b[26]={};
    for(int j=0;j<s.size();++j){
        b[s[j]-'a']++;
    }
    for(int j=0;j<26;++j){
        a[j]=min(a[j],b[j]);
    }
  }
  for(int i=0;i<26;++i){
    if(a[i]==1e9)continue;
    for(int j=0;j<a[i];++j){
        cout << (char)('a'+i);
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
S = [x for x in input()]
op_cnt = len(S) - 1  # すき間の個数
ans = 0

for i in range(2 ** op_cnt):

    ops = [""] * op_cnt

    for j in range(op_cnt):
        if (i >> j) & 1:
            ops[op_cnt - 1 - j] = "+"

    formula = S[0]
    for op, num in zip(ops, S[1:]):
        formula += op + num

    ans += eval(formula)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    long long time = 60 * H2 + M2 - 60 * H1 - M1;
    cout << time - K << "\n";
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
int main(){
    int a;
    scanf("%d", &a);
    getchar();
    char string[105];
    scanf("%[^\n]", string);
    int len = strlen(string);
    // if(len > a){
    //     strcpy(string + a, "...");
    // }
    // printf("%s\n", string);
    for(int i = 0; i <= a && string[i] != '\0'; i++){
        if(i == a){
            printf("...");
            break;
        }
        else{
            printf("%c", string[i]);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1696
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> arr(n, 0);
  for(int i = 0; i < n; i++) cin >> arr[i];
  sort(arr.begin(), arr.end());
  for(int i = 1; i <= arr[0]; i++){
    bool iscd = true;
    for(size_t j = 0; j < arr.size(); j++) iscd &= (arr[j] % i == 0);
    if(iscd) cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
a,b = map(int, input().split())
t = 0
if a > b:
    t = t + a
    a = a - 1
else:
    t = t + b
    b = b - 1
if a > b:
    t = t + a
    a = a - 1
else:
    t = t + b
    b = b - 1
print(t)

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

int main(void) {

  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  double m = sum*(1.0)/n;
  double dif[n];
  for (int i = 0; i < n; i++) {
    dif[i] = fabs(a[i]-m);
  }
  double min = -1.0;
  int number;
  for (int i = 0; i < n; i++) {
    if (min < 0 || dif[i] < min) {
      min = dif[i];
      number = i;
    }
  }
  printf("%d\n", number);

  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 __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}
vector<lli> a;
vector<vector<lli>> dp;
vector<vector<bool>> vis;
lli go(int l, int r){
	if(vis[l][r])return dp[l][r];
	vis[l][r]=1;
	if(l==r)return dp[l][r]=a[l];
	return dp[l][r]=max(a[l]-go(l+1,r),a[r]-go(l,r-1));	

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	a.assign(n,0);
	dp.assign(n,vector<lli>(n,0));
	vis.assign(n,vector<bool>(n,0));
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cout<<go(0,n-1)<<endl;;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<string,int> mp;
  mp["SUN"] = 0;
  mp["MON"] = 1;
  mp["TUE"] = 2;
  mp["WED"] = 3;
  mp["THU"] = 4;
  mp["FRI"] = 5;
  mp["SAT"] = 6;
  string s;
  cin >> s;
  cout << 7 - mp[s] << endl;
  return 0;
}


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

int main() {
    string s; cin >> s;
    int len = 0;
    int maxlen = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            len += 1;
            maxlen = max(maxlen, len);
        } else {
            len = 0;
        }
    }
    cout << maxlen << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

b = Array.new(n, 0)
n.times {|i| b[i] = b[i-1] + a[i]}

ans = 0
m = 10 ** 9 + 7
n.times do |i|
    ans = (ans + a[i] * (b[-1] - b[i])) % m
end

p ans

Measured memory_bytes: 35440
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

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

    int n, m, sol = 0;
    cin >> n >> m;

    vector<int> h(n + 1);
    vector<vector<int>> adj(n + 1);

    for (int i = 1; i <= n; ++i)
        cin >> h[i];

    int x, y;
    for (int i = 0; i < m; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    bool great = true;
    for (int i = 1; i <= n; ++i)
    {
        for (int x : adj[i])
        {
            if (h[x] >= h[i])
            {
                great = false;
                break;
            }
        }
        if (great == true)
            sol += 1;
        great = true;
    }

    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 8744
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){ 
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    vector<int> vec = {a1, a2, a3};
    sort(vec.begin(), vec.end());
    cout << vec[2] - vec[0] << endl;
}

Measured memory_bytes: 256
s = int(input())

def f(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1

a = [s]
i = 1
while True:
    s = f(s)
    i += 1
    if s in a:
        break
    a += [s]
print(i)

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

def isOk(x):
    cnt = 0
    for a in A:
        cnt += (a - 1) // x
    return cnt <= K

ok = max(A)
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 30984
#include <iostream>
#include <utility>

using ll_t = long long;
const int MAXN = 300 + 1;
const int INF = (int)1e9 + 1;

int edge[MAXN][MAXN];
std::pair<int, int> f[MAXN][MAXN];
bool used[MAXN];

void dijkstra(int n, int l, int s) {
  for (int i = 1; i <= n; ++i) {
    used[i] = false;
    if (i == s) f[s][s] = std::make_pair(0, l);
    else f[s][i] = std::make_pair(INF, 0);
  }

  auto better = [](const std::pair<int, int> &x, const std::pair<int, int> &y) {
    if (x.first < y.first) return true;
    if (x.first == y.first && x.second > y.second) return true;
    return false;
  };

  while (true) {
    int v = -1;
    for (int u = 1; u <= n; ++u) {
      if (!used[u] && (v == -1 || better(f[s][u], f[s][v]))) v = u;
    }
    if (v == -1 || f[s][v].first >= INF) break;
    used[v] = true;
    for (int u = 1; u <= n; ++u) {
      if (u == v || edge[v][u] > l) continue;
      auto cur = f[s][v];
      if (cur.second - edge[v][u] < 0) {
        ++cur.first;
        cur.second = l;
      }
      cur.second -= edge[v][u];
      if (better(cur, f[s][u])) f[s][u] = cur;
    }
  }
}

void solve(int n, int l) {
  for (int s = 1; s <= n; ++s) {
    dijkstra(n, l, s);
  }
}

int main() {
  int n, m, l;
  std::cin >> n >> m >> l;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      edge[i][j] = edge[j][i] = INF;
    }
  }
  for (int i = 0, u, v, w; i < m; ++i) {
    std::cin >> u >> v >> w;
    edge[u][v] = edge[v][u] = w;
  }
  
  solve(n, l);
  
  int q;
  std::cin >> q;
  for (int i = 0, s, t; i < q; ++i) {
    std::cin >> s >> t;
    std::cout << (f[s][t].first >= INF ? -1 : f[s][t].first) << std::endl;
  }
  return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define ll long long
#define P pair<int,int>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    vector<ll> p(n);
    for(ll i = 0; i<n; i++)cin>>p[i];
    vector<ll> q(n);
    for(ll i = 0; i<n; i++)cin>>q[i];
    vector<ll> a(n);
    a = p;
    sort(a.begin(),a.end());
    ll cnt = -1;
    ll ap,aq;
    ap=aq=-1;

    while(next_permutation(a.begin(),a.end())){
        cnt++;
        if(p == a){
            ap=cnt;
            if(aq != -1)break;
        }
        if(q == a){
            aq =cnt;
            if(ap != -1)break;
        }
    }
    ll ans = abs(ap - aq);
    cout<< ans <<endl;
}


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

using namespace std;
typedef long long ll;

struct XStruct
{
	int x;
	int Left;
	int Right;

	bool operator<(const XStruct &x) const
	{
		return Left < x.Left;
	};
};

int main()
{
	int N;
	int X[100000];
	int L[100000];
	
	XStruct XData[100000];
	
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d %d", &X[i], &L[i]);
		XData[i].x = X[i];
		XData[i].Left = X[i] + L[i];
		XData[i].Right = X[i] - L[i];
	}
	
	sort(XData, XData+N);
	
	int count = 0;
	int current = -1000000009;
	for(int i = 0; i < N; i++){
		if(XData[i].Right >= current){
			current = XData[i].Left;
			count++;
		}
	}
	
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 2176