akhauriyash/Code-Regression huggingface dataset:
import heapq

tmp = list(map(int, (input().split())))
n = tmp[0]
m = tmp[1]

job = [[] for i in range(m+1)]

for i in range(0, n):
  tmp = list(map(int, (input().split())))
  if tmp[0] > m:
    continue
  else:
    job[tmp[0]].append(-tmp[1])

score = 0
tjob = []
for i in range(1, m+1):
  for j in job[i]:
    heapq.heappush(tjob, j)
  if len(tjob) == 0:
    continue
  else:
    score -= heapq.heappop(tjob)

print (score)

Measured memory_bytes: 68312
MOD = pow(10, 9) + 7

def main():
  n, x, y, z = map(int, input().split())
  ngnum = pow(2, z-1) + pow(2, y+z-1) + pow(2, x+y+z-1)
  mask = pow(2, x+y+z) - 1
  dp = [[0 for _ in range(mask + 1)] for _ in range(n + 1)]
  ans = 1
  for _ in range(n):
    ans = ans * 10 % MOD

  dp[0][0] = 1
  for i in range(n):
    for j in range(mask + 1):
      if dp[i][j] == 0:
        continue
      for d in range(1, 11):
        t = j*pow(2, d) | pow(2, d-1)
        if (t & ngnum) == ngnum:
          continue
        t &= mask
        dp[i+1][t] = (dp[i+1][t] + dp[i][j]) % MOD

  for i in range(mask + 1):
    ans = (ans + MOD - dp[n][i]) % MOD

  print(ans)


if __name__ == '__main__':
  main()


Measured memory_bytes: 134656
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  int N, X, T;  
  cin >> N >> X >> T;

  int c = N/X;

  if(N%X == 0)
    cout << T*c << endl;
  else
    cout << T*(c+1) << endl;

  return 0;
}


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

int main()
{
    int n;cin>>n;
    vector<double> a(n);
    for(int i = 0; i<n; i++) cin>>a[i];
    double sum = 0.0;
    for(int i = 0; i<n; i++){
        sum += 1.0 / a[i];
    }
    cout <<fixed <<  setprecision(10)<< 1.0/sum << endl;
    
    return 0;
}



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


	int main() {
		int N;
		cin >> N;
		int A[100];
		for (int i = 0; i < N; i++) {
			cin >> A[i];
		}
		for (int i = 0; i < N - 1; i++) {
			cout << A[i] << ' ';
		}
		cout << A[N - 1] << endl;
		
		for (int i = 1; i <= N - 1; i++) {
			int v = A[i];
			int j = i - 1;
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
				A[j + 1] = v;
			}
			for (int i = 0; i < N - 1; i++) {
				cout << A[i] << ' ';
			}
			cout << A[N - 1] << endl;
		}

		return 0;
	}



Measured memory_bytes: 3084
def cmb(n, r, mod):
    p, q = 1, 1
    for i in range(r):
        p *= n - i
        p %= mod
        q *= i + 1
        q %= mod
    # 1/q!の逆元をかける(= q! ^ (mod-2) % mod)
    return p * pow(q, mod - 2, mod)


N, a, b = map(int, input().split())
MOD = 10**9+7

print((pow(2, N, MOD) - cmb(N, a, MOD)-cmb(N, b, MOD)-1) % MOD)


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

const int INF=1e8;

signed main(){
	int n,m;
    cin>>n>>m;
    vi c(m);
    rep(i,0,m) cin>>c[i];
    int dp[50010]={};
    rep(i,0,50010) dp[i]=INF;
    dp[0]=0;
    rep(i,0,m){
        rep(j,0,50010){
            //if(j-c[i]>=0) dp[j]=min(dp[j],dp[j-c[i]]+1);
            if(j+c[i]<50010) dp[j+c[i]]=min(dp[j+c[i]],dp[j]+1);
        }
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1588
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			long[] a = new long[n+1];
			long sum = 0;
			
			
			for(int i=1;i<=n;i++) {
				a[i] = sc.nextLong();
				sum += a[i];
			}
			
			long x = 0;
			long y = sum;
			long ret = Long.MAX_VALUE;
			
			for(int i=1;i<n;i++) {
				x += a[i];
				y -= a[i];
				ret = Math.min(ret, Math.abs(x-y));
			}
			
			System.out.println(ret);
		}
		
	}
	


Measured memory_bytes: 61204
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  u64 n;
  cin >> n;
  u64 div[n+1];
  for (u64 i = 0; i <= n; ++i) {
    div[i] = 0;
  }
  for (u64 i = 1; i <= n; ++i) {
    u64 tgt = i;
    u64 d = 2;
    while (tgt > 1) {
      if (tgt%d == 0) {div[d]++;tgt/=d;}
      else d++;
    }
  }
  u64 ret = 1;
  for (u64 i = 2; i <= n; ++i) {
    ret = ret * (div[i]+1) % 1000000007;
  }
  cout << ret << endl;
  return 0;
}


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

