akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	int h, w;
	cin >> h >> w;
	cout << h / w + (h % w > 0 ? 1 : 0) << endl;
}









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

int main(){
    string str, order, p, tmp;
    int q, a, b;
    cin >> str;
    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> order >> a >> b;
        if(order == "print") {
            //strのaからbまでを出力
            cout << str.substr(a, b-a+1) <<endl;
        }else if(order == "reverse"){
            //strのaからbまでを逆に
            tmp = str.substr(a, b-a+1);
            reverse(tmp.begin(), tmp.end());
            str = str.replace(a, b-a+1, tmp);
        }else{ //order == "replace"
            //strのaからbをpに入れ替える
            cin >> p;
            str = str.replace(a, b-a+1, p);
        }
    }
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main(){
  int H, W;
  string az = "abcdefghijklmnopqrstuvwxyz";
  int cnts[26];
  int life2 = 0;
  int life1 = 0;
  
  string line;
  cin >> H >> W;

  if(H%2==1){
    life2 += W/2;
  }
  if(W%2==1){
    life2 += H/2;
  }

  if(H%2 == 1 && W%2 == 1){
    life1 = 1;
  }
  
  for(int k=0;k<26;++k){
    cnts[k]=0;
  }
  for(int i=0;i<H;++i){
    cin >> line;
    for(int j=0;j<W;++j){
      for(int k=0;k<26;++k){
	if(line[j] == az[k]){
	  cnts[k]++;
	}
      }
    }
  }
  cerr << life1 << ","<< life2<<endl;
  for(int k=0;k<26;++k){
    int check = cnts[k] % 4;
    cerr<<cnts[k]<<","<<check<<endl;
    if(check == 1){
      life1 -= 1;
    }
    if(check == 2){
      life2 -= 1;
    }
    if(check == 3){
      life1 -= 1;
      life2 -= 1;
    }
    if(life1 < 0 || life2 < 0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
import math

N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

sumA = 0
for i in range(N):
  sumA += A[i]

can_be_chosen = 0
for i in range(N):
  if A[i] >= sumA/4.0/M:
    can_be_chosen += 1

if can_be_chosen >= M:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))




n=input1()
fb_list=range(1,n+1)
count=0
for i in fb_list:
	if i%3!=0 and i%5!=0:
		count+=i
print(count)

Measured memory_bytes: 9188
def main():
    #1. input
    a, b = map(int, input().split())

    ans = 0

    #2. from A to B
    for i in range(a, b+1):
        #2.1. judge if the number is palindromic
        if (str(i)[0]==str(i)[4]) and (str(i)[1]==str(i)[3]):
            ans = ans+1

    #3. output
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
n = int(input())
H = list(map(int, input().split()))

ocean = 1
for i in range(1, n):
    count = 0
    for j in range(0, i):
        if H[j] > H[i]:
            count += 1
        if count >= 1:
            break
    if count == 0:
        ocean += 1

if n == 1:
    print(1)
else:
    print(ocean)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int n, ans = 0;
	bool a[30], b[30];
	char s[105];
	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 0; i <= n - 2; i++)
	{
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		for (int j = 0; j <= i; j++)
			a[s[j] - 'a'] = true;
		for (int j = i + 1; j < n; j++)
			b[s[j] - 'a'] = true;
		int sum = 0;
		for (int i = 0; i <= 25; i++)
			if (a[i] && b[i]) sum++;
		ans = max(ans, sum);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef std::vector<ll> vi;
typedef pair < ll , ll > pll;
 
ll MOD = 1e9+7;
 
#define pb push_back
#define mp make_pair
 
ll mx(ll a , ll b){if (a > b) return a;return b;}
ll mx(ll a , ll b , ll c){if (mx(a,c) > b) return mx(a,c);return b;}
ll mn(ll a , ll b){return a + b - mx(a , b);}
ll mod (ll x ){if (x % MOD < 0) return(mod (x + MOD));return x % MOD;}
 
ll n;
ll gcd (ll x , ll y){
	if (y == 0)return x;
	return gcd( y , x%y );
}
 
ll lcm(ll x, ll y, ll z){
 	
 	if (x <= 0 or y <= 0 or z <= 0) return 0 ;

	ll l = x * y / gcd(x , y);
	return l * z / gcd( l , z); 
}
 
bool ip(ll x){
 
	for (ll i = 2; i <= sqrt(x) ; i ++){
		if (x % i == 0 )return false;
	}
	return true;
}
 

ll a , b , c ,k;


int main(){
	
	ios::sync_with_stdio(0);
	cin.tie(0);
 	
 	cin >> a >> b >> c >> k;

 	if (k%2 == 0){

 		cout << a - b;
 	}
 	else cout << b - a; 

	return 0;
 
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

	int n, m;
	int[] a;

	void run() {
		n = sc.nextInt();
		m = sc.nextInt();
		a = new int[m];
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
		}
		solve();
	}

	void solve() {
		int gcd = a[0];
		for (int i = 1; i < m; i++) {
			gcd = gcd(gcd, a[i]);
		}
		println(gcd(gcd, n) == 1 ? "Yes" : "No");
	}

	int gcd(int a, int b) {
		return a == 0 ? b : gcd(b % a, a);
	}

	void println(String s) {
		System.out.println(s);
	}

	void print(String s) {
		System.out.print(s);
	}

	void debug(Object... os) {
		System.err.println(deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#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;

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

  vector<pair<ll, ll>> ans;
  if (N % 2 == 0) {
    REP(i, 1, N + 1) {
      REP(j, i + 1, N + 1) {
        if (i + j != N + 1) {
          ans.push_back(make_pair(i, j));
        }
      }
    }
  } else {
    REP(i, 1, N) {
      REP(j, i + 1, N) {
        if (i + j != N) {
          ans.push_back(make_pair(i, j));
        }
      }
      ans.push_back(make_pair(i, N));
    }
  }

  cout << ans.size() << endl;
  REP(i, 0, ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int a, b;
    std::cin>>a>>b;

    std::string ans = "Impossible";
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
        ans = "Possible";
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.net.SecureCacheResponse;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int ans = 0;
        int countSum = 0;
        for (int i = n; i > 0; i--) {
            int count = 0;
            for (int j = i; j > 0; j--) {
                if (i % j == 0) count++;
            }
            if (count == 8 && i % 2 == 1) {
                countSum++;
            }
        }

        System.out.println(countSum);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;



int main(int argc, char* argv[])
{
    long n,k,x,y;
    scanf("%ld%ld%ld%ld", &n,&k,&x,&y);

    if(n<=k) {
        printf("%ld\n", n*x);
    }
    else {
        printf("%ld\n", n*x+(n-k)*(y-x));
    }

    return 0;
}


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

int main(){
    int m, n;
    cin >> m >> n;

    // 隣接リスト
    vector<int> adj[m+1];

    bool visit[m+1] = {};
    visit[2] = true;
    int indeg[m+1] = {};

    int x, y;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        if(y != 2){
            adj[x].push_back(y);
            indeg[y]++;
        }
    }

    // topological sort
    while(1){
        int next = -1;
        for(int j = 1; j <= m; j++){
            if(!visit[j] && indeg[j] == 0){
                next = j;
                break;
            }
        }

        if(next == -1)  break;
        cout << next << endl;
        
        visit[next] = true;

        for(int x = 0; x < adj[next].size(); x++){
            indeg[adj[next][x]]--;
        }
    }

    cout << 2 << endl;

    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,sum=0;
cin>>n>>m;
vector<int> v(n);
for(int i=0;i<n;i++)
    {
        cin>>v[i];
    sum+=v[i];
    }
sort(v.begin(),v.end());

float k=((float)(sum))/(4*m);
int c=lower_bound(v.begin(),v.end(),k)-v.begin();

if(n-c>=m)
    cout<<"Yes";
else cout<<"No";
}


Measured memory_bytes: 256
int main(){
	int a,b,i,keta;

	while(~scanf("%d%d",&a,&b)){
		i=a+b;
		keta=0;
		for(i;i>=1;){
			i=i/10;
			keta++;
		}
		printf("%d\n",keta);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll MOD2=1e9+9;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n;
ld a,x,y;
vector<ld> v;
stack<ld> stk;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);	
	cin>>n;
	while(n--){
		cin>>a;v.pb(a);
	}
	sort(v.rbegin(),v.rend());
	for(auto i:v)stk.push(i);
	while(SZ(stk)>1){
		x=stk.top();stk.pop();y=stk.top();stk.pop();
		stk.push((x+y)/2);
	}
	cout<<fixed<<setp(12)<<stk.top()<<"\n";
	return 0;
}




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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	int A,B;
	cin>>A>>B;
	if(B%A==0) cout<<A+B<<endl;
	else cout<<B-A<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
/*
Author: CNYALI_LK
LANG: C++
PROG: B.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<int,int> pii;
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
int read(){
	int s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
char WriteIntBuffer[1024];
template<class T>void write(T a,char end){
	int cnt=0,fu=1;
	if(a<0){putchar('-');fu=-1;}
	do{WriteIntBuffer[++cnt]=fu*(a%10)+'0';a/=10;}while(a);
	while(cnt){putchar(WriteIntBuffer[cnt]);--cnt;}
	putchar(end);
}
int a[102424];
int s[1024],t[1024],cnt;
void add(int u,int v){
	s[++cnt]=u;t[cnt]=v;
}
void out(){
	printf("%d\n",cnt);
	for(int i=1;i<=cnt;++i)printf("%d %d\n",s[i],t[i]);
}
int main(){
#ifdef cnyali_lk
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
#endif
	int n,t=1,s=0;
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		if(chkmax(s,abs(a[i])))t=i;
	}
	if(a[t]>0){
		for(int i=1;i<=n;++i)if(a[i]<0)add(t,i);
		for(int i=1;i<n;++i)add(i,i+1);
	}
	else{
		for(int i=1;i<=n;++i)if(a[i]>0)add(t,i);
		for(int i=n;i>1;--i)add(i,i-1);
	}
	out();
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

bool is_heisei(u64 y, u64 m, u64 d) {
  if(y < 2019) {
    return true;
  } else if(y == 2019) {
    if(m < 5) {
      return true;
    } else {
      return false;
    }
  } else {
    return false;
  }
}

int main(int argc, const char* argv[]) {
  string s;
  cin >> s;
  
  u64 y = atoi(s.substr(0, 4).c_str());
  u64 m = atoi(s.substr(5, 2).c_str());
  u64 d = atoi(s.substr(8, 2).c_str());
  
  if(is_heisei(y, m, d)) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}


Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

answer = 0
for i, t in enumerate(T):
    if t == 's':
        if i - K >= 0:
            if T[i-K] != t:
                answer += R
            else:
                T[i]=0
        else:
            answer += R
    elif t == 'p':
        if i - K >= 0:
            if T[i-K] != t:
                answer += S
            else:
                T[i]= 0
        else:
            answer += S
    elif t == 'r':
        if i - K >= 0:
            if T[i-K] != t:
                answer += P
            else:
                T[i]=0
        else:
            answer += P
    
print(answer)

Measured memory_bytes: 4084
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [a];
        for(int i=0;i<a;i++){
                             in[i] = sc.nextInt();
                            }
		Arrays.sort(in);
        int b = in[a-1]-in[0];	
		System.out.println(b);
	}
}


Measured memory_bytes: 23252
a,b=map(int,input().split())
print(100,100)
a-=1
b-=1

for i in range(25):
    for q in range(50):
        if b>0:
            print("#",end="")
            b-=1
        else:
            print(".",end="")
        print(".",end="")
    print()
    print("."*100)
              
for i in range(25):
    print("#"*100)
    for q in range(50):
        if a>0:
            print(".",end="")
            a-=1
        else:
            print("#",end="")
        print("#",end="")
    print()
                  

Measured memory_bytes: 9232
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        k: i32,
        s: i32,
    }
    let mut res = 0;
    for x in 0..(k + 1) {
        for y in 0..(k + 1) {
            let z = s - x - y;
            // println!("x = {:?}, y = {:?}, z = {:?}", x, y, z);
            if 0 <= z && z <= k {
                res += 1;
            }
        }
    }
    println!("{:?}", res);
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	String fileName = "prizes";

	public void solve() throws IOException {
		int n = nextInt();
		int ans[] = new int[n];
		int[][] a = new int[2][n];
		int[][] sum = new int[2][n];
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < n; j++) {
				a[i][j] = nextInt();
				if (j == 0)
					sum[i][j] = a[i][j];
				else
					sum[i][j] = sum[i][j - 1] + a[i][j];
			}
		for (int i = 0; i < n; i++)
			ans[i] = sum[0][i] + sum[1][n - 1] - sum[1][i] + a[1][i];
		int max = ans[0];
		for (int ktr = 0; ktr < ans.length; ktr++) {
			if (ans[ktr] > max) {
				max = ans[ktr];
			}
		}
		out.print(max);

	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out, true);
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	BufferedReader br;
	StringTokenizer in;
	static PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

}

Measured memory_bytes: 21204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int k = Integer.parseInt(str[0]);
		int n = Integer.parseInt(str[1]);

		int a[] = new int[n];

		str = br.readLine().split(" ");

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		int min = k - Math.abs(k - Math.abs(a[0] - a[n - 1]));

		for (int i = 0; i < n - 1; i++) {
			min = Math.min(min, k - Math.abs(a[i] - a[i + 1]));
		}

		System.out.println(min);
	}
}

Measured memory_bytes: 62168
N,M = map(int, input().split())
ab = []
ans = 0

for i in range(N):
    ab.append(list(map(int, input().split())))
ab = sorted(ab)
nokori = M
for i in ab:
    if nokori - i[1] >= 0:
        ans += i[0] * i[1]
        nokori -= i[1]
    else:
        ans += i[0] * nokori
        break

print(ans)

Measured memory_bytes: 28656
#include <stdio.h>
#include <stdlib.h>
int pz[3][3],tmp[3][3];
int dx[4] = {0,1,0,-1},dy[4] = {1,0,-1,0};
void emp(int *x,int *y) {
  int i,j;
  for(i=0; i<3; i++) {
    for(j=0; j<3; j++) {
      if(!pz[i][j]) {
    *x = j;
    *y = i;
      }
    }
  }
}
void swap(int *s,int *v){
  int tmp;
  tmp = *s;
  *s = *v;
  *v = tmp;
}   
int calc(){
  int i,a,sum=0; 
  for(i=0; i<9; i++){
    a = pz[i/3][i%3];
    if(a){
      a--;
      sum += abs(i/3 - a/3) + abs(i%3 - a%3);
    }
  }    
  return sum;
}
int dfs(int x,int y,int p,int d,const int lim){
    int i,h,x2,y2,res;   
    h = calc();
    if(h==0) {
        return d;
    }
    if(d+h>lim) {
        return -1;
    }
    for(i=0; i<4; i++){
        x2 = x+dx[i];
        y2 = y+dy[i];      
        if(~p && i==(p+2)%4) continue;
        if(!(0<=x2 && x2<3 && 0<=y2 && y2<3)) continue;    
        swap(&pz[y][x],&pz[y2][x2]);
        res = dfs(x2,y2,i,d+1,lim);
        if(~res) {
            return res;
        }
        swap(&pz[y][x],&pz[y2][x2]);
    }   
    return -1;
}    
int main() {
    int i,j,l,ans,x,y;
       
    for(i=0; i<3; i++){
        for(j=0; j<3; j++) scanf("%d",&pz[i][j]);
    }
        
    emp(&x,&y);
    for(l=0; l<100; l++){
        for(i=0; i<3; i++){
            for(j=0; j<3; j++) tmp[i][j] = pz[i][j];
        }
           
        ans = dfs(x,y,-1,0,l);
        if(ans!=-1){
            printf("%d\n",ans);
            break;
        }
           
        for(i=0; i<3; i++){
            for(j=0; j<3; j++) pz[i][j] = tmp[i][j];
        }
           
        ans = -1;
        if(l==99) printf("%d\n",ans);
    }
       
    return 0;
}



Measured memory_bytes: 2112
from fractions import gcd


def list_lcm(A):
    """N個の最小公倍数
    Args:
        A (list[int])

    Returns:
        int: 最小公倍数

    Examples:
        >>> list_lcm([12, 34, 54, 65])
        119340
    """
    ans = A[0]
    for i in range(1, len(A)):
        ans = ans * A[i] // gcd(ans, A[i])
    return ans


def resolve():
    A, B, C, D = map(int, input().split())
    A -= 1

    lcm_C_D = list_lcm([C, D])
    ans_B = B - B // C - B // D + B // lcm_C_D
    ans_A = A - A // C - A // D + A // lcm_C_D

    print(ans_B - ans_A)


resolve()

Measured memory_bytes: 5048
import sys

sys.setrecursionlimit(1000000)
S = input()


def start_with(i):
    if i == len(S):
        print('YES')
        sys.exit(0)

    try:
        if S[i:i+5] == 'dream':
            start_with(i+5)
        if S[i:i+7] == 'dreamer':
            start_with(i+7)
        if S[i:i+5] == 'erase':
            start_with(i+5)
        if S[i:i+6] == 'eraser':
            start_with(i+6)
        return
    except IndexError:
        return


start_with(0)
print('NO')


Measured memory_bytes: 19156
#include <cstdio>
#include <vector>

using namespace std;

int m, n;
bool in[20], vis[20];
vector<int> G[20], ord;

void dfs(int v)
{
	vis[v] = true;
	for (int i = 0; i < G[v].size(); i++)
		if (!vis[G[v][i]]) dfs(G[v][i]);
	ord.push_back(v);
}

int main()
{
	int m, n;
	
	scanf("%d %d", &m, &n);
	
	for (int i = 0; i < n; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		G[--x].push_back(--y);
		in[y] = true;
	}
	
	for (int i = 0; i < m; i++)
		if (!in[i]) dfs(i);
		
	for (int i = m - 1; ~i; i--)
		printf("%d\n", ord[i] + 1);
		
	return (0);
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n; 
    string s;
    cin >> n;
    cin >> s;
    
    int ans = 0;
    int x = 0;
    rep(i, n){
        if (s[i] == 'I'){
            x++;
        } else {
            x--;
        }
        ans =max(ans,x);
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    static long ans;
    static int[] k_list;

    public static void main(String[] args) {
        var scaner = new Scanner(System.in);
        var n = scaner.nextInt(); // sunuke
        var k = scaner.nextInt(); // kind

        var set = new HashSet<>();
        
        for(int i = 0; i<k; i++) {
            int d = scaner.nextInt();
            for(int j = 0; j<d; j++) {
                set.add(scaner.nextInt());
            }
        }

        System.out.println(n - set.size());
        scaner.close();
    }

}


Measured memory_bytes: 46688
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n),b(n);
    for(lint i=0;i<n;i++){
        lint x;std::cin>>x;x--;
        a.at(i)=x;
        b.at(x)++;
    }
    lint ans=0;
    for(lint x:b)ans+=x*(x-1)/2;
    for(lint x:a){
        lint y=b.at(x);
        std::cout<<ans-(b.at(x)-1)<<'\n';
    }
}


Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int s[366][26];
int main() {

	int d;
	cin >> d;
	int c[26];
	int i, j, j2;
	for (i = 0; i < 26; i++) {
		cin >> c[i];
	}

	for (i = 0; i < d; i++) {
		for (j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}
	int last[26];
	for (i = 0; i < 26; i++) {
		last[i] = 0;
	}
	int jmax, jindex, jindex2;
	for (i = 1; i <= d; i++) {

		jmax = 0;
		jindex = -1;
		jindex2 = -1;
		/*for (j = 0; j < 26; j++) {
			if (c[j] *(i - last[j]) > jmax) {
				jmax = c[j] *(i - last[j]);
				jindex = j;
			}
			else if (c[j] *(i - last[j]) == jmax) {
				if (s[i - 1][j] > s[i - 1][jindex]) {
					jindex = j;
				}
			}
		}*/
		for (j = 0; j < 26; j++) {
			for (j2 = 0; j2 < 26; j2++) {
				if (j != j2) {
					if (s[i - 1][j] + 5 * c[j] * (i - last[j]) + s[i][j2] + 3 * c[j2] * (i + 1 - last[j2]) > jmax) {
						jmax = s[i - 1][j] + 5 * c[j] * (i - last[j]) + s[i][j2] + 3 * c[j2] * (i + 1 - last[j2]);
						jindex = j;
						jindex2 = j2;
					}
				}
				else {
					if (s[i - 1][j] + 5 * c[j] * (i - last[j]) + s[i][j2] + 3 * c[j2] > jmax) {
						jmax = s[i - 1][j] + 5 * c[j] * (i - last[j]) + s[i][j2] + 3 * c[j2];
						jindex = j;
						jindex2 = j2;
					}
				}
			}
		}
		/*for (j = 0; j < 26; j++) {
			if (s[i - 1][j] + 15 * c[j] * (i - last[j]) >= jmax) {
				jmax = s[i - 1][j] + 15 * c[j] * (i - last[j]);
				jindex = j;
			}
		}*/
		last[jindex] = i;
		cout << jindex + 1 << endl;
		


	}
	return 0;


}

Measured memory_bytes: 3668
#include <stdio.h>
#include <string.h>
#define MAX 1000

void LCSlength(char x[],char y[]){
  int m,n,i,j;

  m = strlen(x);
  n = strlen(y);

  int c[m+1][n+1];
  for(i=0; i<=m; i++){
    c[i][0] = 0;
  }
  for(j=0; j<=n; j++){
    c[0][j] = 0;
  }
  for(i=1; i<=m; i++){
    for(j=1; j<=n; j++){
      if(x[i-1] == y[j-1])c[i][j] = c[i-1][j-1] + 1;
      else if(c[i-1][j] >= c[i][j-1])c[i][j] = c[i-1][j];
      else c[i][j] = c[i][j-1];
    }
  }

  /*for(i = 0; i <= m; i++) {
    for(j = 0; j <= n; j++) {
      printf("%d ", c[i][j]);
    }
    printf("\n");
    }*/
  
  printf("%d\n",c[m][n]);
}

int main(){
  int i,n;
  char x[MAX],y[MAX];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%s",x);
    scanf("%s",y);

    LCSlength(x,y);
  }
  return 0;
}

