akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

int computeXOR(int n) 
{ 
   if(n == 0)return 0; 
    // Modulus operator are expensive on most of the  
    // computers. n & 3 will be equivalent to n % 4.    

    switch(n & 3) // n % 4  
    { 
    case 0: return n;     // if n is multiple of 4 
    case 1: return 1;     // If n % 4 gives remainder 1   
    case 2: return n + 1; // If n % 4 gives remainder 2     
    case 3: return 0;     // If n % 4 gives remainder 3   
    } 
} 
int32_t main(){_

   int a, b;
   cin>>a>>b;

   int R = computeXOR(b);
   int L = computeXOR(a-1);

   cerr << L << ' ' << R << endl;

   cout<<(L^R); 
   

   #warning make sure N size is correct!
   return 0;
}

Measured memory_bytes: 256
A = [i for i in input().split()]
S = []

for i in A:
    if i in ['+', '-', '*']:
        b = S.pop()
        a = S.pop()

    if i == '+':
        S.append(a + b)
    elif i == '-':
        S.append(a - b)
    elif i == '*':
        S.append(a * b)
    else:
        S.append(int(i))

print(S.pop())


Measured memory_bytes: 5604
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1e9;

int main() {

  int n; cin >> n;
  long long int t = 1;
  long long int a = 1;
  for(int i=0; i<n; i++){
    cerr << t << " " << a << endl;
    long long int nt, na;
    cin >> nt >> na;
    long long int x = max((t+nt-1)/nt, (a+na-1)/na);
    t = nt * x;
    a = na * x;
  }
  cerr << t << " " << a << endl;
  cout << t + a << endl;

  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("03")
//#pragma GCC target("avx2")
 
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sqr(a) (a)*(a)
#define um unordered_map 
#define us unordered_set
using namespace std;
 
hash<string> hfn;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef double dbl;
typedef unsigned int ui;
const int inf = 2e9;
const ll mod = 1e9+7;
const ld eps = 1e-7;
const ll biginf = 1e18;
const ld pi = acosl(-1);

void solve()
{
  int n, k;
  cin >> n >> k;
  vector<int> v(n), dp(k+1, 1);
  for(auto& i : v)
    cin >> i;
  dp[0] = 0;
  for(int i = 1; i <= k; i++)
  {
    for(int j = 0; j < n; j++)
    {
      if(i - v[j] >= 0)
        dp[i] &= dp[i- v[j]];
    }
    dp[i] ^= 1;
  }
  if(dp[k])
    cout << "First";
  else
    cout << "Second";
}
 
void multisolve()
{
  int t;
  cin >> t;
  while(t--)
    solve();
}
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  //freopen("hull.in", "r", stdin);
  //freopen("hull.out", "w", stdout);
  solve();
  //multisolve();
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> h(n);
  REP(i, n)
  {
    cin >> h[i];
  }

  int ans = 0;
  FOR(i, 1, n)
  {
    if (h[i - 1] >= h[i])
    {
      int tmp = 0;
      while (i < n && h[i - 1] >= h[i])
      {
        tmp++;
        i++;
      }
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<pair<ll, ll>> xy(n);
    rep(i, n) cin >> xy[i].first >> xy[i].second;
    vector<ll> p(n);
    rep(i, n) p[i] = i;
    double ans = 0;
    do {
        double tmp = 0;
        rep(i, n - 1) {
            ll dx = xy[p[i]].first - xy[p[i + 1]].first;
            ll dy = xy[p[i]].second - xy[p[i + 1]].second;
            tmp += sqrt(dx * dx + dy * dy);
        }
        ans += tmp;
    }
    while(next_permutation(all(p)));
    ll pat = 1;
    rep(i, n) pat *= (i + 1);
    printf("%.10f\n", ans / pat);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  ill x;
  cin >> x;
  ill n = 100;
  for(int i = 1; 1; i++) {
    n *= 1.01;
    if(n >= x) {
      cout << i;
      return 0;
    }
  }
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll dif(vector<int> &v){
    ll sum = 0;
    rep(i,0,v.size()-1)sum += abs(v[i+1] - v[i]);
    return sum;
}
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    sort(V.begin(), V.end());
    ll maxi = 0;
    //N is odd
    if(N % 2 == 1){
        //small big small ..
        vector<int> arr(N);
        arr[0] = V[N/2];
        arr[N-1] = V[N/2-1];
        rep(i,0,(N+1)/2-2){
            arr[i*2+2] = V[i];
        }
        rep(i,0,N/2){
            arr[i*2+1] = V[i+N/2+1];
        }
        maxi = max(maxi, dif(arr));
        //big small big ..
        arr[0] = V[N/2];
        arr[N-1] = V[N/2+1];
        rep(i,0,(N+1)/2-2){
            arr[i*2+2] = V[N-i-1];
        }
        rep(i,0,N/2){
            arr[i*2+1] = V[i];
        }
        maxi = max(maxi, dif(arr));
        //rep(i,0,N)cout << arr[i] << " ";
    }else{
        vector<int> arr(N);
        rep(i,0,N/2){
            arr[N-i*2-2] = V[i];
        }
        rep(i,0,N/2){
            arr[N-i*2-1] = V[i + N/2];
        }
        maxi = max(maxi, dif(arr));
        //rep(i,0,N)cout << arr[i] << " ";

    }
    cout << maxi << endl;
}

Measured memory_bytes: 1024
# -*- coding:utf-8 -*-
N = int(input())
factor = 0
a = list(map(int, input().split()))
b = [ tmp for tmp in a if tmp%4 == 0 ]
c = [ tmp for tmp in a if tmp%2 == 0 ]
d = [ tmp for tmp in a if tmp%2 != 0 ]
if len(c)-len(b) != 0 and len(b)-len(d) >= 0:
    print("Yes")
elif len(c)-len(b) == 0 and len(b)+1 >= len(d):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include <stdio.h>
#define MAX 8
#define FREE 0
#define NOT_FREE 1
int Q[MAX][MAX];
int col[MAX],row[MAX],dpos[MAX*2-1], dneg[MAX*2-1];
int putQueen(int);
void print(void);


int main()
{
  int i,j,n;
  int r,c;

  //?????????
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
      Q[i][j]=0;
    }
  }
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    Q[r][c]=1;
  }

  //?????????
  for(i=0;i<MAX;i++){
    col[i]=FREE;
    row[i]=FREE;
  }
  for(i=0;i<MAX*2-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
  
  putQueen(0);

  return 0;
}