int main(){
    int x,n;
    cin >> x >> n;
    if(n == 0){
        cout << x << endl;
        return 0;
    }
    vector<int> p(n);
    for(int i=0; i<n; i++){
        cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    int tmp = 0;
    vector<int> pp;
    for(int i=0;i<=102;i++){
        if(tmp < n && p.at(tmp) == i){
            tmp++;
            continue;
        }
        pp.push_back(i);
    }
    int a = x + 1;
    if(abs(x - pp.at(0)) >= a){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0; i<pp.size(); i++){
        int aa = abs(x - pp.at(i));
        if(aa < a){
            a = aa;
            continue;
        }
        if(aa >= a){
            cout << pp.at(i-1) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;
const int MAX = 447;

int main(void){
    
    scanf("%d", &N);
    
    vector<ll> v(MAX);
    iota(v.begin(), v.end(), 1);
    for(int i = 0; i < MAX - 1; ++i) v[i + 1] += v[i];
    //for(int i = 0; i < MAX; ++i) cout << v[i] << " ";
    
    int k = -1, ele = -1;
    for(int i = 0; i < MAX; ++i){
        if(v[i] == N){
            k = i + 1, ele = i;
            break;
        }
    }
    
    if(k == -1){ printf("No\n"); return 0; }
    
    ++k, ++ele;
    vector<vector<int>> s;
    int cnt = 0;
    for(int i = 1; i < k; ++i){
        vector<int> temp(ele, 0);
        for(int j = 1; j < i + 1; ++j){
            ++cnt;
            temp[j - 1] = cnt;;
        }
        s.push_back(temp);
    }
    
    for(int i = 1; i < s.size(); ++i) s[0][i] = s[i][i]; 
    for(int i = 1; i < s.size(); ++i) for(int j = 1; j < s[i].size(); ++j) if(s[i][j] == 0) s[i][j] = s[j][i];
    vector<int> temp;
    for(int i = 0; i < s.size(); ++i) temp.push_back(s[i].front());
    s.push_back(temp);
    
    printf("Yes\n%d\n", k);
    for(int i = 0; i < s.size(); ++i) {
        printf("%d ", (int)s[i].size());
        for(int j = 0; j < s[i].size(); ++j){
            if(j) printf(" ");
            printf("%d", s[i][j]);
        }
        printf("\n");
    }
    
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n, m; cin >> n >> m;
    priority_queue<int> que;
    rep(i, n) {
        int a; cin >> a;
        que.push(a);
    }
    rep(i, m) {
        int a = que.top();
        que.pop();
        a /= 2;
        que.push(a);
    }
    ll ans = 0;
    rep(i, n) {
        ans += que.top();
        que.pop();
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 892
k = int(input())

INF = 10 ** 6

d = [INF for _ in range(k)]

d[1] = 1
temp = [[1,1]]
while 1:
    next = []
    for p, c in temp:
        if c + 1 < d[(p + 1) % k]:
            d[(p + 1) % k] = c + 1
            next.append([(p + 1) % k, c + 1])
        if c < d[(p * 10) % k]:
            d[(p * 10) % k] = c
            next.append([(p * 10) % k, c])
    if len(next) == 0:
        break
    else:
        temp = [] + next

print(d[0])

Measured memory_bytes: 17232
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    float t,a;
    cin>>n>>t>>a;
    float h[n];
    float min=1000000;
    float ans=0;
    for(int i=0;i<n;i++){
      cin>>h[i];
      if(abs(a-(t-h[i]*0.006))<min){
        min=abs(a-(t-h[i]*0.006));
        ans=i+1;
      }

    }
    cout<<ans<<endl;


}



Measured memory_bytes: 256
//author: zekigurbuz (Zeki Gurbuz) 2019
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef queue<int> qi;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, vi> mvi;
typedef map<int, vpii> mvpii;
typedef priority_queue<int> pqi;
typedef set<int> si;

#define int ll
#define double ld
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rsz resize
#define forn(a,b) for(int a=0;a<b;++a)
#define rep(a,b,c) for(int a=b;a<c;++a)
#define all(x) begin(x),end(x)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);

const ld PI=4*atan((ld)1);
const int MOD=1000000007;//998244353
const ll INF=0x3FFFFFFFFFFFFFFFLL;
const int N=200005;

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

template<class T>void ckmin(T&a,T b){a=min(a,b);}
template<class T>void ckmax(T&a,T b){a=max(a,b);}
template<class T>using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

string Eval(bool b){return(b?"Yes":"No");}
string eval(bool b){return(b?"yes":"no");}
string EVAL(bool b){return(b?"YES":"NO");}

void precomp() {
	
}

void solve(int testCaseNumber) {
	int n; cin >> n;
	int ans = INF;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) ckmin(ans, i + n / i - 2);
	}
	cout << ans << endl;
}
signed main(){fastio//freopen("replace.in", "r", stdin);freopen("replace.out", "w", stdout);
	
	precomp();
	int t = 1;
//	cin >> t;
	rep(i, 1, t + 1) solve(i);
	
return 0;}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
typedef long long ll;
#define ff first
#define ss second
#define md 998244353
#define md1 998244353 
#define pb push_back
#define in insert
#define mkp make_pair
#define f(i,yha,wha) for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha) for(ll i=wha;i>=yha;i--)
#define mpll map<ll,ll>
#define len(p) p.size()
#define pll pair<ll,ll>
#define arr_sort_rev(arr,n) sort(arr, arr+n, greater<ll>());
#define vec_sort_rev(v) sort(v.begin(), v.end(), greater<ll>());
#define arr_sort(arr,n) sort(arr,arr+n)
#define vec_sort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define mem(a,t) memset(a,t,sizeof(a))
#define endl "\n"

void flash()
{
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
  cout.tie(NULL);
}

ll pw(ll x,ll y)
{
    if(y==0)
      return 1;
    if(y==1)
      return x;
    ll ans=pw(x,y/2);
    ans=ans*ans;
    if(y%2==1)
        ans=ans*x;
    return ans;
}
 
ll pwm(ll x,ll y)
{
    if(y==0)
      return 1;
    if(y==1)
      return x;
    ll ans=pwm(x,y/2)%md;
    ans=(ans*ans)%md;
    if(y%2==1)
        ans=(ans*x)%md;
    return ans;
}
 
int check(ll n)
{
    if(n<0)
      return 0;
    else
      return 1;
}
 
ll add(ll a,ll b)
{
    return a+b;
}
 
ll max(ll a,ll b)
{
    if(a>b)
      return a;
     else
      return b;
}
 
ll min(ll a,ll b)
{
    if(a>b)
      return b;
     else
      return a;
}

ll minv(ll a, ll m) 
{ 
    ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) 
      return 0; 
    while (a > 1) 
    { 
        ll q = a / m,t = m; 
        m = a % m, a = t,t = y; 
        y = x - q * y; 
        x = t; 
    } 
    if (x < 0) 
       x += m0; 
    return x; 
} 
bool cmp(ll i1,ll i2) 
{ 
   
    // i1<i2 for increasing order
    // i1>i2 for decreasing order
    return (i1 > i2); 
}

void solve()
{
    
    ll n,m;
    cin>>n>>m;
    
    ll tmp=n%m;
    
    cout<<min(tmp,abs(tmp-m))<<endl;
    
    
//    ll a[n+10];
//    ll sm=0;
//    f(i,0,n){
//      cin>>a[i];
//      sm+=a[i];
//    }
//    
//    sort(a,a+n,cmp);
//    int nt=0;
//    for(int i=0;i<m;i++)
//    {
//    	if(sm/(4*m)>a[i])
//    	{
//    		nt=1;
//    		break;
//		}
//	}
//	if(nt==0)
//	  cout<<"Yes"<<"\n";
//    else
//      cout<<"No"<<"\n";
      
    
}

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

Measured memory_bytes: 256
# A
a, b = map(str, input().split())

if a == 'H':
    if b == 'H':
        print('H')
    elif b == 'D':
        print('D')
elif a == 'D':
    if b == 'H':
        print('D')
    elif b == 'D':
        print('H')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <deque>
#include <queue>
using namespace std;
typedef long long int ll;
vector<ll> A, B;
priority_queue<ll> diff;

int N;
ll sum = 0;
ll s = 0;
ll ans = 0;
bool need = false;
void input()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        ll ai;
        cin >> ai;
        A.push_back(ai);
    }
    for (int i = 0; i < N; i++)
    {
        ll bi;
        cin >> bi;
        B.push_back(bi);
    }
    for (int i = 0; i < N; i++)
    {
        if (A[i] - B[i] < 0)
        {
            need = true;
        }
        sum += A[i] - B[i];
        // cout << A[i] - B[i] << endl;
        if (A[i] - B[i] > 0)
        {
            diff.push(A[i] - B[i]);
        }
        else
        {
            s += abs(A[i] - B[i]);
            ans++;
        }
    }
}