Measured memory_bytes: 4524
#include <stdio.h>
#include <algorithm>
#include <string.h>

int A[12345];
int B[12345];

int loop(int num){
	int A_num;
	int B_num;
	int ba;
	memset(A, 0, sizeof(A));
	memset(B, 0, sizeof(B));
	A_num = B_num = num;
	ba = 0;
	for (int a = 0; a < num * 2; a++){
		B[a] = a + 1;
	}
	for (int a = 0; a < num; a++){
		scanf("%d", &A[a]);
		B[A[a] - 1] = 0;
	}

	std::sort(A, A + num);
	std::sort(B, B + num * 2);

	for (int a = 0;; a++){
		for (int b = 0; b < num; b++){
			if (ba < A[b]){
				ba = A[b];
				A[b] = 0;
				A_num--;
				break;
			}
			if (b == num - 1) ba = 0;
		}
		if (A_num == 0){
			printf("%d\n0\n", B_num);
			return 0;
		}
		for (int b = num; b < num * 2; b++){
			if (ba < B[b]){
				ba = B[b];
				B[b] = 0;
				B_num--;
				break;
			}
			if (b == num * 2 - 1) ba = 0;
		}
		if (B_num == 0){
			printf("0\n%d\n", A_num);
			return 0;
		}
	}
}