int putQueen(int i)
{
  int j;
  if(i==MAX) print();
  for(j=0;j<MAX;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+MAX-1]==NOT_FREE) continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+MAX-1]=NOT_FREE;
    putQueen(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+MAX-1]=FREE;
  }
}

void print()
{
  int i,j;
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
      if(Q[i][j]){
	if(row[i]!=j) return;
      }
    }
  }
   
  for(i=0;i<MAX;i++){
    for(j=0;j<MAX;j++){
      if(row[i]==j) printf("Q");
       else printf(".");
     }
     printf("\n");
   }
}

Measured memory_bytes: 572
// 計数ソート
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 2000000
//const int INFTY = 2147483647;

void CountingSort(int base[], int sort[], int n, int max);

int main(void)
{

    int n;
    int max = 0;

    int *A = new int[MAX_N + 1];
    int *B = new int[MAX_N + 1];

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> A[i + 1];

        if( max < A[i + 1] )
        {
            // 最大値を保存する
            max = A[i + 1];
        }
    }

    CountingSort(&A[0], &B[0], n, max);

    for(int i = 1; i <= n; i++)
    {
        if( i > 1 )
        {
            printf(" ");
        }

        printf("%d", B[i]);
    }

    printf("\n");

    return 0;
}

// 計数ソートを実施する関数
void CountingSort(int base[], int sort[], int n, int max)
{
    int *count = new int[max + 1];
	//int count[10];

    for(int i = 0; i <= max; i++)
    {
        count[i] = 0;
    }

    // count[]に各要素の出現回数を記録する
    for(int i = 0; i < n; i++)
    {
        count[ base[i + 1] ]++;
    }

    // count[]に i 以下の数の出現数を記録する
    for(int i = 1; i <= max; i++)
    {
        count[i] += count[i - 1];
    }

    // count[]に i 以下の数の出現数を記録する
    for(int i = n; i > 0; i--)
    {
        sort[ count[ base[i] ] ] = base[i];
        count[ base[i] ]--;
    }

    return;
}



Measured memory_bytes: 18772
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
      for(var j=i+i;j<=max;j+=i){
         arr[j]=false;
      }
   }
   var result=[];
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)result.push(arr[i]);
   }
   return result;
}
var p=prime(10000000);
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var a=input.trim()-0;
var str=a+": ";
var arr=[];
for(var i=0;i<p.length;i++){
   if(a==1)break;
   while(a%p[i]==0){
      a/=p[i];
      arr.push(p[i]);
   }
}
if(a!=1)arr=[a];
console.log(str+arr.join(" "));

Measured memory_bytes: 205956
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int A[4009], sum[2][2009];
int fw[2][2009][2009];
int dp[2009][2009];
char C[4009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,2*N) cin>>C[i]>>A[i];
    rep(i,2*N) A[i]--;
    
    rep(i,2*N){
        int a=A[i];
        int c=(C[i]=='B');
        rep(j,N+1) fw[c][a][j]=sum[c][a]+sum[c^1][j];
        for(int j=a;j>=0;j--) sum[c][j]++;
    }
    
    rep(i,2009)rep(j,2009) dp[i][j]=INF;
    dp[0][0]=0;
    rep(i,N+1)rep(j,N+1){
        if(i<N) chmin(dp[i+1][j],dp[i][j]+fw[1][i][j]);
        if(j<N) chmin(dp[i][j+1],dp[i][j]+fw[0][j][i]);
    }
    cout1(dp[N][N]);
}

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


int cmp( const void* a ,const void* b )
{
	return *( int* )b - *( int* )a ;
}