void solve()
{
    while (!diff.empty() && s > 0)
    {
        ll front = diff.top();
        // cout << front << endl;

        diff.pop();
        s -= front;
        ans++;
    }
}

int main()
{
    input();

    if (sum < 0)
        cout << -1 << endl;
    else
    {
        if (need)
        {
            solve();
            cout << ans << endl;
        }
        else
            cout << 0 << endl;
    }
}

Measured memory_bytes: 2804
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cin.tie(0);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    vector<char> to(500);
    to['G'] = 'C';
    to['C'] = 'G';
    to['A'] = 'T';
    to['T'] = 'A';
    char c;
    cin >> c;
    cout << to[c] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main(){
  string s;
  map<char, int> mp;
  cin >> s;
  for(auto x : s) mp[x]++;
  bool ok = true;
  for(auto x : s) {
    if(mp[x] != 2) ok = false;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

ll N, T[101], V[101];
double dp[20001][101];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> T[i];
  REP(i, 0, N) cin >> V[i];

  T[N] = 0;
  REP(i, 0, N) T[i + 1] += T[i];
  V[N] = 0;

  REP(i, 0, 20001) REP(j, 0, 101) dp[i][j] = -1e20;
  dp[0][0] = 0;
  ll vi = 0;
  REP(t, 1, T[N] + 1) {
    ll vmax = V[vi], lvmax = V[vi];
    if(t >= T[vi]) {
      vmax = min(V[vi], V[vi + 1]);
      lvmax = V[vi];
      vi++;
    }
    REP(v, 0, vmax + 1) {
      dp[t][v] = max(dp[t][v], dp[t - 1][v] + v);
      if(v <= vmax && v + 1 <= lvmax) dp[t][v] = max(dp[t][v], dp[t - 1][v] + v + 0.25);
      if(v + 1 <= 100) dp[t][v] = max(dp[t][v], dp[t - 1][v + 1] + v + 0.5);
      if(v - 1 >= 0) dp[t][v] = max(dp[t][v], dp[t - 1][v - 1] + v - 0.5);
    }
  }
  printf("%.15lf\n", dp[T[N]][0]);
}


Measured memory_bytes: 16000
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const int MaxN = 1000000;

int n;
char s[MaxN + 2], t[MaxN + 2];

int q_l, q_r;
int q[MaxN + 1];

inline int solve()
{
	if (!strcmp(s + 1, t + 1))
		return 0;

	q_l = 1, q_r = 0;

	int l = 0, last = n + 1;
	int res = 0;
	for (int i = n, j = n; i; --i)
	{
		if (i > 1 && t[i] == t[i - 1])
			continue;

		while (j > i || (j && s[j] != t[i]))
			--j;
		if (j == 0)
			return -1;

		q[++q_r] = j + ++l;
		while (q_l <= q_r && q[q_l] - l >= last)
			++q_l;

		res = max(res, q_r - q_l + 1);

		last = i - 1;
	}

	return res;
}

int main()
{
	scanf("%d", &n);
	scanf("%s%s", s + 1, t + 1);

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 6144
require 'pp'

n = gets.chomp!.to_i
p_n = gets.chomp!.split(" ").map(&:to_i)

diff_count = 0

p_n.each.with_index(1) do |i, n|
    if i != n
        diff_count +=1
    end
end

if diff_count <= 2
    puts "YES"
else
    puts "NO"
end


Measured memory_bytes: 2044
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(H: int):
    return 1 if H == 1 else solve(H//2) * 2 + 1


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    print(f'{solve(H)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75268
import heapq

n, d, a = map(int, input().split())
bom = []

for _ in range(n):
    x, h = map(int, input().split())
    bom.append([x, h])

bom.sort(key=lambda x:x[0])

ans = 0
tot = 0
q = []
for x, h in bom:
    while q:
        if q[0][0] >= x: break
        else:
            _, t = heapq.heappop(q)
            tot -= t
    
    r = max((h-tot-1)//a + 1, 0)
    ans += r
    tot += r * a
    heapq.heappush(q, (x+2*d, r*a))

print(ans)



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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for(int i=0; i<3;++i){
    if(s[i]==t[i]) ans+=1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    print(max(a*b,c*d));

}


Measured memory_bytes: 256
import sys
from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
 
 
def main():
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def mi():    return map(int, input().split())
    def lmi():   return list(map(int, input().split()))
    
 
    class MaxPQueue:
        def __init__(self):
            self.h = []
            self.size = 0
 
        def is_empty(self):
            return self.size == 0
        
        def push(self, delicious_dq):
            self.size += 1
            heappush(self.h, list(map(lambda x: -x, delicious_dq)))
        
        def pop(self):
            self.size -= 1
            tmp = heappop(self.h)
            return list(map(lambda x: -x, tmp)) 
 
 
    n, k = mi()
    L = [lmi() for _ in range(n)]
    L.sort(key=lambda x: x[1], reverse=True)
 
    d = dict()
    for neta, delcious in L:
        if neta in d:
            d[neta].append(delcious)
        else:
            d[neta] = [delcious]
 
    group_num = dict()
    group_size = 0
    ans = 0
    for neta, delcious in L[:k]:
        ans += delcious
        if neta in group_num:
            group_num[neta] += 1
        else:
            group_num[neta] = 1
            group_size += 1
    ans += group_size ** 2
    
    pq_new = MaxPQueue()
    for neta in d.keys():
        if neta not in group_num:
            pq_new.push(d[neta])
    
    # print(L)
    # print(ans)
    # print(group_num)
    prev = ans
    for ind in range(k-1, -1, -1):
        neta, delicious = L[ind]
        if group_num[neta] > 1 and not pq_new.is_empty():
            diff = pq_new.pop()[0] + (2 * group_size + 1) - delicious
            ans = max(ans, prev + diff)
            prev += diff
            group_size += 1
            group_num[neta] -= 1
            # print(f"prev {prev}")            
    print(ans)
 
 
 
if __name__ == "__main__":
    main()

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

int main(){
	
	int k,x;
	cin >> k >> x;
	
	
	for(int i = -1*(k-1); i <= k-1;i++){
      printf("%d%c", x+i, i==k-1? '\n' : ' ');
		//cout << x+i << endl;
	}
	return 0;
}

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

template<class V, int NV> class SegTree {
public:
	vector<V> val;
	static V const def = 0;
	V comp(V l, V r) { return max(l,r); };

	SegTree() { val = vector<V>(NV * 2, def); };
	V getval(int x, int y, int l = 0, int r = NV, int k = 1) {	// [x,y)
		if (r <= x || y <= l) return def;
		if (x <= l && r <= y) return val[k];
		return comp(getval(x, y, l, (l + r) / 2, k * 2), getval(x, y, (l + r) / 2, r, k * 2 + 1));
	}
	void update(int entry, V v) {
		entry += NV;
		val[entry] = v;
		while (entry>1) entry >>= 1, val[entry] = comp(val[entry * 2], val[entry * 2 + 1]);
	}
};

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

	int n; cin >> n;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];


	map<int, int> zaatsu;
	rep(i, 0, n) zaatsu[a[i]] = 0;
	int index = 0;
	for (auto p : zaatsu)
	{
		zaatsu[p.first] = index;
		index++;
	}

	SegTree<int, 1 << 20> st;
	int ans = 0;
	rep(i, 0, n)
	{
		int _max = st.getval(0, zaatsu[a[i]]) + 1;
		ans = max(ans, _max);
		st.update(zaatsu[a[i]], _max);
	}
	cout << ans << endl;
}

Measured memory_bytes: 15968
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_052
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long[] nab = ReadLongs();
            int n = (int)nab[0];
            long[] xs = ReadLongs();
            long res = 0;
            for(int i = 1; i < n; i++)
            {
                long dist = xs[i] - xs[i - 1];
                res += Math.Min(dist * nab[1], nab[2]);
            }
            Console.WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 18912
X = int(input())
flg = False
for A in range(120):
    Ap = A**5
    for B in range(120):
        Bp = B**5
        if Ap-Bp==X:
            print(A,B)
            flg = True
            break
        elif Ap+Bp==X:
            print(A,-B)
            flg = True
            break
    if flg:
        break

Measured memory_bytes: 9164
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

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

int main() {
  int a, b;
  while(scanf("%d %d", &a, &b) != EOF){
    if(a < b) swap(a, b);
    cout <<gcd(a, b) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
/*
        |___________________________Arshit Mangukiya_____________________________|
        |_______________________________DA-IICT__________________________________|
        |_____________________________201801173__________________________________|
*/
        /*______________________WRITE  YOUR  CODE  HERE_________________________*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;            
typedef long double ld;
#define ff first
#define ss second
#define pi acos(-1)
#define mr_ad_0501 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define all(a)      a.begin(),a.end()
#define F(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007
#define MAX 200007
#define LM LLONG_MAX
#define sz size()
#define p(x) 		cout<< x << " ";
#define pe(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
const int N=2e5+5;
    	/*	bool fun(pair<int,int>a , pair<int,int>b)
			{
				if(a.ff == b.ff)	return a.ss < b.ss;
				else			return a.ff > b.ff;
			}*/
 /*void bfs(ll x)
 {
 	queue<ll> q;
	q.push(x);
    while(!q.empty())
    {
        ll k=q.front();
        q.pop();
        for(auto X:v[k])
        {
            if(!vis[X])
            {
            	l[X]=l[k]+1;
                vis[X]=1;
                q.push(X);
            }
        }
    }
 }*/

void solve()
{
	 ll n,m,k;
    cin>>n;
    cin>>m>>k;
    if(n==1)
    {
        cout<<"OK";
        return ;
    }
    if((m/n)!=(k/n) || m%n==0 || k%n==0)
    {
        cout<<"OK";
    }
    else
    {
        cout<<"NG";
    }

}
int32_t main(){
	mr_ad_0501;
	ll t=1;
	//cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include<string>
#define fn(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<n;i++)
#define ll long long
#define wh while
#define pb push_back
#define sc(n) scanf("%lld",&n)
#include <vector>
#define N 100100

using namespace std; 
 ll sumd(ll n)
 {
     ll ans=0;
     while(n>0)
     {
         ans+=n%10;
         n=n/10;
     }
     return ans;
 }
int main() {
	ll n,a,b;sc(n);sc(a);sc(b);
    ll ans=0;
    fn(i,n+1)
    {
        ll x=sumd(i);
        if(x>=a&&x<=b)
            ans+=i;
    }
    cout<<ans<<endl;
        
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split(' '))
    
    # out = min(float('inf'), N)
    prev = N % K
    
    isFinish = False
    
    if prev == 0:
        print(0)
        return
    
    while not isFinish:
        next = abs(prev - K)
        
        if next >= prev:
            isFinish = True
        else:
            prev = next
            
    print(prev)

main()

Measured memory_bytes: 2940
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int tp = 0, hp = 0;
			for (int i = 0; i < n; i++)
			{
				string[] s = Console.ReadLine().Split(' ');
				if (s[0] == s[1])
				{
					tp++;
					hp++;
				}
				else
				{
					int tl = s[0].Length;
					int hl = s[1].Length;
					int min = System.Math.Min(tl, hl);
					int j = 0;
					while (j < min)
					{
						if ((int)s[0][j] > (int)s[1][j])
						{
							tp += 3;
							break;
						}
						if ((int)s[0][j] < (int)s[1][j])
						{
							hp += 3;
							break;
						}
						j++;
					}
					if (j == min && tl > hl) tp += 3;
					if (j == min && tl < hl) hp += 3;
				}
			}
			Console.WriteLine("{0} {1}", tp, hp);
		}
	}
}

Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std ;
int main(){
  	int N ; cin >> N ;
  	int ac = 0, wa = 0, re = 0, tle = 0 ;
  	string temp ;
  	while( N-- ) {
    	cin >> temp ;
      	if( temp == "AC" ) ac++ ;
      else if( temp == "WA" ) wa++ ;
      else if( temp == "TLE" ) tle++ ;
      else if( temp == "RE" ) re++ ;
    }
  	cout << "AC x " << ac << endl ;
  cout << "WA x " << wa << endl ;
  cout << "TLE x " << tle << endl ;
  cout << "RE x " << re << endl ;
	return 0 ;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int p[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
    }
    int now = p[0],count = 1;
    for(i=1;i<n;i++){
        if(now > p[i]){
            now = p[i];
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 896
#![allow(non_snake_case)]
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        h: usize, w: usize,
        s: [Chars; h]
    }
    let vect = vec![(0, 1), (1, 0)];
    let mut pq = BinaryHeap::new();
    if s[0][0] == '.' { pq.push((0, (0, 0)))} else {pq.push((-1, (0, 0)))};
    let mut d = vec![vec![-1; w]; h];
 
    while let Some((dep, (x, y))) = pq.pop() {
        let dep = -dep;

        // if d[y][x] >= 0 { continue; }
 
        // d[y][x] = dep;
 
        for &(dx, dy) in vect.iter() {
            let cx = x as i64 + dx;
            let cy = y as i64 + dy;
            if cx >= 0 && cx < w as i64 && cy >= 0 && cy < h as i64 {
                let (cyu, cxu) = (cy as usize, cx as usize);
                if d[cyu][cxu] < 0 {
                    if s[cyu][cxu] == s[y][x] {
                        d[cyu][cxu] = dep;
                        pq.push((-dep, (cxu, cyu)))
                    } else {
                        d[cyu][cxu] = dep+1;
                        pq.push((-(dep+1), (cxu, cyu)))
                    }
                }
            }
        }
    }
 
    println!("{}", (d[h-1][w-1]+1)/2)
}

Measured memory_bytes: 2276
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll t[20000005];
ll a[10000005];
ll b[10000005];
ll dp[10005][10005];
ll ex = 1000000007;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	ll n;
	cin >> n;
	int flag = 0;
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < n; i++) {
		
		if (i == 0 && (a[i] + b[i]) != t[i]) {
			cout << "No" << endl;
			return 0;
		}
		if(i!=0) {
			ll d = abs(a[i] - a[i - 1]) + abs(b[i] - b[i - 1]);
			if (d > t[i] - t[i - 1] || (d % 2 != (t[i]-t[i-1]) % 2)) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 10496
import java.util.*;

public class Main{
    public static void main(String[] args) {
        int count = 0;
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int x, y;
        for(int i = 0;i<n;i++){
            x = Integer.parseInt(sc.next());
            y = Integer.parseInt(sc.next());
            if(d >= Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))) count++;
        }
        System.out.println(count);
    }
}

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

using namespace std;

const int MOD=1e9+7;
const double PI=3.14159265359;



int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    vector<int> v(3);
    for(int&i:v)cin>>i;
    sort(v.begin(), v.end());
    int k;
    cin>>k;
    
    cout<<v[0]+v[1]+(v[2]<<k);
    
    
    
    return 0;
    
    
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

//#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt(s) cout<<s,exit(0)IFD(,cout<<"\n\nTIME: "<<runtime<<" sec\n\n")
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)
#define loop(n) for0(LOOP_COUNTER,n)
#define runtime (clock()*1.0/CLOCKS_PER_SEC)
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define int ll

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

template
<
    class key,
    class val=null_type, /// null_mapped_type
    class comp=less<key>
>
using ord_set=tree /// find_by_order(), order_of_key()
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

typedef trie
<
    string,
    null_type,
    trie_string_access_traits<>,
    pat_trie_tag,
    trie_prefix_search_node_update
>
pref_trie; /// insert(), prefix_range()

template<class T,class U>
ostream&operator<<(ostream&out,pair<T,U> p)
{
    return out<<"("<<p.x<<","<<p.y<<")";
}

template<class Iter>
struct rng
{
    Iter from,to;
    rng(Iter from,Iter to):from(from),to(to){}
};

template<class Iter>
rng<Iter> range(Iter from,Iter to)
{
    return rng<Iter>(from,to);
}

template<class Iter>
ostream&operator<<(ostream&out,rng<Iter> r)
{
    out<<distance(r.from,r.to)<<":";
    for(Iter i=r.from;i!=r.to;i++)
        out<<" "<<*i;
    return out;
}

ll ppow(ll x,ll y,ll mod)
{
    ll res=1;
    while(y)
    {
        if(y&1)
            res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}

signed main()
{
    IFN
    (
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    )

    int a,b,c;
    cin>>a>>b>>c;
    cout<<max({a,b,c})-min({a,b,c});

    IFD(cout<<"\n\nTIME: "<<runtime<<" sec\n\n";)
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var str = new string(Console.ReadLine().ToArray());
        var uniq_str = new string(str.ToCharArray().Distinct().ToArray());
        var a = str.ToArray();
        if (uniq_str.Length == 2)
        {
            var oneCnt = CountStr(uniq_str[0].ToString(), a);
            var twoCnt = CountStr(uniq_str[0].ToString(), a);
            if (oneCnt == 2 && twoCnt == 2)
            {
                Console.WriteLine("Yes");
            }
        }
        else
        {
            Console.WriteLine("No");
        }

    }
    public static int CountStr(string target, char[] str)
    {
        return str.Count(e => e.ToString() == target);
    }
}


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


int main(){
  int h,w,a,b;
	cin>>h>>w>>a>>b;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if((i<b)^(j<a))
				cout<<1;
			else
				cout<<0;
		}
		cout<<"\n";
	}
  return 0;
}