int main() {
	int num;
	while (1){
		scanf("%d", &num);
		if (num == 0)return 0;
		loop(num);
	}
}

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

int main(void) {
    int N, K;
    cin >> N >> K;

    long long max = 0;
    long long min = 0;
    long long cnt = 0;

    for (long long i=K; i<=N+1;i++) {
        max = 0;
        min = 0;
        max = (2*N - i + 1) * i / 2;
        min = (i - 1) * i / 2;
        cnt += (max - min + 1);
        cnt %= (1000000000 + 7);

//        cnt += i * (N+1-i) + 1;a
#if 0
        max = 0;
        min = 0;
        for (int j=0; j<i; j++) {
            min += j;
            max += (N - j);
        }
        cnt += (max - min + 1);
#endif
    }

    cout << cnt << endl;
    return 0;
}



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

using namespace std;

int main() {
	string S;
	cin >> S;
	long long ans = 0;
	int s = 0;
	for (int i = 0; i < (int) S.size(); i++) {
		if (S[i] == 'W')
			ans += s;
		else
			s++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let m: i64 = read();
    let mut ab: Vec<(i64, i64)> = (0..n).map(|_| (read(), read())).collect();

    let mut count = 0;
    let mut ans = 0;
    ab.sort_by_key(|k| k.0);

    for (a, b) in ab {
        if count + b >= m {
            ans += (m - count) * a;
            break;
        }
        count += b;
        ans += a * b;
    }

    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
  using namespace std;
const int N=100000;
const int A[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
int n,f[N+1];
inline void into(){
  scanf("%d",&n);
}
inline void work(){
  memset(f,10,sizeof(f));
  f[0]=0;
  for (int i=1;i<=n;i++)
    for (int j=0;j<12;j++)
      if (i-A[j]>=0) f[i]=min(f[i-A[j]]+1,f[i]);
}
inline void outo(){
  printf("%d\n",f[n]);
}
int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{   
      senky_bansal
      IIIT_ALLAHABAD
      
      ll n;
      cin>>n;
      ll a[n];
      map<ll,ll>mp;
      priority_queue<ll,vector<ll>>pq;
      for(int i=1;i<=n;i++){
      cin>>a[i];
      pq.push(a[i]);
      mp[a[i]]++;}
      for(int i=1;i<=n;i++)
      {
          ll p = pq.top();
          if(p!=a[i])
          cout<<p<<endl;
          else if(p==a[i] && mp[p]>1)
          cout<<p<<endl;
          else if(p==a[i])
          {
              pq.pop();
              ll q = pq.top();
              cout<<q<<endl;
              pq.push(p);
          }
      }
}
















Measured memory_bytes: 12144
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG dpmatome/b.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e15)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int N, K;
    cin >> N >> K;
    int h[N + 1];
    for(int i = 1; i <= N; i++){
        cin >> h[i];
    }

    ll dp[N + 1];
    for(int i = 1; i <= N; i++){
        dp[i] = INF;
    }
    dp[1] = 0;
    for(int i = 2; i <= N; i++){
        for(int j = 1; j <= K; j++){
            if(i - j < 1) break;
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << dp[N] << "\n";
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> X(N);

    int minv = INT32_MAX;
    int maxv = INT32_MIN;

    for (int i = 0 ; i < N; ++i) {
        cin >> X[i];
        if (minv > X[i]) {
            minv = X[i];
        }

        if (maxv < X[i]) {
            maxv = X[i];
        }
    }

    int min_cost = INT32_MAX;

    for (int mp = minv; mp <= maxv; ++mp) {
        int cost = 0;
        for (int xi : X) {
            int d = abs(mp - xi);
            cost += d * d;
        }

        if (cost < min_cost) {
            min_cost = cost;
        }
    }

    cout << min_cost << endl;

    return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        String s2 = sc.nextLine();
        int count = 0;

        for (int i = 0; i < s1.length(); i++) {
            if (s1.charAt(i) != s2.charAt(i)) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 42672
import numpy as np
from collections import defaultdict
 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])
 
for i in range(H):
  for j in range(W):
    if S[i, j] == '.':
      d = defaultdict(int)
      S[i, j] = np.sum(S[max(i-1, 0):i+2, max(j-1, 0):j+2] == '#')
for s in S:
  print(''.join(s))

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

int main(){
	char *hoge = "01235789";
	int kyu;
	int shinketa;
	char shin[10];
	
	while(cin>>kyu,kyu){
		shinketa=0;
		do{
			shin[shinketa]=hoge[kyu % 8];
			shinketa++;
			kyu /= 8;
		}while(kyu);
		while(shinketa--) cout<<shin[shinketa];
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1148
// AOJ 2805: Tournament
// 2017.11.24 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

char a[256];

int calc(int l, int n, int *f)
{
	int c1, c2, f1, f2;
	int m;

	*f = 0;
	if (n == 2) {
		if (a[l] && a[l+1]) { *f = 1; return 0; }
		if (a[l] || a[l+1]) return 0;
		return 1;
	}
	m= n >> 1;
	c1 = calc(l, m, &f1), c2 = calc(l+m, m, &f2);
	if (f1 && f2) { *f = 1; return c1 + c2; }
	if (f1 || f2) return c1 + c2;
	return c1 + c2 + 1;
}

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

	scanf("%d%d", &n, &m);
	if (m == 0) printf("%d\n", n - 1);
	else {
		while (m--) scanf("%d", &k), a[k] = 1;
		printf("%d\n", calc(0, n, &k));
	}
	return 0;
}

Measured memory_bytes: 1848
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cout<<a[i]<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const ll p = 1e9 + 7;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

vector<vector<int>> G;

vector<bool> visited;

vector<int> topsort;

void dfs(int start)
{
    visited[start] = true;
    for (auto s: G[start]) if (!visited[s]) dfs(s);
    topsort.push_back(start);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    
    int n;
    cin>>n;
    vector<double> p(n);
    get(p);
    
    vector<double> dp(n+1);
    dp[0] = 1;
    for (int i = 0; i<n; i++)
    for (int j = n; j>=0; j--)
    {
        dp[j]*=(1-p[i]);
        if (j>0) dp[j]+=dp[j-1]*p[i];
    }
    
    
    double answer = 0;
    for (int i = n/2+1; i<=n; i++) answer+=dp[i];
    cout<<setprecision(10)<<answer;
}

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

using namespace std;

int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> ans;
    for(int i=0;i<n;i++){
        ans.push_back(0);
    }
    for(int i=0;i<q;i++){
        int a;
        cin >> a;
        ans[a-1]+=1;
    }
    for(int i =0;i<n;i++){
        if(q-ans[i]<k){
            cout <<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }

}

Measured memory_bytes: 1144
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
  a = list(map(int, input().split()))
  t = 0
  for d, e in zip(a, b):
    t += d * e
  t += c
  if t > 0:
    ans += 1
print(ans)

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll x;
  cin >> x;
  ll ans = 0;
  ll y = 100;
  while(y < x){
    y += y/100;
    ans++;
  }
  print(ans);
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LL long long int 
const LL MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LL n,i,j,ans=0,k;cin>>n;
      fo(i,1,n+1){
        ans=0;
        fo(j,1,sqrt(2*i)+1){
          fo(k,1,sqrt(2*i-j*j)+1){
            double x1=2*i-j*j-k*k;
            if(x1<0||floor(sqrt(x1))!=sqrt(x1)) continue;
            LL x=(LL)sqrt(x1),r=(j+k+x);
            if((j+k+x)%2==0&&r/2>j&&r/2>k&&r/2>x) ans++;
          }
        }
        cout<<ans<<endl;
      }
    }
    return 0;
}

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

using namespace std;

int main() {
  
  int num=0, kyori=0, max=0;
  
  cin >> num;
  cin >> kyori >> max;
  
  int solve = max/num * num;
  
  if(kyori<=solve) {
    
    cout << "OK" << endl;
    
  } else {
    
    cout << "NG" << endl;
    
  }
  
  return 0;
  
}
    
    

Measured memory_bytes: 3620
import sys
from collections import deque
read = sys.stdin.read

N, M, *AB = map(int, read().split())
graph = [[] for _ in range(N + 1)]

# その頂点の親の数
parents = [0] * (N + 1)
for A, B in zip(*[iter(AB)] * 2):
    graph[A].append(B)
    parents[B] += 1

answer = [0] * (N + 1)
n = parents[1:].index(0) + 1
queue = deque([n])

while queue:
    V = queue.popleft()

    for v in graph[V]:
        # vはVの子
        parents[v] -= 1

        if parents[v] == 0:
            # より根に近い頂点は全て調査済みなので、
            # V = 真の親である可能性のある頂点の中で最も若い親
            # このとき「書き足された各辺u→vは、ある頂点uからその子孫であるような頂点vに向かって伸びています。」を必ず満たせる
            queue.append(v)
            answer[v] = V

print(*answer[1:], sep='\n')

Measured memory_bytes: 27508
import math
from heapq import heappop, heappush
N, D, A = map(int, input().split())
D *= 2
enemies = []
for _ in range(N):
    x, h = map(int, input().split())
    enemies.append((x, math.ceil(h / A)))
enemies.sort()

t = 0
ans = 0
attacks = []
attacksum = 0
for f in range(N):
    x, h = enemies[f]
    while attacks:
        if x > attacks[0][0]:
            ax, ad = heappop(attacks)
            attacksum -= ad
        else:
            break
    if h <= attacksum:
        continue
    damage = h - attacksum
    attacksum += damage
    ans += damage
    heappush(attacks, (x + D, damage))

print(ans)

Measured memory_bytes: 95576
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・順序が固定されるので、区間だったら簡単
・円のときも、地点 0 をそれぞれの方向に通った人数を見れば計算できる
"""

N, L, T = map(int, readline().split())
XW = np.array(read().split(), np.int64)
X = XW[::2]
W = XW[1::2]

speed = np.where(W == 1, 1, -1)

Y = X + speed * T

n = (Y // L - X // L).sum()
n %= N

Y %= L
Y.sort()
Y = np.concatenate((Y[n:], Y[:n]))

print('\n'.join(map(str, Y.tolist())))

Measured memory_bytes: 41876
from heapq import heappush, heappop

R_next = tuple((x, y) for x in range(-3, 0) for y in range(-2, 3) if abs(x) + abs(y) <= 3)
L_next = tuple((x, y) for x in range(1, 4) for y in range(-2, 3) if abs(x) + abs(y) <= 3)
c_num = tuple(str(i) for i in range(10))
L, R = 0, 1
INF = 10 ** 20

def conv(c):
  if c in c_num:
    return int(c)
  if c in ("T", "S"):
    return 0
  return -1

while True:
  w, h = map(int, input().split())
  if w == 0:
    break
  mp = [[-1] * 3 + input().split() + [-1] * 3 for _ in range(h)]
  for i in range(h):
    mp[i] = list(map(conv, mp[i]))
  mp.insert(0, [-1] * (w + 6))
  mp.insert(0, [-1] * (w + 6))
  mp.append([-1] * (w + 6))
  mp.append([-1] * (w + 6))

  def search():
    start = []
    goal = []
    for x in range(3, w + 3):
      if mp[h + 1][x] == 0:
        start.append((x, h + 1))
      if mp[2][x] == 0:
        goal.append((x, 2))

    que = []
    dic = {}
    for x, y, in start:
      heappush(que, (0, x, y, L))
      heappush(que, (0, x, y, R))
      dic[(x, y, L)] = 0
      dic[(x, y, R)] = 0
 
    while que:
      total, x, y, foot = heappop(que)
      if foot == R:
        direct = R_next
        next_foot = L
      else:
        direct = L_next
        next_foot = R

      for dx, dy in direct:
        nx, ny = x + dx, y + dy
        if (nx, ny) in goal:
          return total
        cost = mp[ny][nx]
        if cost == -1:
          continue
        if not (nx, ny, next_foot) in dic or dic[(nx, ny, next_foot)] > total + cost:
          dic[(nx, ny, next_foot)] = total + cost
          heappush(que, (total + cost, nx, ny, next_foot))
    else:
      return -1
  print(search()) 


Measured memory_bytes: 6216
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fr			 first
#define sc			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	int i,k,l;
	string s;
	cin>>k;
	cin>>s;
	l = s.size();
	if(l<=k) cout<<s<<nw;
	else{
		for0(i,k) cout<<s[i];
		cout<<"...\n";
		}
	return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>

#define MAX 100000

struct Node {
  int p,l,r;
};

struct Node T[MAX];

int tree(int);
void child(int);

int main()
{
  int i,j,n,k,id,c,a;

  scanf("%d",&n);

  for(i = 0; i < n ;i++){
    T[i].p = -1;
    T[i].l = -1;
    T[i].r = -1;
  }

  for(i = 0; i < n; i++){ 
    scanf("%d%d",&id,&k);
    for(j = 1; j <= k; j++){
      scanf("%d",&c);
      T[c].p = id;
      if(j == 1) T[id].l = c;
      else T[a].r = c;
      a = c;
    }
  }


  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,tree(i));

    if(T[i].p == -1) printf("root, [");
    else if(T[i].l == -1) printf("leaf, [");
    else printf("internal node, [");

    child(i);
  }
  return 0;
}

int tree(int i){

  int d = 0;

  while(T[i].p != -1){
    i = T[i].p;
    d++;
  }
  return d;
}

void child(int i){

  int a;

  a = T[i].l;

  while(a != -1){
    printf("%d",a);
    a = T[a].r;
    if(a != -1) printf(", ");
  }
  printf("]\n");
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=1005;
char s[N][N];
int n,m,sx,sy,ex,ey;
bool vis[N][N];
int dis[N][N];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
struct node
{
    int x,y,v;
    node(int x=0,int y=0,int v=0):x(x),y(y),v(v){}
    bool operator<(const node&o)const
    {
        return v>o.v;
    }
};
priority_queue<node>q;
int main()
{
    scanf("%d%d%d%d%d%d",&n,&m,&sx,&sy,&ex,&ey);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    memset(dis,inf,sizeof(dis));
    q.push(node(sx,sy,dis[sx][sy]));
    dis[sx][sy]=0;
    while(!q.empty())
    {
        int x=q.top().x,y=q.top().y;q.pop();
        if(vis[x][y]) continue;
        vis[x][y]=true;
        for(int i=0;i<4;i++)
        {
            int xx=dx[i]+x;
            int yy=dy[i]+y;
            if(xx<1||xx>n||yy<1||yy>m||s[xx][yy]=='#') continue;
            if(dis[xx][yy]>dis[x][y])
            {
                dis[xx][yy]=dis[x][y];
                q.push(node(xx,yy,dis[xx][yy]));
            }
        }
        for(int dx=-2;dx<=2;dx++)
            for(int dy=-2;dy<=2;dy++)
        {
            int xx=dx+x;
            int yy=dy+y;
            if(xx<1||xx>n||yy<1||yy>m||s[xx][yy]=='#') continue;
            if(dis[xx][yy]>dis[x][y]+1)
            {
                dis[xx][yy]=dis[x][y]+1;
                q.push(node(xx,yy,dis[xx][yy]));
            }
        }
    }
    if(dis[ex][ey]==inf) dis[ex][ey]=-1;
    printf("%d\n",dis[ex][ey]);
}


Measured memory_bytes: 9704