akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
#ifdef LOCAL
mt19937 rng(unsigned(70));
#else
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif
#define rand rng


int main() {
	// fios;
	int n;
	cin >> n;
	int l = n % 10;
	if(l == 3) puts("bon");
	else if(l <= 1 || l == 6 || l == 8) puts("pon");
	else puts("hon");

}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

int dp[100001];

void solve()
{
	int n,k;
	cin>>n>>k;
	vector<int>h(n);
	rep(i,n){
		cin>>h[i];
	}
	rep(i,n){
		dp[i]=1e9+2;
	}
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	FOR(i,0,n){
		rep(j,k){
			if(i+j+1<n)
			chmin(dp[i+j+1],dp[i]+abs(h[i]-h[i+j+1]));
		}
	}
	cout<<dp[n-1]<<endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  int i,j,n,m,**D;
  char buf1[1001],buf2[1001],*X,*Y;
  
  if (scanf("%s %s",buf1,buf2) < 2) exit(1);
  n = strlen(buf1);
  m = strlen(buf2);
  X = malloc((n+1)*sizeof(char));
  Y = malloc((m+1)*sizeof(char));
  for (i=1;i<n+1;i++) X[i] = buf1[i-1];
  for (j=1;j<m+1;j++) Y[j] = buf2[j-1];
  
  D = malloc((n+1)*sizeof(int*));
  for (i=0;i<n+1;i++) {
    D[i] = malloc((m+1)*sizeof(int));
  }
  for (i=0;i<n+1;i++) {
    for (j=0;j<m+1;j++) {
      D[i][j] = 0;
    }
  }
  
  for (i=1;i<n+1;i++) D[i][0] = i;
  for (j=1;j<m+1;j++) D[0][j] = j;
  
  for (i=1;i<n+1;i++) {
    for (j=1;j<m+1;j++) {
      if (X[i] == Y[j]) D[i][j] = D[i-1][j-1];
      else D[i][j] = D[i-1][j-1] + 1;
      if (D[i][j] > D[i][j-1] + 1) D[i][j] = D[i][j-1] + 1;
      if (D[i][j] > D[i-1][j] + 1) D[i][j] = D[i-1][j] + 1;
    }
  }

  printf("%d\n",D[n][m]);
  
  return 0;
}

Measured memory_bytes: 4496
#include<bits/stdc++.h>
#define ll  long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define f(i,n)   for(int i=0;i<n;i++)

using namespace std;
/************************BELIAL**********DEVIL*********BELIAL***********DEVIL*************************/


int main()
{
  FAST_IO
  int n,k;
  cin>>n>>k;
  int arr[n],dp[n];


  f(i,n)
  {
  	cin>>arr[i];
    dp[i]= INT_MAX;

  }
  dp[0]=0;
 f(i,n)
 {
      
   for(int j=i+1;j<=i+k;j++)
   {
        if(j<n)
      dp[j]= min(dp[j],dp[i]+abs(arr[j]-arr[i])); 

   }


 }
   cout<<dp[n-1];


}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)

int main()
{
	ll n; cin>>n;
	vector<double> x(n,0),y(n,0),ddx(n,0),ddy(n,0);
	vector<double> rx,lx,uy,dy,rly,udx;
	REP(i,n)
	{
		string s; cin>>x[i]>>y[i]>>s;
		if( s[0] == 'R' ) { ddx[i]=1;ddy[i]=0;rx.push_back(x[i]);rly.push_back(y[i]); }
		if( s[0] == 'L' ) { ddx[i]=-1;ddy[i]=0;lx.push_back(x[i]);rly.push_back(y[i]); }
		if( s[0] == 'U' ) { ddx[i]=0;ddy[i]=1;uy.push_back(y[i]);udx.push_back(x[i]); }
		if( s[0] == 'D' ) { ddx[i]=0;ddy[i]=-1;dy.push_back(y[i]);udx.push_back(x[i]); }
	}
	sort( ALL(rx) );
	sort( ALL(lx) );
	sort( ALL(uy) );
	sort( ALL(dy) );
	sort( ALL(rly) );
	sort( ALL(udx) );

	vector<double> tt;
	tt.push_back( 0 );
	if(lx.size()>=1&&rx.size()>=1)
	{
		tt.push_back( ( *lx.rbegin() - *rx.rbegin() ) * 0.5 );
		tt.push_back( ( *lx.begin() - *rx.begin() ) * 0.5 );
	}
	if(uy.size()>=1&&dy.size()>=1)
	{
		tt.push_back( ( *dy.rbegin() - *uy.rbegin() ) * 0.5 );
		tt.push_back( ( *dy.begin() - *uy.begin() ) * 0.5 );
	}
	if(udx.size()>=1&&rx.size()>=1)
	{
		tt.push_back( *udx.rbegin()-*rx.rbegin() );
		tt.push_back( *udx.begin()-*rx.begin() );
	}
	if(udx.size()>=1&&lx.size()>=1)
	{
		tt.push_back( *lx.rbegin()-*udx.rbegin() );
		tt.push_back( *lx.begin()-*udx.begin() );
	}
	if(rly.size()>=1&&uy.size()>=1)
	{
		tt.push_back( *rly.rbegin()-*uy.rbegin() );
		tt.push_back( *rly.begin()-*uy.begin() );
	}
	if(rly.size()>=1&&dy.size()>=1)
	{
		tt.push_back(*dy.rbegin()-*rly.rbegin() );
		tt.push_back(*dy.begin()-*rly.begin() );
	}

	double minn = cINF;
	for( auto& t : tt ) if( t >= 0 )
	{
		double maxW=-cINF,minW=cINF,maxH=-cINF,minH=cINF;
		REP(i,n)
		{
			double xx = x[i]+ddx[i]*t;
			double yy = y[i]+ddy[i]*t;
			maxW = max(maxW,xx);
			minW = min(minW,xx);
			maxH = max(maxH,yy);
			minH = min(minH,yy);
		}
		//cout << (maxW-minW)*(maxH-minH) << endl;
		minn = min( minn, (maxW-minW)*(maxH-minH) );
	}

	cout << fixed << setprecision(16) << minn << endl;

	return 0;
}