Measured memory_bytes: 1280
//============================================================================
// Name        : BubbleSort.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

int BubbleSort(vector<int>&);
void writeVector(const vector<int>&);

int BubbleSort(vector<int>& v){
	int flag = 1;
	int n_swp = 0;
	while(flag){
		flag = 0;
		for(int i=v.size()-1; i>=1; i--){
			if(v.at(i-1)>v.at(i)){
				int tmp = v.at(i);
				v.at(i) = v.at(i-1);
				v.at(i-1) = tmp;
				flag = 1;
				n_swp = n_swp + 1;
			}
		}
	}
	return n_swp;
}


void writeVector(const vector<int>& v){
	for(int i=0; i<v.size(); i++){
		if(i==v.size()-1){
			cout << v.at(i);
			break;
		}
		cout << v.at(i) << " ";
	}
	cout << "\n";
}

int main() {
	int n_elem;
	cin >> n_elem;
	vector<int> v;
	int input;
	for(int i=0; i<n_elem; i++){
		cin >> input;
		v.push_back(input);
	}

	int n_swp;
	n_swp = BubbleSort(v);

    writeVector(v);
    cout << n_swp << "\n";


	return 0;
}



Measured memory_bytes: 3136
#include<iostream>
using namespace std;
 
int coinChange(int coin[], int x, int N)
{
    int i,j;
 
    //make a matrix of size (N+1)*x to tabulate the computed values 
    int dp[N+1][x];
 
    //dp[i][j] represents no.of ways in which change of Rs. i can be made with just j type of coins available
 
    int including,excluding;
 
    //initialization
    //since, there is only one way in which change of Rs. 0 can be made ie., not including any coin
    for(j=0;j<x;j++)
    {
        dp[0][j]=1;
    }
 
    //i represents the amount whose change is required
    for(i=1;i<=N;i++)
    {
        //j represents the coin values available
        for(j=0;j<x;j++)
        {
            //if the the value of current coin is less than or equal to total amount whose change is required
            //include this coin
            if(i>=coin[j])
            {
                including=dp[i-coin[j]][j];
            }
 
            else
                including=0;
 
            //excluding will store the number of ways in which the amount can be changed without including the current coin value
            if(j>=1)
                excluding=dp[i][j-1];
 
            else
                excluding=0;
 
            //dp[i][j] will be the sum of no.of ways by including as well as excluding the current coin
            dp[i][j]=including+excluding;
        }
    }
 
    return dp[N][x-1];
}
 