int main( void )
{
	int n ;
	int base_k ,add_k ;
	int kiji ,topy ;

	int cal[ 100 ] ;

	scanf( "%d" ,&n ) ;
	scanf( "%d %d" ,&base_k ,&add_k ) ;
	scanf( "%d" ,&kiji ) ;

	int sum = kiji ;

	int i ,j ;
	for( i = 0 ; i < n ; ++i )
	{
		scanf( "%d" ,cal + i ) ;

		sum += cal[ i ] ;
	}

	int best = sum / ( base_k + ( add_k * n ) ) ;

	qsort( cal ,n ,sizeof( int ) ,cmp ) ;

	while( n-- )
	{
		sum = kiji ;

		for( i = 0 ; i < n ; ++i )
		{
			sum += cal[ i ] ;
		}

		sum /= base_k + ( add_k * n ) ;

		best = best < sum ? sum : best ;
	}

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


	return 0 ;
}

Measured memory_bytes: 1852
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define maxn 100005
using namespace std;
long long n,b,a,h[maxn];
bool check(long long x)
{
	long long d=a-b;
	long long u=0,g=0;
	for(long long i=0;i<n;i++)
	{
		u=h[i]-b*x;
		if(u<=0)
			continue;
		else
		{
			g+=u/d;
			g+=(u%d!=0);
			if(g>x)
				return false;
		}
	}
	if(g>x)
		return false;
	return true;
}
int main()
{
	cin>>n>>a>>b;
	for(long long i=0;i<n;i++)
		cin>>h[i];
	long long lbound=0,ubound=1e9,ans=ubound;
	while(lbound<=ubound)
	{
		long long mid=(lbound+ubound)/2;
		if(check(mid))
		{
			ubound=mid-1;
			ans=min(ans,mid);
		}
		else
			lbound=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int n;
  bool ans = true;
  cin >> n;
  
  vector<int> a(n);
  
  for(int i = 0;i<n;i++){
    cin >> a.at(i);
  }
  
  for(int i=0;i<n;i++){
    if(a.at(i) % 2 == 0){
      if(a.at(i) % 3 != 0 && a.at(i) % 5 != 0) ans = false;
    }
  }
  
  if(ans == true) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
      
}



Measured memory_bytes: 256
///-BISMILLAHIR RAHMANIR RAHIM-///
#include <bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define pb push_back
#define scn(n) scanf("%lld",&n)
#define pi acos(-1)
#define ll long long
#define llu unsigned long long
#define mod 1000000007
int main()
{
    while(1)
    {
        ll n;
        cin>>n;
        if(n==0) break;
        ll a[n],i,sum=0;
        double m,ans=0;
        for(i=1; i<=n; i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        m=(double)sum/n;
        ///cout<<m<<endl;
        for(i=1; i<=n; i++)
        {
            ans+=(double)((a[i]-m)*(a[i]-m));
        }
        ans=(double)ans/n;
        printf("%.5lf\n",sqrt(ans));
    }
    return 0;
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(),(x).end()
#define lowbit(x) x&-x
#define pb push_back
#define ls (id<<1)
#define rs (id<<1|1)
#define Rint register int
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MAXN=1e6+10,MAXM=4e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int MOD=1e9+7,mod=998244353;
const int inv2=5e8+4;
const int Lim=1<<20;


void solve()
{
    int w,s;
    R(s,w);
    if(w>=s)W("unsafe");
    else W("safe");
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	int t=1;
	//R(t);
	while(t--)solve();
	return 0;
}


Measured memory_bytes: 3828
#include <stdio.h>

int main(int argc,char* argv[]){
  double x1,y1,x2,y2,x3,y3,x4,y4;
  int n,i;
  double s_x1,s_y1,s_x2,s_y2,suc;
  
  scanf("%d",&n);

  for(i = 0;i < n; ++i){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
    
    s_x1 = x1 - x2;
    s_y1 = y1 - y2;
    s_x2 = x3 - x4;
    s_y2 = y3 - y4;
    
    suc = s_x1 * s_y2 - s_y1 * s_x2;
    
    if(suc <= 1e-10 && suc >= -1e-10){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){
  int n,ans=4000000,sum,s,t;
  scanf("%d",&n);
  
  int a[n+1];
  for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
  
  for(int i=-100;i<=100;i++){
    sum=0;
    for(int j=1;j<=n;j++){
      s=a[j]-i;
      t=s*s;
      sum+=t;
    }
    if(sum<ans){
      ans=sum;
    }
  }
  
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int N; cin >> N;
    vector<int> fib(N + 1);
    fib[0] = 1; fib[1] = 1;
    for (int i = 2; i <= N; i++) {
        fib[i] = fib[i - 1] + fib[i - 2];
    }

    cout << fib[N] << endl;
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>
#include<iomanip>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/


int main()
{
	long long n, m, d;
	double ans;

	cin >> n >> m >> d;
	if (d == 0) {
		ans = double((m - 1)) / n;
	}
	else {
		//ans = (m - 1)*((2 / n)*(d / n) + (1 - 2*(d / n))*(2/n));
		ans = double((m - 1)*(2*n-2*d))/(n*n);
	}

	cout << setprecision(6) << fixed;
	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)
 
 
def solve(N: int, K: int, h: "List[int]"):
    INF = float('inf')
    dp = [INF] * N
    dp[0] = 0
    for i in range(N):
        for j in range(K):
            if i + j + 1 < N:
                dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(h[i + j + 1] - h[i]))
    print(dp[N - 1])
    return
 
 
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)
 
if __name__ == '__main__':
    main()

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

using namespace std;

int n;
char s[100];

int guess(int i) {
    printf("%d\n", i); fflush(stdout);
    scanf("%s", s);
    if (s[0] == 'V') return 0;
    if (s[0] == 'M') return 1;
    return -1;
}

int inv(int x) {
    if (x == 1) return -1;
    if (x == -1) return 1;
    return 0;
}

int main() {
    scanf("%d", &n);

    int lo = 1;
    int hi = n - 1;
    int last = inv(guess(0));
    if (last == 0) return 0;
    while (lo <= hi) {
        // printf("%d %d\n", lo, hi); fflush(stdout);
        int mid = (lo + hi)/2;
        int c = guess(mid); if (c == 0) return 0;
        if (((mid-lo)%2 == 0 && c == last) || ((mid-lo)%2 == 1 && c != last))
            lo = mid + 1, last = inv(c);
        else
            hi = mid - 1;
    }
    return 0;
}

Measured memory_bytes: 980
#include <iostream>
#include <stdio.h>
#define EPS 0.0000001
using namespace std;

int main()
{
    double a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f) {
		//A*x=y
		//x=A^-1*y

		double x = (c * e + f * -b)/(a*e - b*d) + EPS;
		double y = (c * -d + f * a)/(a*e - b*d) + EPS;
		printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int S;
  cin >> S;
  int L = S / 100;
  int R = S % 100;
  if (1 <= L && L <= 12)
  {
    if (1 <= R && R <= 12)
      printf("AMBIGUOUS\n");
    else
      printf("MMYY\n");
  }
  else
  {
    if (1 <= R && R <= 12)
      printf("YYMM\n");
    else
      printf("NA\n");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long double dp[303][303][303];

long double solve(int z,int o,int t,int n){
  if(z<0||o<0||t<0)
    return 0;
  if(o==0 && z==0 && t==0)
    return 0;
  if(dp[z][o][t]>0)
    return dp[z][o][t];
  long double x=z+o+t;
  long double y=n+ z*solve(z-1,o,t,n)+o*solve(z+1,o-1,t,n)+t*solve(z,o+1,t-1,n);
  dp[z][o][t]=y/x;
  return dp[z][o][t];  
}

int main() {
  int n;
  cin>>n;
  int  a[n],z=0,o=0,t=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]==1)
      z++;
    else if(a[i]==2)
      o++;
    else
      t++;
  }
  memset(dp,-1,sizeof(dp));
  cout<<setprecision(10)<<solve(z,o,t,n); 
}

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

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

	vector<int> V(N), C(N);
	for (int i = 0; i < N; ++i) {
		cin >> V[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
	}

	vector<int> dp(N + 1, 0);
	for (int i = 0; i < N + 1; ++i) {
		dp[i + 1] = max(dp[i], dp[i] + V[i] - C[i]);
	}

	cout << dp[N] << endl;	
}



Measured memory_bytes: 256
d,g=map(int,input().split())
pc=[list(map(int, input().split())) for _ in range(d)]
t1=[bin(2**d+i)[3::] for i in range(2**d)]
a=[]
for t in t1:
    ta=0
    tb=0
    for i in range(d):
        if t[i]=='1':
            ta+=pc[i][0]
            tb+=100*pc[i][0]*(i+1)+pc[i][1]
    if tb>=g:
        a.append(ta)
    else:
        for i in range(d-1,-1,-1):
            if t[i]=='0':
                if 100*(i+1)*pc[i][0]>=g-tb:
                    if (g-tb)%(100*(i+1))==0:
                        ta+=(g-tb)//(100*(i+1))
                        tb+=100*(i+1)*((g-tb)//(100*(i+1)))
                    else:
                        ta+=(g-tb)//(100*(i+1))+1
                        tb+=100*(i+1)*((g-tb)//(100*(i+1))+1)
                break
        if tb>=g:
            a.append(ta)
print(min(a))

Measured memory_bytes: 3064
#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 mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18

typedef long long ll;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> o_tree;

void solve()
{
    ll n;
    cin >> n;
    if (n == 2)
    {
        cout << "1\n";
        return;
    }
    ll res = 0;
    vll fact;
    ll i;
    for (i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            fact.pb(i);
            if (i * i != n)
            {
                fact.pb(n / i);
            }
        }
    }
    fact.pb(n);
    ll n2 = n-1;
    vll fact2;
    for (i = 2; i * i <= n2; i++)
    {
        if (n2 % i == 0)
        {
            fact2.pb(i);
            if (i * i != n2)
            {
                fact2.pb(n2 / i);
            }
        }
    }
    fact.pb(n2);
    res+=sz(fact2);
    for (auto it : fact)
    {
        ll noo = n / it;
        ll nn =n;
        while(nn%it==0)
        {
            nn/=it;
        }
        if(nn%it==1)
        {
            res++;
        }

    }
    cout << res << "\n";
}

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

    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    cout << setprecision(20);

    ll t = 1;

    // cin>>t;

    while (t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3596
/*input
6 3
2 1
2 3
4 1
4 2
6 1
2 6
4 6
6 5
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

const int N = 1e5+1;
int vis[N];
vi adj[N];
int par[N];
queue<int> q;
int indeg[N];
int got[N];
vi topso;
int n,m;


void solve(){
    cin >> n >> m;
    REP(i,n+m-1){
       int a,b;cin >> a >> b;
       adj[a].pb(b);
       indeg[b]++;
    }
    RE(u,n){
      if(!indeg[u]){
         q.push(u);
         par[u] = 0;
      }
    }
    while(!q.empty()){
      int x = q.front();q.pop();
      for(int v:adj[x]){
        indeg[v]--;
        if(indeg[v] == 0){
          par[v] = x;
          q.push(v);
        }
      }

    }
    RE(i,n)cout << par[i] << endl;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

Measured memory_bytes: 7936
#include <cstdio>
#include <vector>
#include <set>
#include <list>

void simulate(int, std::vector<std::list<int>>&);

int main()
{
    int N, p;
    scanf("%d", &N);
    std::vector<std::list<int>> pl(N); /* index???????????°??§??????????????? */
    for (int i = 0; i < N; i++) {
        scanf("%d", &p);
        pl[p - 1].push_back(i + 1);
    }
    simulate(N, pl);    
    return 0;
}

void simulate(int N, std::vector<std::list<int>>& pl)
{
    std::vector<int> seats(N, -1); /* ??????????????§?????¨ */
    
    std::set<int> next;
    std::set<int> vacant_seats; /* ??????????????? */
    
    for (int i = 0; i < N; i++) {
        if (!pl[i].empty()) {
            next.insert(i);
        }
        vacant_seats.insert(i);
    }
    
    while (!vacant_seats.empty()) {
        int n = *next.begin();        
        
        next.erase(n);
        seats[n] = pl[n].front();       
        pl[n].pop_front();

        vacant_seats.erase(n);
        auto it = vacant_seats.upper_bound(n);
        if (it == vacant_seats.end()) {
            it = vacant_seats.begin();
        }
                
        if (!pl[n].empty()) {
            pl[*it].splice(pl[*it].end(), pl[n]);
            next.insert(*it);
        }
    }

    for (int num : seats) {
        printf("%d\n", num);
    }
}

Measured memory_bytes: 15084
n = int(input())
h = list(map(int, input().split()))
h = [0] + h

is_able = True
for i in range(n):
  if h[i] < h[i+1]:
    h[i+1] -= 1
  elif h[i] == h[i+1]:
    pass
  else:
    is_able = False
    break

print('Yes' if is_able else 'No')

Measured memory_bytes: 14396
n, m = map(int, input().split())
array=list(map(int, input().split()))
all = sum(array)
flag = 0
border = all/(4*m)
for i in range(n):
  if array[i-1] >= border:
    flag += 1
    
if flag >= m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;

int n;
string s[2];

signed main() {
	int i, j;
	
	cin >> n;
	cin >> s[0] >> s[1];
	
	vector<int> cnts;
	int cnt = 1;
	for (i = 1; i < n; i++) {
		if (s[0][i] != s[0][i - 1]) {
			cnts.push_back(cnt);
			cnt = 0;
		}
		cnt++;
	}
	cnts.push_back(cnt);
	
	int ans = 3 * cnts[0];
	for (i = 1; i < cnts.size(); i++) {
		if (cnts[i - 1] == 2 && cnts[i] == 2) ans *= 3;
		if (cnts[i - 1] == 1) ans *= 2;
		ans %= 1000000007;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int sum = sc.nextInt();

        int count = 0;

        for(int i=0;i<=sum;i++){
            for(int j=0;j<=sum;j++){
                int value = r*i + g*j;

                if(value<=sum && (sum-value)%b==0)
                    count++;
            }
        }

        System.out.println(count);

    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define mx 100001
#define tc int t;cin>>t;for(int raf=1;raf<=t;raf++)
#define fm cout<<"Case "<<raf<<": "
using namespace std;
int main()
{
    int b,c,d,e,f,i,j,n;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)cin>>a[i];
    sort(a, a+n);
    cout<<(a[n/2]-a[n/2-1])<<endl;













    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;

template <class T>
using lim = numeric_limits<T>;

vector<string> perms;
void permute(string str, string out){
	if(str.size() == 0){
		perms.push_back(out);
		return;
	}
	
	for (int i = 0; i < (int)str.size(); i++){
		permute(str.substr(1), out+str[0]);
		rotate(str.begin(),str.begin()+1,str.end());
	}
}

int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	int N, M, R;
	cin >> N >> M >> R;
	
	int r[R];
	for (int i = 0; i < R; i++){
		cin >> r[i];
		r[i]--;
	}
	
	ll graph[N][N];
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			if (i == j) graph[i][j] = 0;
			else graph[i][j] = lim<int>::max();
		}
	}
	
	for (int i = 0; i < M; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		graph[a][b] = c;
		graph[b][a] = c;
	}
	
	for (int k = 0; k < N; k++){
		for (int i = 0; i < N; i++){
			for (int j = 0; j < N; j++){
				graph[i][j] = min(graph[i][j], graph[i][k]+graph[k][j]);
			}
		}
	}
	
	string s = "";
	for (int i = 0; i < R; i++){
		s += i+'0';
	}
	
	permute(s,"");
	
	ll ans = lim<ll>::max();
	for (int p = 0; p < (int) perms.size(); p++){
		string perm = perms[p];
		ll total = 0;
		for (int i = 0; i < R-1; i++){
			int curr = perm[i]-'0';
			int next = perm[i+1]-'0';
			total += graph[r[curr]][r[next]];
		}
		ans = min(ans, total);
	}
	
	cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; i++) cin >> D[i];

  if (D[0] != 0) {
    cout << 0 << endl;
    return 0;
  }
  
  for (int i = 1; i < N; i++) {
    if (D[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  vector<int> dist(N);
  for (int i = 0; i < N; i++) dist[D[i]]++;

  long long ans = 1;
  int v = 1;
  for (int i = 1; i < N; i++) {
    long long tmp = (dist[i - 1] == 0 ? 0 : 1);
    for (int j = 0; j < dist[i]; j++) tmp = tmp * dist[i - 1] % 998244353;
    ans = ans * tmp % 998244353;
    v += dist[i];
    if (v == N) break;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z), SUM_AB(X*Y), SUM_ABC(K*Z);
    for (int i=0; i<X; i++) {
        cin >> A[i];
    }
    for (int i=0; i<Y; i++) {
        cin >> B[i];
    }
    for (int i=0; i<Z; i++) {
        cin >> C[i];
    }
    
    
    for (int i=0; i<X; i++) {
        for (int j=0; j<Y; j++) {
            SUM_AB[(i*Y)+j] = A[i]+B[j];
        }
    }
    sort(SUM_AB.begin(), SUM_AB.end(), greater<long long>());
    
    for (int i=0; i<K && i<SUM_AB.size(); i++) {
        for (int j=0; j<Z; j++) {
            SUM_ABC[(i*Z)+j] = SUM_AB[i]+C[j];
        }
    }
    
    sort(SUM_ABC.begin(), SUM_ABC.end(), greater<long long>());
    
    for (int i=0; i<K; i++) {
        cout << SUM_ABC[i] << endl;
    }
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[5][5],dp[5010],d1[25000010],ansn,an1;
int main(){
	cin>>n;
	for (int i=1;i<=2;i++)cin>>a[i][1]>>a[i][2]>>a[i][3];
	for (int i=1;i<=3;i++)
		for (int j=0;j+a[1][i]<=n;j++)dp[j+a[1][i]]=max(dp[j+a[1][i]],dp[j]+a[2][i]);
	for (int j=0;j<=n;j++)ansn=max(ansn,dp[j]+n-j);
	for (int i=1;i<=3;i++)
		for (int j=0;j+a[2][i]<=ansn;j++)d1[j+a[2][i]]=max(d1[j+a[2][i]],d1[j]+a[1][i]);
	for (int j=0;j<=ansn;j++)an1=max(an1,d1[j]+ansn-j);
	cout<<an1<<endl;
	return 0;
}

Measured memory_bytes: 195584
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void Change(string,int);
string Change2(int);
int cal1,cal2,len;
int main(){
  int Q,Max,cal,i,j,k,cnt;
  string N;
  cin >> Q;
  for(i=0;i<Q;i++){
    cnt=0;
    cin >> N;
    while(1){
      Max=0; 
      len=N.size();
      if(len==1) break;
      for(j=1;j<len;j++){
	cal1=cal2=0;
	Change(N,j);
	cal=cal1*cal2;
	Max=max(cal,Max);
	if(Max==0){
	  cnt++;
	  break;
	}
      }
      if(Max==0) break;
      N=Change2(Max);
      cnt++;
      if(cnt==100000000) break;
    }
    if(cnt==100000000) cout << -1 << endl;
    else cout << cnt << endl;
  }
  return 0;
}
void Change(string N,int s){
  int x=1,i,cnt;
  i=0;
  cnt=s;
  while(cnt){
    cal1=cal1*x+(N[i]-'0');
    x=10;
    i++;
    cnt--;
  }
  x=1;
  i=s;
  cnt=len-s;
  while(cnt){
    cal2=cal2*x+(N[i]-'0');
    x=10;
    i++;
    cnt--;
  }
}
string Change2(int n){
  string retstr;
  int l=0,cp=n,i;
  while(cp){
    cp/=10;
    l++;
  }
  for(i=0;i<l;i++){
    retstr+=n%10+'0';
    n/=10;
  }
  reverse(retstr.begin(),retstr.end());
  return retstr;
}

Measured memory_bytes: 1212
n = gets.to_i
abc = []
n.times { |i|
  abc[i] = gets.split.map(&:to_i)
}

dp = []
dp[0] = abc[0]

1.upto(n-1) { |i|
  tmp = []
  tmp[0] = [dp[i-1][1],dp[i-1][2]].max + abc[i][0]
  tmp[1] = [dp[i-1][0],dp[i-1][2]].max + abc[i][1]
  tmp[2] = [dp[i-1][0],dp[i-1][1]].max + abc[i][2]
  dp << tmp.dup
}

p dp[n-1].max


Measured memory_bytes: 16124
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int N = ReadLineParseInt();
        int[] dp = new int[N + 1];
        for (int i = 1; i <= N; i++)
            dp[i] = i;
        int sixs = 6;
        int nines = 1;
        int v = 6;
        while(v <= N)
        {
            for(int i = v; i <= N; i++)
            {  
                dp[i] = Min(dp[i], dp[i - v] + 1);
            }
            if(sixs * 6 < nines * 9)
            {
                sixs *= 6;
                v = sixs;
            }
            else
            {
                nines *= 9;
                v = nines;
            }
        }
        WriteLine(dp[N]);
    }

    static int ReadLineParseInt() => int.Parse(ReadLine());
}

Measured memory_bytes: 11232
#include<bits/stdc++.h>
using namespace std;
typedef unsigned char uc;
typedef vector<uc> vec;
int main(){
  int m;
  cin>>m;
  int l[m],r[m];
  map<string,int> ms;
  for(int i=0;i<m;i++){
    string s;
    cin>>s>>l[i]>>r[i];
    ms[s]=i;
  }
  int n;
  cin>>n;
  string ss[n];
  for(int i=0;i<n;i++) cin>>ss[i];
  bool f=0;
  stack<vec> sc;
  for(int i=0;!f&&i<n;i++){
    //cout<<i<<":"<<ss[i]<<endl;
    if(ms.find(ss[i])!=ms.end()){ 
      int j=ms[ss[i]];
      vec t;
      for(int k=l[j];k<=r[j];k++) t.push_back((uc)k);
      sc.push(t);
    }else if(isdigit(ss[i][0])){
      uc a=0;
      for(int j=0;j<(int)ss[i].size();j++) a=(uc)(a*10+ss[i][j]-'0');
      sc.push(vec(1,a));
    }else{
      vec t,a,b;
      b=sc.top();sc.pop();
      a=sc.top();sc.pop();
      for(int j=0;!f&&j<(int)b.size();j++){
	for(int k=0;!f&&k<(int)a.size();k++){
	  if(ss[i]=="+") t.push_back(a[k]+b[j]);
	  if(ss[i]=="-") t.push_back(a[k]-b[j]);
	  if(ss[i]=="*") t.push_back(a[k]*b[j]);
	  if(ss[i]=="/"){
	    if(b[j]) t.push_back(a[k]/b[j]);
	    else{
	      f=1;
	      break;
	    }
	  }
	}
      }
      sort(t.begin(),t.end());
      t.erase(unique(t.begin(),t.end()),t.end());
      sc.push(t);
    }
  }
  cout<<(!f?"correct":"error")<<endl;
  return 0;
}

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll inf = 1e15;
const ll mod = 1e9+7;

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

int main() {
    string S;
    int K;
    cin >> K;
    cin >> S;

    if (S.length() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) + "..."  << endl;
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;


int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    vector<int> q(n);
    rep(i, n) cin >> q[i];


    vector<int> nums(n);
    rep(i, n) nums[i] = i + 1;
    
    int cnt = 0;
    int a = -1, b = -1;
    do {
        bool ok = true;
        rep(i, n) if (nums[i] != p[i]) {
            ok = false;
            break;
        } 
        if (ok) a = cnt;

        ok = true;
        rep(i, n) if (nums[i] != q[i]) {
            ok = false;
            break;
        } 
        if (ok) b = cnt;

        if (a >= 0 && b >= 0) {
            put(abs(a - b));
            return 0;
        }
        cnt++;
    } while (next_permutation(nums.begin(), nums.end()));

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 1007, INF = 1e7 + 7;

int n, m, k, f[N][N];

bool clean(int calc[], int mask, int j) {
    loop(i, n)
        calc[i] = 0;
    int cnt = 0, last = 0;
    while (last < n) {
        for (; last < n - 1 && !(mask & (1 << last)); ++last)
            calc[cnt] += f[last][j];
        calc[cnt] += f[last++][j];
        if (calc[cnt] > k) return 0;
        ++cnt;
    }
    return 1;
}

int ask(int mask) {
    int calc[n] = {0}, ans = 0;
    loop(j, m) {
        int last = 0, cnt = 0;
        while (last < n) {
            int cr = 0;
            for (; last < n - 1 && !(mask & (1 << last)); ++last)
                cr += f[last][j];
            cr += f[last++][j];
            if (cr > k) return INF;
            if (cr + calc[cnt] > k) {
                ++ans;
                if (!clean(calc, mask, j))
                    return INF;
                break;
            }
            calc[cnt] += cr;
            ++cnt;
        }
    }
    return ans;
}

void solve() {
    cin >> n >> m >> k;
    loop(i, n)
        loop(j, m) {
            char c; cin >> c;
            f[i][j] = c - '0';
        }
    // loop(i, n) {
    //     loop(j, m)
    //         cout << f[i][j];
    //         cout << '\n';
    // }
    int ans = INF;
    loop(mask, (1 << (n - 1))) {
        int cr = ask(mask);
        loop(i, n)
            cr += bool(mask & (1 << i));
        //cout << mask << " " << cr << "\n";
        ans = min(ans, cr);
    }
    cout << ans;
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
b = []
for i in range(n):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)
    
happya = 0
happyb = 0

def wa(a,b):
    return a+b

c = list(map(wa, a, b))
for i in range(n):
    c[i] = [c[i], i]
c.sort()
c.reverse()

d = []
for i in range(n):
    d.append(c[i][1])

for i in range(n):
    if(i % 2 == 0):
        happya += a[d[i]]
    else:
        happyb += b[d[i]]
        
print(happya-happyb)

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll N,c[10101];
vector<ll> tv[10101];
ll i, j, k;
queue<ll> qq;
ll ans,anss[10101];

int main(){
    scanf("%lld", &N);
    fornum(i,1,N){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        tv[a].push_back(b);
        tv[b].push_back(a);
    }
    fornum(i,0,N){
        scanf("%lld", &c[i]);
        if(tv[i+1].size()>k){
            j = i + 1;
            k = tv[i + 1].size();
        }
    }
    sort(c, c + N,greater<ll>());
    qq.push(j);
    j = 0;
    while(!qq.empty()){
        ll qa = qq.front();
        qq.pop();
        anss[qa] = c[j++];
        fornum(i,0,tv[qa].size()){
            if(anss[tv[qa][i]]==0){
                qq.push(tv[qa][i]);
            }else{
                ans += anss[qa];
            }
        }
    }
    printf("%lld\n", ans);
    fornum(i,0,N){
        printf("%lld ", anss[i + 1]);
    }

    return 0;
}

Measured memory_bytes: 1152
#include<iostream>

using namespace std;

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

	int r,d,x;
	cin >> r >> d >> x;
	for(int i=0; i<10; i++){
		x = r*x - d;
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 3560
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \
 
*/
 
#import<bits/stdc++.h>
typedef long long ll;
#define num 10000000
#define root 10000
#define forll(i,a,b,c) for(int i=a; i<=b; i+=c)
#define forll2(i,a,b,c) for(int i=a; i>=b; i-=c)
#define pb(n) push_back(n)
 
using namespace std;
 
int main()
{
  int n,k;
  cin>>n>>k;
  int x=0;
  while(n--)
  {
    double a,b;
    cin>>a>>b;
    double p=sqrt((a*a)+(b*b));
    if(p<=(double)k){x++;}
  }
  cout<<x<<"\n";
}

Measured memory_bytes: 3816
#include <stdio.h>
int main (void)
{
  int a,b,h,s;
  char str[8];
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d",&a);
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d",&b);
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d",&h);
  s = (a + b) * h / 2;
  printf("%d",s);
  return 0;
}
  

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

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

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

  bool gray = false;
  bool brown = false;
  bool green = false;
  bool light_blue = false;
  bool blue = false;
  bool yellow = false;
  bool orange = false;
  bool red = false;
  int free = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) >= 1 && A.at(i) <= 399)
      gray = true;
    else if (A.at(i) >= 400 && A.at(i) <= 799)
      brown = true;
    else if (A.at(i) >= 800 && A.at(i) <= 1199)
      green = true;
    else if (A.at(i) >= 1200 && A.at(i) <= 1599)
      light_blue = true;
    else if (A.at(i) >= 1600 && A.at(i) <= 1999)
      blue = true;
    else if (A.at(i) >= 2000 && A.at(i) <= 2399)
      yellow = true;
    else if (A.at(i) >= 2400 && A.at(i) <= 2799)
      orange = true;
    else if (A.at(i) >= 2800 && A.at(i) <= 3199)
      red = true;
      else
        free++;
  }

  int tot = gray + brown + green + light_blue + blue + yellow + orange + red;
  cout << max(tot, 1) << ' ' << tot + free << endl;
}

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

int main() {
	int A, B, C, X, i, j, k, solve, ans = 0;
	cin >> A >> B >> C >> X;
	
	for (i = 0; i <= A; ++i) {
		for (j = 0; j <= B; ++j) {
			for (k = 0; k <= C; ++k) {
				solve = 500 * i + 100 * j + 50 * k;
				if (solve == X) ++ans;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int h, w;
    cin >> h >> w;
    auto d = make_vec<ll>(10, 10);
    rep(i, 10) rep(j, 10) {
        ll c;
        cin >> c;
        d[i][j] = c;
    }
    rep(k, 10) rep(i, 10) rep(j, 10) chmin(d[i][j], d[i][k] + d[k][j]);

    ll ans = 0;
    rep(i, h) rep(j, w) {
        ll a;
        cin >> a;
        if (a != -1) ans += d[a][1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256