Measured memory_bytes: 5360
#arc082c
from collections import Counter

n=int(raw_input())
a=map(int,raw_input().split())
a.insert(0,-float('inf'))
for i in xrange(1,n+1):
 a.append(a[i]-1)
 a.append(a[i]+1)
print Counter(a).most_common(1)[0][1]


Measured memory_bytes: 22716
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll MOD = (ll)pow(10.0, 9.0) + 7;
pint dx[4] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
ll min(ll a, ll b)
{

	return (a < b) ? a : b;
}
ll max(ll a, ll b) { return (a > b) ? a : b; }


template<typename T, T MOD = 1000000007>
struct Mint {
	T v;

	Mint() : v(0) {}
	Mint(signed v) : v(v) {}
	Mint(ll t) { v = t % MOD; if (v < 0) v += MOD; }

	Mint pow(ll k) {
		Mint res(1), tmp(v);

		while (k) {

			if (k & 1) res *= tmp;

			tmp *= tmp;
			k >>= 1;
		}



		return res;
	}

	Mint inv() { return pow(MOD - 2); }

	Mint& operator=(Mint a) { if (a.v >= MOD) a.v %= MOD; v = a.v; return *this; }
	Mint& operator+=(Mint a) { v += a.v; if (v >= MOD) v -= MOD; return *this; }
	Mint& operator-=(Mint a) { v += MOD - a.v; if (v >= MOD) v -= MOD; return *this; }
	Mint& operator*=(Mint a) { v = 1LL * v * a.v % MOD; return *this; }
	Mint& operator/=(Mint a) { return (*this) *= a.inv(); }
	Mint operator+(Mint a) const { return Mint(v) += a; }
	Mint operator-(Mint a) const { return Mint(v) -= a; }
	Mint operator*(Mint a) const { return Mint(v) *= a; }
	Mint operator/(Mint a) const { return Mint(v) /= a; }

	Mint operator-() { return v ? MOD - v : v; }
	bool operator==(const Mint a) const { return v == a.v; }
	bool operator!=(const Mint a) const { return v != a.v; }
	bool operator < (const Mint a) const { return a < a.v; }


};

using M = Mint<ll>;

M Fact[2 * 100005];



ll board[1001][1001];
ll visA[1001 * 1001], visB[1001 * 1001];
vector <ll> A, B;
int main() {
	ll n, m, indx, indy;

	cin >> n >> m;
	A.resize(n);
	B.resize(m);
	rep(i, n) {
		cin >> A[i];
		
			
	}
	rep(i, m) {

		cin >> B[i];
		
	}
	
	
	rep(i, n) {
		if (visA[A[i]] == 1) {
			cout << 0 << endl;
			return 0;
		}

		visA[A[i]] = 1;
		
	}

	rep(i, m) {
		if (visB[B[i]] == 1) {
			cout << 0 << endl;
			return 0;
		}
		visB[B[i]] = 1;

	}

	M ans = 1;
	ll nx = 0, ny = 0;
	for (int i = m * n; i >= 1; i--) {
		
		if (visA[i] == 1 && visB[i] == 1) nx++, ny++;

		else if (visA[i] == 1) ans *= ny, nx++;
		
		else if (visB[i] == 1) ans *= nx, ny++;

		else ans *= max(0, ny * nx - (m * n - i));
	}


	cout << ans.v << endl;

	return 0;
}

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

int main(){
  int n, q;
  cin >> n >> q;
  int a[q], b[q];
  vector<int> f(n);
  f[0] = 1; f[1] = -1;
  int pos = 0;
  rep(i,q) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    if(f[a[i]] == 1) pos = b[i];
    if(f[b[i]] == 1) pos = a[i];
    swap(f[a[i]],f[b[i]]);
    if(pos+1 < n and f[pos+1] == 0) f[pos+1] = -1; 
    if(pos-1 >= 0 and f[pos-1] == 0) f[pos-1] = -1; 
  }
  int ans = 0;
  rep(i,n) if(f[i] != 0) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4544