int main()
{
    int i;
    int x;  //number of distinct values of coins
    int N;  //amount whose change is required
 
    //cout<<"Enter the amount whose change is required"<<endl;
    cin>>N;
 x=6;
    int coin[] = { 100,101,102,103,104 ,105}; 
 
   i=coinChange(coin,x,N);
 
    if(i==0) cout<<0;
    else cout<<1;
    return 0;
}

Measured memory_bytes: 2560
n = input()
l = input().split()
m = []
for a in l:
    a = int(a)
    c = 0
    while a % 2 == 0:
        a = a / 2
        c = c + 1
    m.append(c)
d = m[0]
for b in m:
    if b < d:
        d = b
    else:
        pass
print(d)

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n,0);
  long long count=0;
  for(int c=0;c<n;c++){
  for(int i=1;i*i<=n;i++){
    for(int j=1;j*j<=n;j++){
      for(int k=1;k*k<=n;k++){
        long long keisan=i*i+j*j+k*k+i*j+j*k+k*i;
        if(keisan==c+1)a[c]++;
        else if(keisan>c+1)break;
      }
    }
  }
  }
  for(int i=0;i<n;i++){
    cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3620
N, *A = map(int, open(0).read().split())
d = 0
ans = 1
for i in range(N-1):
  if d == 0 and A[i] != A[i+1]:
    d = - 1 + 2 * (A[i] < A[i+1])
  elif d == 1 and A[i] > A[i+1]:
    d = 0
    ans += 1
  elif d == -1 and A[i] < A[i+1]:
    d = 0
    ans += 1
print(ans)

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    string s;
    cin >> s;
    pair<bool,bool> NS = {false,false}, EW = {false,false};
    for(auto i : s){
        switch(i){
            case 'N':
                NS.first = true;
                break;
            case 'S':
                NS.second = true;
                break;
            case 'E':
                EW.first = true;
                break;
            case 'W':
                EW.second = true;
                break;
        }
    }
    string ans = ((NS.first ^ NS.second) || (EW.first ^ EW.second))? "No" : "Yes";
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
  string Taro,Hanako;
  int T=0, H=0,n,m;//T:Taro's score//H:Hanako's score//m:counnt for "mojisuu"
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>Taro>>Hanako;
    if(Taro.length()>=Hanako.length())m=Hanako.length();
    if(Taro.length()<Hanako.length())m=Taro.length();
    for(int v=0;v<m;v++){
      if(Taro[v]<Hanako[v]){
        H+=3;
        break;
      }
      if(Taro[v]>Hanako[v]){
        T+=3;
        break;
      }
      if(v==m-1&&Taro[v]==Hanako[v]&&Taro.length()==Hanako.length()){
        T++;
        H++;
      }
      if(v==m-1&&Taro[v]==Hanako[v]&&Taro.length()>Hanako.length())T+=3;
      if(v==m-1&&Taro[v]==Hanako[v]&&Taro.length()<Hanako.length())H+=3;
    }
  }
  cout<<T<<" "<<H<<endl;
  return 0;
}



Measured memory_bytes: 3180
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int MAX_N = 110;

int N, v[MAX_N][MAX_N], cnt[MAX_N][MAX_N];

void check(int y, int x, int my, int mx, bool type){
  int ry = y, rx = x, _y = y, _x = x;
  while(y < N && x < N){
    if((type && v[y][x] > v[ry][rx]) || (!type && v[y][x] < v[ry][rx])){ ry = y; rx = x; }
    y += my; x += mx;
  }
  while(_y < N && _x < N){
    if(v[_y][_x] == v[ry][rx]) ++cnt[_y][_x];
    _y += my; _x += mx;
  }
}

int main() {
  while(cin >>N && N){
    REP(i, N){
      REP(j, N){ cin >>v[i][j]; cnt[i][j] = 0; }
    }
    REP(i, N) check(i, 0, 0, 1, 0);
    REP(i, N) check(0, i, 1, 0, 1);
    int ans = 0;
    REP(i, N) REP(j, N) if(cnt[i][j] >= 2) ans = v[i][j];
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
N,K = map(int,input().split())
slist = [1 if s == "1" else -1 for s in input()]
last_ch = slist[0]

s_enc_list = []
seq = 0
for s in slist:
  if s == last_ch:
    seq += s
  else:
    s_enc_list.append(seq)
    seq = s
    last_ch = s
s_enc_list.append(seq)
if s_enc_list[0] < 0:
  s_enc_list.insert(0,0)
if s_enc_list[-1] < 0:
  s_enc_list.append(0)
  
k_seq = min(2*K+1,len(s_enc_list))
max_sum = 0
for i in range(k_seq):
  max_sum += abs(s_enc_list[i])
  
sum = max_sum
for i in range(2,len(s_enc_list)-k_seq+1,2):
  sum -= abs(s_enc_list[i-2]) + abs(s_enc_list[i-1])
  sum += abs(s_enc_list[i+k_seq-2]) + abs(s_enc_list[i+k_seq-1])
  if sum > max_sum:
    max_sum = sum
    
print(max_sum)


Measured memory_bytes: 4764
// 5/26
// 2-5-3 最小全域木
// 類題 There is no alternative
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1350&lang=en
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// UnionFind
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

// クラスカル法ではグラフは辺の集合として定義（無向が前提）
struct Edge {
    int u;
    int v;
    int cost;
    Edge(int u, int v, int c) : u(u), v(v), cost(c) { }
    // Edge(int u_, int v_, int c) : u(u_), v(v_), cost(c) { }
    // Edge(int u, int v, int c) {
    //     this->u = u;
    //     this->v = v;
    //     this->cost = c;
    // }
    bool operator<(const Edge& o) const {
        return cost < o.cost;
    }
};
using Graph = vector<Edge>;

int kruskal(int N, Graph& es, Edge pass, vector<Edge>& candidates) {  // ここでconstはだめ。ソートするから。いっぱいエラー出る。http://nocotan.github.io/%E3%82%A2%E3%83%AB%E3%82%B4%E3%83%AA%E3%82%BA%E3%83%A0/2017/01/27/mst-copy.html
    sort(es.begin(), es.end());
    UnionFind uf(N);
    
    int res = 0;
    // int num_e = 0;  // 引かれる辺の数

    // for (auto e : es) {
    rep(i, es.size()) {
        // if (i == pass) continue;
        Edge e = es[i];
        if (e.u == pass.u && e.v == pass.v) continue;

        if (!uf.same(e.u, e.v)) {
            uf.unite(e.u, e.v);
            res += e.cost;
            // num_e++;
            candidates.push_back(e);  // i
        }
    }

    // if (num_e == N - 1) {
    //     return res;
    // } else {
    //     return -1;
    // }
    return res;
}

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

    Graph es;

    rep(i, M) {
        int s, d, c;
        cin >> s >> d >> c;
        s--; d--;
        es.push_back(Edge(s, d, c));
    }

    vector<Edge> candidates;  // 最短経路候補の辺のes通し番号を格納
    int min_cost = kruskal(N, es, Edge(-1, -1, -1), candidates);

    // printf("candidates size is %d\n", candidates.size());

    int ans_num = 0;
    int ans_cost = 0;

    // rep(i, M) {
    //     int cost = kruskal(N, es, i);
    //     // if (cost != min_cost && cost == -1) {
    //     if (cost == -1 || (cost != -1 && cost != min_cost)) {
    //         ans_num++;
    //         ans_cost += es[i].cost;
    //     }
    // }

    rep(i, candidates.size()) {
        // cout << candidates.size() << endl;
        vector<Edge> dummy;
        int cost = kruskal(N, es, candidates[i], dummy);
        // printf("i, candidates[i], cost, min_cost = %d, %d, %d, %d\n", i, candidates[i], cost, min_cost);
        if (cost != min_cost) {
            ans_num++;
            // ans_cost += es[i].cost;
            ans_cost += candidates[i].cost;
        }
    }

    cout << ans_num << " " << ans_cost << endl;
}



Measured memory_bytes: 3800