i=61,c=100,f[204],m,x,s;main(y){for(;s?++f[y*12+x+"=>?2J13IK<@V&"[--s]]:~scanf("%d,%d,%d",&x,&y,&s)?s=s*4+1:++i<180?i%12>1?m=fmax(m,f[i]),f[i]?c--:1:1:!printf("%d\n%d\n",c,m););}

Measured memory_bytes: 0
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        string s = IO.STRING();
        int c = 0;
        char b = s[0];
        for (int i = 1; i < s.Length; i++)
        {
            if (s[i] != b)
            {
                c++;
                b = s[i];
            }
        }
        IO.WRITE(c);
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(object s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}

Measured memory_bytes: 3160
#include <cstdio>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <utility>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))

int N;
int A[100000];

int main(int argc, char* argv[])
{
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &A[i]);
	sort(A, A + N);

	int w = 0, h = 0;
	for(int i = N - 1; i > 0; i--)
	{
		if(A[i] == A[i - 1] && w == 0)
		{
			w = A[i];
			i--;
		}
		else if(A[i] == A[i - 1] && w != 0)
		{
			h = A[i];
			break;
		}
	}
	printf("%lld\n", (ll)w * (ll)h);

	return 0;
}


Measured memory_bytes: 512
card = []
3.times do
  card << gets.split.map(&:to_i)
end

N = gets.to_i
N.times do
  t = gets.to_i
  card.each_with_index do |c, i|
    c.each_with_index do |v, j|
      card[i][j] = 0 if v == t
    end
  end
end

def col_check(card)
  card.any? do |c|
    c.all? do |v|
      v == 0
    end
  end
end

exists = col_check(card)
if exists
  print "Yes"
  exit
end

card = card.transpose
exists = col_check(card)
if exists
  print "Yes"
  exit
end

if card[0][0] == 0 && card[1][1] == 0 && card[2][2] == 0
  print "Yes"
  exit
end

if card[0][2] == 0 && card[1][1] == 0 && card[2][0] == 0
  print "Yes"
  exit
end

print "No"

Measured memory_bytes: 3836
#include <bits/stdc++.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
#define ld long double
 
using namespace std;
 
const int N = 5e5 + 123;
const ll mod = 1e9 + 7;

ll dp[N], res, was[N];
int n, maxw;

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

	cin >> n >> maxw;

	was[0] = 1;
	for(int i = 1;i <= n;i++){
		ll x, y;
		cin >> x >> y;
		for(int j = maxw;j >= x;j--){
			if(!was[j - x])
				continue;
			dp[j] = max(dp[j], dp[j - x] + y);
			was[j] = 1;
			res = max(res, dp[j]);
		}
	}
	cout << res;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <unordered_map> 
#define io ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define int long long
#define sp " "
#define fi freopen("bruh.txt","r",stdin);
#define fo freopen("input.txt", "w", stdout);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),c.end();
#define allr(x) x.rbegin(), x.rend()
#define pii pair< int , int >
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,n,a)for(int i=n;i>=a;i--)
#define mem(ara,a) memset(ara,a,sizeof (ara))
long long inf=2e18;
long long minf=-inf;
using namespace std;

signed main(){
int n , m;
cin>> n>>m;
int ans=0;
while(m--){
    int a;
    cin>> a;
    ans+=a;
}
cout<<(n-ans>=0? n-ans : -1);
}



Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;




int ds[1 << 17];
int dt[1 << 17];
bool used[1 << 17];
vector<int> G[1 << 17];
void solve() {
	int n, s, t; cin >> n >> s >> t; s--; t--;
	rep(i, n - 1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	queue<int> q;
	used[s] = true;
	ds[s] = 0; q.push(s);
	while (!q.empty()) {
		int id = q.front(); q.pop();
		rep(j, G[id].size()) {
			int to = G[id][j];
			if (used[to])continue;
			used[to] = true;
			ds[to] = ds[id] + 1;
			q.push(to);
		}
	}
	fill(used, used + n, false);
	used[t] = true;
	dt[t] = 0; q.push(t);
	while (!q.empty()) {
		int id = q.front(); q.pop();
		rep(j, G[id].size()) {
			int to = G[id][j];
			if (used[to])continue;
			used[to] = true;
			dt[to] = dt[id] + 1;
			q.push(to);
		}
	}
	int ans = 0;
	rep(i, n) {
		if (ds[i] < dt[i])ans = max(ans, dt[i] - 1);
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(4);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 7680
#include <iostream>

using namespace std;

int main()
{

    const int N = 1000001;
    int a[N];

    int n, cnt;
    
    cin >> n;

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

    cnt = 0;
    for (int i = 1; i <= n; i++){
        if ( a[a[i]] == i) {
            cnt++;
        } 
    }

    cout << cnt / 2 << endl;

    return 0;
}

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

int main()
{
  int N, x;
  std::cin >> N >> x;
  std::vector<int> v;
  for (int i=0; i<N; ++i) {
    int a;
    std::cin >> a;
    v.push_back(a);
  }
  
  std::sort(v.begin(), v.end(), std::less<int>());
//  for (int i=0; i<N; ++i) std::cout << " " << v[i]; std::cout << std::endl;
  int sum =0;
  for (int i=0; i<N; ++i) {
	sum += v[i];
    if (sum == x) {
      std::cout << i+1 << std::endl;
      return 0;
    }
    if (sum > x) {
      std::cout << i << std::endl;
      return 0;
    }
  }
  std::cout << N-1 << std::endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int result = 0;
  if (N<=9) result = N;
  else if (N<=99) result = 9;
  else if (N<=999) result = N-90;
  else if (N<=9999) result = 909;
  else if (N<=99999) result = N-9090;
  else result = 90909;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int t, n, s, f;

int main(){
	while (cin >> t&&t){
		int sum = 0;
		cin >> n;
		REP(i, n){
			cin >> s >> f;
			sum += f - s;
		}
		if (t <= sum)cout << "OK" << endl;
		else cout << t - sum << endl;
	}
}

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

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

    double d = log10(N);
    int d_floor = floor(d);
    int c = 0;
    for (int i = 0; i < d_floor; i += 2) {
        c += 9 * pow(10, i);
    }
    if (d_floor % 2 == 0) {
        for (int i = pow(10, d_floor); i <= N; i++) {
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

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

using namespace std;

int main() {
    vector<string> buffer;
    while(true) {
        string str;
        getline(cin, str);
        if(str == "END_OF_TEXT") break;
        buffer.push_back(str);
    }

    int row = 0, col = 0;
    string clipboard;
    while(true) {
        char op;
        cin >> op;
        if(op == '-') break;
        if(op == 'a') {
            col = 0;
        }
        else if(op == 'e') {
            col = buffer[row].size();
        }
        else if(op == 'p') {
            col = 0;
            if(row-1 >= 0) row--;
        }
        else if(op == 'n') {
            col = 0;
            if(row+1 < buffer.size()) row++;
        }
        else if(op == 'f') {
            if(col == buffer[row].size()) {
                if(row+1 < buffer.size()) {
                    row++;
                    col = 0;
                }
            }
            else col++;
        }
        else if(op == 'b') {
            if(col == 0) {
                if(row-1 >= 0) {
                    row--;
                    col = buffer[row].size();
                }
            }
            else col--;
        }
        else if(op == 'd') {
            if(col == buffer[row].size()) {
                if(row+1 < buffer.size()) {
                    buffer[row] += buffer[row+1];
                    for(int i = row+1; i < (int)buffer.size()-1; ++i) buffer[i] = buffer[i+1];
                    buffer.resize((int)buffer.size()-1);
                }
            }
            else buffer[row] = buffer[row].substr(0, col) + buffer[row].substr(col+1);
        }
        else if(op == 'k') {
            if(col == buffer[row].size()) {
                if(row+1 < buffer.size()) {
                    buffer[row] += buffer[row+1];
                    for(int i = row+1; i < (int)buffer.size()-1; ++i) buffer[i] = buffer[i+1];
                    buffer.resize((int)buffer.size()-1);
                    clipboard = "\n";
                }
            }
            else {
                clipboard = buffer[row].substr(col);
                buffer[row] = buffer[row].substr(0, col);
                col = buffer[row].size();
            }
        }
        else if(op == 'y') {
            if(clipboard == "\n") {
                buffer.resize(buffer.size()+1);
                for(int i = (int)buffer.size()-1; i > row+1; --i) 
                    buffer[i] = buffer[i-1];
                buffer[row+1] = buffer[row].substr(col);
                buffer[row] = buffer[row].substr(0, col);
                ++row;
                col = 0;
            }
            else if(clipboard != "") {
                buffer[row] = buffer[row].substr(0, col) + clipboard + buffer[row].substr(col);
                col += clipboard.size();
            }
        }
    }
    for(int i = 0; i < buffer.size(); ++i)
        cout << buffer[i] << endl;
    return 0;
}

Measured memory_bytes: 0
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  set<int> dset;
  vector<int> dv;
  for(int i=0; i<N; ++i){
    int d;
    cin >> d;
    dset.insert(d);
  }

  cout << dset.size() << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
typedef long long          ll;
typedef unsigned long long ull;
using namespace std;

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

int main() {
    Setup();

    string S;
    cin >> S;
    const int len  = S.size();
    int       zero = 0;
    int       one  = 0;
    for (int i = 0; i < len; i++) {
        if (S[i] == '0') {
            zero++;
        } else {
            one++;
        }
    }
    int ans = min(zero, one) * 2;

    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        constexpr int M = 27;

        string s, t;
        cin >> s >> t;

        const int n = s.length(), m = t.length();

        string ss = char('a' + 1) + s + s;
        auto ta = make_v(2 * n + 1, M, -1);
        vector<int> next(M, -1);
        for (int i = 2 * n; i >= 0; i--) {
                rep (j, M) {
                        ta[i][j] = next[j];
                }
                
                rep (j, M) {
                        if (ss[i] - 'a' == j) {
                                next[j] = i;
                        } else {
                                next[j] = ta[i][j];
                        }
                }
        }

        ll i = 0, c = 0;
        rep (j, m) {
                if (ta[i][t[j] - 'a'] == -1) {
                        cout << -1 << endl;
                        return 0;
                } else {
                        if (ta[i][t[j] - 'a'] > n) {
                                i = ta[i][t[j] - 'a'] - n;
                                c++;
                        } else {
                                i = ta[i][t[j] - 'a']; 
                        }
                }
        }

        cout << n * c + i << endl;

        return 0;
}


Measured memory_bytes: 30336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define INF (1LL << 31)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "

int main()
{
    int k; cin >> k;
    string s; cin >> s;
    string dot = "...";
    if (s.size() > k) {
        cout << (s.substr(0, k) + dot) << endl;
    }else{
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let r: i32 = input();
    println!("{}", 3 * r * r);
}


Measured memory_bytes: 4352
package main

import (
	"fmt"
	"strconv"
)

func main() {

	var strN string
	fmt.Scanf("%s", &strN)
	N, _ := strconv.Atoi(strN)

	cnt := 0
	for i := 0; i < N; i++ {
		var D1 string
		var D2 string
		fmt.Scanf("%s %s", &D1, &D2)
		if cnt != 3 {
			if D1 == D2 {
				cnt += 1
			} else {
				cnt = 0
			}
		}
	}

	if 3 <= cnt {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

pair<bool, vector<int64_t>> BellmanFord(int N, int S, vector<pair<int, int>> edges[]){
    vector<int64_t> dist(N, 1e18);
    dist[S] = 0;
    for(int k=0; k<N; k++){
        for(int i=0; i<N; i++) for(auto& e : edges[i]){
            int j = e.first, d = e.second;
            if(dist[j] > dist[i] + d){
                dist[j] = dist[i] + d;
            }
        }
    }
    for(int k=0; k<N; k++){
        for(int i=0; i<N; i++) for(auto& e : edges[i]){
            int j = e.first, d = e.second;
            if(dist[j] > dist[i] + d){
                dist[j] = dist[i] + d;
                if(j == N-1) return {false, {}};
            }
        }
    }
    return {true, dist};
}

int main(){
    int N, M, P;
    cin >> N >> M >> P;
    vector<pair<int, int>> edges[2500];
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        edges[a-1].emplace_back(b-1, P-c);
    }
    auto res = BellmanFord(N, 0, edges);
    if(res.first){
        cout << max(int64_t(0), -res.second[N-1]) << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


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

using namespace std;

int main(void) {
	string s;
	int y, m, d;
	cin >> s;
	y = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
	m = (s[5] - '0') * 10 + (s[6] - '0');
	d = (s[8] - '0') * 10 + (s[9] - '0');
	if (y > 2019)
		printf("TBD\n");
	else if (y == 2019) {
		if (m > 4)
			printf("TBD\n");
		else if (m == 4 && d > 30)
			printf("TBD\n");
		else
			printf("Heisei\n");
	}
	else
		printf("Heisei\n");
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left


def get_primes(n):
    prime = []
    limit = n ** 0.5
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


X = int(input())
primes = get_primes(10 ** 5 + 3)
print(primes[bisect_left(primes, X)])


Measured memory_bytes: 7496
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

ll solve(ll, ll);

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

  for(int i=0; i<q; i++){
    ll a, b; cin >> a >> b;
    cout << solve(a, b) << endl;
  }

  return 0;
}

ll solve(ll a, ll b){
  ll s = a*b;
  ll sq = (ll)sqrt(s);

  ll ans=0;
  if(sq*(sq+1) < a*b){
    ans += sq*2;
  }
  else{
    sq--;
    ans += sq*2;
    if((sq+1)*(sq+1) < a*b && (sq+1)!=min(a, b)) ans++;
  }

  if(sq >= min(a, b)) ans--;

  return ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	map<int,int> mope;
	mope[0] = 3;
	int ans = 1;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		ans *= mope[x];
		ans %= inf;
		mope[x]--;
		mope[x+1]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int N = 2e5+5;
const int M = 1e4;
const int INF = 0x3f3f3f3f;

int main() {
	string s;
	cin >> s;
	if(s == "ABC") cout << "ARC" << "\n";
	else cout << "ABC" << "\n"; 
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    if (n < 0)return 0;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    int n;
    cin >> n;
    vector<int> z(n);
    int r=0;
    for (int i = 0; i < n; i++) {
        cin >> z.at(i);
        r += z.at(i);
    }
    int ans = 1341398;
        int t = 0;
        for (int i = 0; i < n; i++) {
            t += z.at(i);
            ans = min(ans, abs(r - 2 * t));
        }
        cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
int vis[maxn];
int main()
{
	int n , te;
	scanf("%d",&n);
	int ans = 0 ;
	memset(vis,0,sizeof(vis));
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%d",&te);
		if(te > 100000)
		{
			ans++;
			
		}
		else 
		{
			vis[te] ++;
		}
		
	}
	for(int i = 0 ; i <= 100000 ; i++)
	{
		if(vis[i] < i)
		{
			ans+=vis[i];
		}
		else if(vis[i] >i)
		{
			ans=ans+(vis[i] - i) ;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 512
n,m=map(int,input().split())
cnt=[[] for _ in range(n+1)]
for i in range(m):
    p,y=map(int,input().split())
    cnt[p].append((y,i))
buf=[None]*m
for p,l in enumerate(cnt):
    if not l:
        continue
    l.sort()
    for j, (y,i) in enumerate(l):
        buf[i]="{:06d}{:06d}".format(p,j+1)
print("\n".join(buf))

Measured memory_bytes: 38352
#include <iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
typedef long long int ll;
using namespace std;
int main(){
    string s;
    ll b=0,ans=0;
    cin>>s;
    for(int i=s.size()-1;i>-1;i--){
        if(s[i]=='B')ans+=b;
        if(s[i]=='W')b++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<queue>
using namespace std ;
struct ST
{
	int x ;
	int y ;
	int cnt = 0 ;
} ;
bool came[ 1000 ][ 1000 ] = {{ 0 }} ;
char map[ 1000 ][ 1000 ] ;
int main()
{
	ST m ,s ;
	queue< ST > que ;
	int n ;
	int w ,h ;
	int mx[ 4 ] = { 0 ,0 ,1 ,-1 } ;
	int my[ 4 ] = { 1 ,-1 ,0 ,0 } ;
	cin >> h >> w >> n ;
	char c = '0' ;
	bool a = true ;	
	for( int i = 0 ; i < h ; i++ )
	{
		cin >> map[ i ] ;
		if( a )
		{
			for( int j = 0 ; j < w ; j++ && a )
			{
				if( map[ i ][ j ] == 'S' )
				{
					m.x = j ;
					m.y = i ;
					a = false ;
				}
			}
		}
	}
	que.push( m ) ;
	int cnt = 0 ;
	while( n )
	{
		n-- ;
		c++ ;
		while( !que.empty() )
		{
			m = que.front() ;
			que.pop() ;
			if( came[ m.y ][ m.x ] == 1 )continue ;
			came[ m.y ][ m.x ] = 1 ;
			if( map[ m.y ][ m.x ] == c )
			{
				while( ! que.empty() )
				{
					que.pop() ;
				}
				break ;
			}
			for( int i = 0 ; i < 4 ; i++ )
			{
				if( m.x + mx[ i ] > -1 && m.x + mx[ i ] < w && m.y +  my[ i ] > -1 && m.y + my[ i ] < h )
				{
					s = m ;
					s.x += mx[ i ] ;
					s.y += my[ i ] ;
					s.cnt++ ;
					if( map[ s.y ][ s.x ] != 'X' && came[ s.y ][ s.x ] == 0 )
					{
						que.push( s ) ;
					}
				}
			}
		}
		memset( came ,0 ,sizeof( came ) ) ;
		que.push( m ) ;
	}
	cout << m.cnt << endl ;
	return 0 ;
}

Measured memory_bytes: 4988
#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;
main(){
    int N,M;
    cin >> N;
    vector<int> T(N);
    ll sum = 0;
    rep(i,0,N){
        cin >> T[i];
        sum += T[i];
    }
    cin >> M;
    vector<int> P(M),X(M);
    rep(i,0,M){
        cin >> P[i] >> X[i];
        cout << sum - T[ P[i]-1 ] + X[i] << endl;
    }

}

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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

void solve(){
	
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
	int x; cin>>x;
    if (x>=30){
        cout<<"Yes\n";
    }else cout<<"No\n";
	
	return 0;
}
/*
NARCO
*/


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main()
{
  int s=0;
  int h,n;
  cin >> h >> n;
  while (n--)
  {
    int u; cin >> u;
    s+=u;
  }
  if (h<=s) cout << "Yes"; else cout << "No";
  return 0;
}

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

int main(){
  int a,d,n;

  cin >>a>>d>>n;

  while(!(a == 0 and  d == 0 and n == 0)){
    int ans , cnt = 0;

    while ((cnt != n)) {
      int flg = 1;

      for(int i = 2; i <= sqrt(a); i++){
        if(a%i == 0)flg = 0;
      }
      if(a == 1)flg = 0;
      if(flg){
        ans = a;
        cnt++;
      }
      a = a + d;
    }
    cout <<ans<<endl;
    cin >>a>>d>>n;
  }
  return 0;
}



Measured memory_bytes: 3072
#include<string.h>
#include <iostream>
#include<cstdio>
#include <stack>
#include <vector>
using namespace std;
#define INF 0x7ffffff
typedef long long ll;
const int maxn=1e5+10;
int pre[maxn];
int dis[maxn];
int findset(int x)
{
    if(x==pre[x])   return x;
    int root=findset(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];
    return pre[x]=root;
}
bool unionset(int x,int y,int w)
{
    int fx=findset(x),fy=findset(y);
    if(fx==fy)
        return w==dis[y]-dis[x];
    pre[fy]=fx;
    dis[fy]=dis[x]+w-dis[y];
    return true;
}
int n,m;
int main()
{
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
    pre[i]=i;
   bool lose=true;
   for(int i=0;i<m;i++)
   {
       int x,y,w;
   scanf("%d%d%d",&x,&y,&w);
        if(lose)
       lose=unionset(x,y,w);
   }
   if(lose) printf("Yes\n");
   else     printf("No\n");
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
    in >> P.first >> P.second;
    return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P){
    out << "(" << P.first << ", " << P.second << ")";
    return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
    for(auto &x: arr) in >> x;
    return in;
}
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr){
    for(auto &x: arr) out << x << ' '; cout << "\n";
    return out;
}
template<class T>
istream &operator>>(istream &in, deque<T> &arr){
    for(auto &x: arr) in >> x;
    return in;
}
template<class T>
ostream &operator<<(ostream &out, const deque<T> &arr){
    for(auto &x: arr) out << x << ' '; cout << "\n";
    return out;
}
int32_t main(){
	int n;
	cin>> n;
	vector< pair<string ,int> > v(n);
	rep(i,0,n){
		cin>> v[i].first >> v[i].second;
	}	
	string u;
	cin>>u;
	int ans = 0;
	bool jf = false;
	rep(i,0,n){
		if(!jf){
			if(u == v[i].first){
				jf = true;
				
			}
		}
		else ans += v[i].second;
	}
	cout<<ans<<endl;
}

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

int main() {
    ll n, m; cin >> n >> m;
    vector<vector<ll>> a(n, vector<ll>(2));

    rep(i, n) {
        cin >> a[i][0] >> a[i][1];
    }
    sort(a.begin(), a.end());

    ll ans = 0;
    rep(i, n) {
        ans += min(a[i][1], m) * a[i][0];
        //cout << ans << endl;
        m -= min(a[i][1], m);
        //printf("m = %d\n", m);
        if (m <= 0)
            break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
mod = 10 ** 9 + 7
n = int(input())
X = list(map(int, input().split()))

ans = []
now_x = 0
now_num = 0
free = n
for k,x in enumerate(X):
  now_num += 1
  dist = x - now_x
  if (dist-1) // 2 + 1 < now_num:
    ans += [free] * (now_num)
    free -= 1
    now_num = 0
    now_x = x
ans += [free] * now_num
res = 1
for k,v in enumerate(ans[::-1]):
  res *= v-k
  res %= mod
print(res)

Measured memory_bytes: 62880
n = gets.to_i
l = gets.split.map(&:to_i)
count = 0

l.combination(3).to_a.each do |x|
  if x.uniq.count == 3
    a = x[0]
    b = x[1]
    c = x[2]
    if a + b > c && b + c > a && c + a > b
      count += 1
    end
  end
end

puts count


Measured memory_bytes: 29744
N, M = map(int, input().split())
A = set()
B = set()

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        A.add(b)
    elif b == N:
        B.add(a)

if A & B:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 19024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  string s;
  cin >> s;
  int cnt=1;
  char c=s[0];
  rep(i,s.size()) {
    if(s[i]!=c) {
      cnt++;
      c=s[i];
    }
  }
  if(cnt%2 && s[0]=='x') pr("x");
  else pr("o");
  return 0;
}


Measured memory_bytes: 1180
#include <iostream>
#include <cstdio>
#ifndef repeat
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#endif
#ifndef repeat_from
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#endif
#ifndef repeat_one
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#endif
#ifndef repeat_rev
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#endif
#ifndef foreach
#define foreach(it, cont) for (typeof(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
#include <vector>
#include <cmath>
#ifndef repeat
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#endif
#ifndef repeat_from
#define repeat_from(i,m,n) for (int i = (m); i < (n); ++i)
#endif
#ifndef repeat_one
#define repeat_one(i,n) for (int i = 1; i <= (n); ++i)
#endif
#ifndef repeat_rev
#define repeat_rev(i,n) for (int i = (n)-1; 0 <= i; --i)
#endif
#ifndef foreach
#define foreach(it, cont) for (typeof(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
#ifndef LIB_DEBUG_HPP
#define LIB_DEBUG_HPP
#ifdef DEBUG
#include <cassert>
#define debug(a) a
#else
#define debug(a)
#endif
#endif
#include <iostream>

// a11x1 + a12x2 + ... + a1m-1xm-1 = a1m
// a21x1 + a22x2 + ... + a2m-1xm-1 = a2m
//      ...        ...            ...
// an1x1 + an2x2 + ... + anm-1xm-1 = anm
std::vector<double> gaussian_elim(std::vector<std::vector<double> > a) {
    const int n = a.size();
#ifdef DEBUG
    assert (0 < n);
#endif
    const int m = a[0].size();
#ifdef DEBUG
    repeat (i, n) assert ((int)a[i].size() == m);
    assert (n == m-1);
#endif
    // make an upper diagonal matrix
    repeat (i, n) {
        {
            int pivot = -1;
            repeat_from (j, i, n) {
                const double eps = 1e-16;
                if (eps < std::abs(a[j][i])) { pivot = j; break; }
            }
#ifdef DEBUG
            assert (pivot != -1);
#endif
            if (pivot != i) std::swap(a[i], a[pivot]);
        }
        repeat_from (j, i+1, m) a[i][j] /= a[i][i];
        a[i][i] = 1;
        repeat_from (j, i+1, n) {
            repeat_from (k, i+1, m) {
                a[j][k] -= a[j][i] * a[i][k];
            }
            a[j][i] = 0;
        }
    }
    // gather the solutions
    std::vector<double> result(n);
    repeat_rev (i, n) {
        result[i] = a[i][m-1];
        repeat_from (j, i+1, n) {
            result[i] -= a[i][j] * result[j];
        }
    }
    return result;
}
using namespace std;
int main() {
    // ax + by = c
    // dx + ey = f
    vector<vector<double> > v(2, vector<double>(3));
    vector<double> w;
    while (true) {
        repeat (i,2) repeat (j,3) cin >> v[i][j];
        if (cin.fail()) break;
        w = gaussian_elim(v);
        printf("%.3lf %.3lf\n", w[0], w[1]);
    }
    return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define MAX (ll)(3e3 + 7)
#define INF (ll)(5e5 + 7)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;

ll dp[MAX][MAX][4], ar[MAX][MAX];
pair<ll, ll> cr[2] = {{1, 0}, {0, 1}};
ll n, m, k;

bool ch (ll x, ll y) {
	return x >= 1 && y >= 1 && x <= n && y <= m;
}

int main () {
	cin >> n >> m >> k;
	for (ll i = 0; i < k; i++) {
		ll x, y;
		cin >> x >> y;
		cin >> ar[x][y];
	}
	for (ll i = 0; i <= n; i++) {
		for (ll j = 0; j <= m; j++) {
			for (ll k = 0; k < 4; k++) {
				ll vv = dp[i][j][k];
				dp[i + 1][j][1] = max (vv + ar[i + 1][j], dp[i + 1][j][1]);
				dp[i][j + 1][k] = max (vv, dp[i][j + 1][k]);
				if (k < 3) {
					dp[i][j + 1][k + 1] = max (dp[i][j + 1][k + 1], vv + ar[i][j + 1]);
				}
			}
		}
	}
	ll ma = 0;
	for (ll i = 0; i < 4; i++) {
		ma = max (dp[n][m][i], ma);
	}
	cout << ma << "\n";
}
			


Measured memory_bytes: 356092
#include <cstdio>

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

int main()
{
  int n;
  int p[20];
  scanf("%d %d %d", &n, p, p + 1);
  int ans = 0;
  for (int i = 2; i < n; ++i)
  {
    scanf("%d", p + i);
    if (max(p[i - 2], max(p[i - 1], p[i])) != p[i - 1] && min(p[i - 2], min(p[i - 1], p[i])) != p[i - 1])
    {
      ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
N, Y = list(map(int, input().split()))

a = -1
b = -1
c = -1
for i in range(N+1):
    for j in range(N+1):
        k = N - i - j
        if k < 0:
            continue
        
        total = i*10000 + j*5000 + k*1000
        if total == Y:
            a = i
            b = j
            c = k

print(str(a) + ' ' + str(b) + ' '  + str(c))

Measured memory_bytes: 3064
import math
k = int(input())
s = 0
box = [0]*(k+1)
for l in range (1,k+1):
     for m in range (1, k+1):
          box[math.gcd(l,m)] += 1
for l in range (1,k+1):
     for n in range (1, k+1):
          s += math.gcd(l,n)*box[l]
print(s)




Measured memory_bytes: 9188
h,w = map(int,input().split())
sharp = ["0"]*(w+2)
for i in range(w+2):
  sharp[i] = "#"

print("".join(sharp))
for j in range(h):
  a = list(input())
  a.append("#")
  a.insert(0,"#")
  print("".join(a))
print("".join(sharp))

Measured memory_bytes: 63384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

struct edge_t {
    int from;
    int to;
};
struct node_t {
    int parent;
    int depth;
    node_t():parent(-2),depth(-1){
    }
};

node_t parentFind(
    int i,
    int n,
    vector<vector<edge_t> > &abs,
    vector<node_t> &node
    ){
  if (node[i].parent!=-2) {
      return node[i];
  }
  if (abs[i].size()==0){
      node[i].parent = -1;
      node[i].depth = 0;
      return node[i];
  }
  vector<edge_t> &es(abs[i]);
  int m = es.size();
  for (int j=0;j<m;j++) {
    node_t p = parentFind(es[j].from,n,abs,node);
    if (node[i].depth < p.depth + 1) {
        node[i].depth = p.depth + 1;
        node[i].parent = es[j].from;
    }
  }
  return node[i];
}

int main() {
  int n, m, t;

  while (cin>>n>>m) {
    t = n - 1 + m;
    vector<vector<edge_t> > abs(n);
    vector<node_t> node(n);
    edge_t e;
    for (int i=0;i<t;i++) {
      cin >> e.from >> e.to;
      e.from--;
      e.to--;
      abs[e.to].push_back(e);
    }
    for (int i=0;i<n;i++) {
      cout << parentFind(i,n,abs,node).parent+1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
int main(){
    int n,k=0,A[1000][1000];
    cin>>n;
    rep(i,1000) if(i*(i-1)==2*n) k=i;
    if(!k){cout<<"No";return 0;}
    int z=1;
    rep(i,k){
        rep(j,i) A[i][j]=A[j][i-1];
        for(int j=i;j<k-1;j++) A[i][j]=z,z++;
    }
    cout<<"Yes"<<endl;
    cout<<k<<endl;
    rep(i,k){
        cout<<k-1<<" ";
        rep(j,k-1) cout<<A[i][j]<<" ";
        cout<<endl;
    }
}

Measured memory_bytes: 3968