akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#define pb emplace_back
#define LOCAL
  
using namespace std;
  
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5+5;
typedef long long ll;
typedef pair<int,int> Pii;
 
template <typename T>inline void read(T& t){
    char c=getchar();t=0;
    int f=1;
    while(!isdigit(c)){
       if(c=='-')f=-1;
        c=getchar();
    }
    while(isdigit(c))t=t*10+c-48,c=getchar();
    t=f*t;
}
  
template <typename T,typename... Args> inline void read(T& t,Args&... args){
    read(t);read(args...);
}

char maze[1005][1005];
int vis[1005][1005];
int c1,c2,d1,d2;
queue<Pii> q[2];//q[0]代表第一种方式,q[2]代表第二种方式
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
 
int main(){
    int t=1;
    // read(t);
    while(t--){
        int h,w;
        read(h,w);
        read(c1,c2,d1,d2);
        for(int i=0;i<=h+1;i++){
            for(int j=0;j<=w+1;j++){
                maze[i][j]='#';
            }
        }
        for(int i=1;i<=h;i++){
            scanf("%s",maze[i]+1);
        }
        bool flag=true;
        vis[c1][c2]=1;
        int x=0,ans=0;//ans代表第二种次数
        q[x].push(Pii(c1,c2));
        while(1){
            while(!q[x].empty()){
                Pii now=q[x].front();
                q[x^1].push(now);
                q[x].pop();
                for(int i=0;i<4;i++){
                    int tx=now.first+dx[i];
                    int ty=now.second+dy[i];
                    if(!vis[tx][ty]&&maze[tx][ty]=='.'){
                        q[x].push(Pii(tx,ty));
                        q[x^1].push(Pii(tx,ty));
                        vis[tx][ty]=1;
                    }
                }
            }
            if(vis[d1][d2]){
                break;
            }
            x^=1;
            ans++;
            while(q[x].size()){
                Pii now=q[x].front();
                q[x].pop();
                for(int i=-2;i<=2;i++){
                    for(int j=-2;j<=2;j++){
                        int tx=now.first+i;
                        int ty=now.second+j;
                        if(tx<0||tx>h)continue;
                        if(ty<0||ty>w)continue;
                        if(!vis[tx][ty]&&maze[tx][ty]=='.'){
                            q[x^1].push(Pii(tx,ty));
                            vis[tx][ty]=1;
                        }
                    }
                }
            }
            if(vis[d1][d2]){
                break;
            }
            x^=1;
            if(q[x].empty()){
                flag=false;
                break;
            }
        }
        if(!flag){
            puts("-1");
            break;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 8868
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}

namespace SOLVE {
    void main(){
    }
}
void calcNext(const string& s,int nxt[]){
    int p = nxt[0] = -1;
    REP(i,1,sz(s)){
        while(p!=-1 && s[p+1]!=s[i])p = nxt[p];
        p+=s[p+1]==s[i];
        nxt[i] = p;
    }
}


int main(){
    int n;in(n);
    VLL v(2*n);
    REP(i,0,2*n)cin>>v[i];
    sort(all(v));
    ll ans = 0;
    REP(i,0,n)ans+=v[i*2];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] l = new int[N];
        int[] r = new int[N];
        int sit = 0;
        
        for(int i = 0; i < N; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        
        for(int i = 0; i < N; i++){
            sit = sit + (r[i] - l[i] + 1);
        }
 
        System.out.println(sit);
        
    }
}

Measured memory_bytes: 23792
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    vector<ll>a(n);
    ll ma=0;
    ll idx=0;
    rep(i,n){
        cin>>a[i];
        if(abs(a[i])>=ma){
            ma=abs(a[i]);
            idx=i;
        }
    }
    vector<pll>p(0);
    if(a[idx]<0){
        while(a[n-1]>a[idx]){
            a[n-1]+=a[idx];
            p.pb(mp(idx,n-1));
        }
        for(int i=n-1;i>0;i--){
            while(a[i-1]>a[i]){
                a[i-1]+=a[i];
                p.pb(mp(i,i-1));
            }
        }
    }else{
        while(a[0]<a[idx]){
            a[0]+=a[idx];
            p.pb(mp(idx,0LL));
        }
        rep(i,n-1){
            while(a[i]>a[i+1]){
                a[i+1]+=a[i];
                p.pb(mp(i,i+1));
            }
        }
    }
    cout<<p.size()<<endl;
    rep(i,p.size()){
        cout<<p[i].first+1<<' '<<p[i].second+1<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll ans=0;
ll x,y;
int main()
{
    cin>>n;
    for(ll i=1;i<=n;i++)  ans+=i*(n-i+1);
    for(int i=1;i<n;i++)
    {
       scanf("%lld%lld",&x,&y);
	   if(x>y)  swap(x,y);
	   ans-=x*(n-y+1);  	
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int h, w, n;
	cin >> h >> w >> n;

	string s[h];
	for ( int i = 0; i < h; i++ ) cin >> s[i];

	bool flag = false;
	for ( int i = 0; i < h; i++ ) {
		for ( int j = 0; j < w-1; j++ ) {
			if ( s[i][j] == s[i][j+1] ) continue;

			string t[h];
			for ( int k = 0; k < h; k++ ) t[k] = s[k];
			swap(t[i][j], t[i][j+1]);			
			
			bool aaa = true;
			while ( aaa ) {
				aaa = false;
				for ( int y = h-2; y >= 0; y-- ) {
					for ( int x = 0; x < w; x++ ) {
						if ( t[y+1][x] == '.' && t[y][x] != '.' ) {
							swap(t[y+1][x], t[y][x]);
							aaa = true;
						}
					}
				}				
			}
			
			bool ch = true;
			
			while ( ch ) {
				bool used[h][w];
				memset(used, 0, sizeof(used));
				ch = false;
				for ( int y = 0; y < h; y++ ) {
					for ( int x = 0; x < w; x++ ) {
						bool ch2 = true;
						if ( y+n-1 < h ) {
							for ( int k = 1; k < n; k++ ) {
								if ( t[y][x] != t[y+k][x] || t[y+k][x] == '.' ) {
									ch2 = false;
									break;
								}
							}
							if ( ch2 ) {
								// if ( i == 3 && j == 2 ) cout << y << " " << x << endl;
								ch = true;
								for ( int k = 0; k < n; k++ ) {
									used[y+k][x] = true;
								}
							}
						}
						if ( x+n-1 < w ) {
							ch2 = true;
							for ( int k = 1; k < n; k++ ) {
								if ( t[y][x] != t[y][x+k] || t[y][x+k] == '.' ) {
									ch2 = false;
									break;
								}
							}
							if ( ch2 ) {
								// if ( i == 3 && j == 2 ) cout << y << " " << x << endl;
								ch = true;
								for ( int k = 0; k < n; k++ ) {
									used[y][x+k] = true;
								}
							}
						}
					}
				}

				for ( int y = 0; y < h; y++ ) {
					for ( int x = 0; x < w; x++ ) {
						if ( used[y][x] ) t[y][x] = '.';
					}
				}

				bool aaa = true;
				while ( aaa ) {
					aaa = false;
					for ( int y = h-2; y >= 0; y-- ) {
						for ( int x = 0; x < w; x++ ) {
							if ( t[y+1][x] == '.' && t[y][x] != '.' ) {
								swap(t[y+1][x], t[y][x]);
								aaa = true;
							}
						}
					}				
				}
			}
			
			bool flag2 = true;
			for ( int y = 0; y < h; y++ ) {
				for ( int x = 0; x < w; x++ ) {
					if ( t[y][x] != '.' ) {
						flag2 = false;
						break;
					}
				}
			}

			if ( flag2 ) {
				flag = true;
				break;
			}			
		}
	}

	if ( flag ) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


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

// 小数点以下桁数
// fixed << setprecision(i)

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

int main()
{
  int n, ans = 0;
  vector<int> b(100);

  cin >> n;
  for (int i = 0; i < n - 1; i++)
    cin >> b[i];
  for (int i = 0; i < n - 1; i++)
  {
    if (i == 0)
      ans += b[0];
    else
      ans += min(b[i - 1], b[i]);
  }
  ans += b[n - 2];
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll a,b,c;
	cin >> a >> b >> c;
	ld r = (ld)c-a-b;
	ld l = sqrtl(a*b) * 2.0;
	cout << (l<r ? "Yes" : "No") << '\n';
	return 0;
}



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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

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

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

int main(){
	int a=read();
	int b=read();
	int k=0;
	if(b+1<0)
		k-=-(b+1);
	if(a<0)
		k+=-a;
	if(a<=0&&0<=b)
		printf("Zero\n");
	else if(k&1)
		printf("Negative\n");
	else
		printf("Positive\n");
}


Measured memory_bytes: 256
class Dictionary:
    def __init__(self):
        self.data = {}
        
    def insert(self, value:str):
        self.data[value] = True

    def find(self, value:str):
        if value in self.data:
            return 'yes'
        return 'no'

if __name__ == '__main__':
    my_dict = Dictionary()
    n = int(input())
    for _ in range(n):
        comm = list(map(str, input().rstrip().split()))
        if comm[0] == 'insert':
            my_dict.insert(comm[1])
        elif comm[0] == 'find':
            print(my_dict.find(comm[1]))


Measured memory_bytes: 33116
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
int len;
int main()
{
	string s,x;
	cin>>s;
	len=s.length();
	x=s;
	for(int i=0;i<len;i++)
		x[i]=s[len-i-1];
	for(int i=0;i<len;i++)
	{
		if(x[i]=='b')
		{
			x[i]='d';
			continue;
		}
		if(x[i]=='d')
		{
			x[i]='b';
			continue;
		}
		if(x[i]=='p')
		{
			x[i]='q';
			continue;
		}
		if(x[i]=='q')
		{
			x[i]='p';
			continue;
		}
	}
	bool flag=true;
	for(int i=0;i<len;i++)
		if(x[i]!=s[i])
			flag=false;
	if(flag==true)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

using namespace std;

int y , m , d,n;
void solve(){
  bool birthDay = false;
  int ans = 0;
  int maxDay;
  for(int year = 1; year < 1000 ; year++){
    for(int month = 1 ; month <= 10 ; month++){
      if(year % 3 == 0) maxDay = 20;
      else if(month % 2 == 0) maxDay = 19;
      else maxDay = 20;
      for(int day = 1; day <= maxDay; day++){
        if(year == y && month == m && day == d){
          birthDay = true;
        }
        if(birthDay) ans++;
      }
    }
  }
  cout << ans << endl;
}

int main(){
  cin >> n;
  for(int input = 0; input < n; input++){
    cin >> y >> m >> d;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3068
//=================================
// Created on: 2018/07/07 21:03:01
//=================================
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
mt19937 mt{random_device{}()};
int main()
{
    string S;
    int W;
    cin >> S >> W;
    for (int i = 0; i < S.size(); i += W) { cout << S[i]; }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<numeric>
//#include <bits/stdc++.h>
#include<cstring>
#include<iostream>
#include<functional>
using namespace std;

int main() {
	int A, B;
	string S;
	cin >> A >> B >> S ;
	if (S[A] != '-') {
		cout << "No" << endl;
		//cin >> A;
		return 0;
	}
	else {
		S[A] = '0';
		for (int i = 0; i < S.size(); i++) {
			if (S[i] < '0' || S[i] > '9') {
				cout << "No" << endl;
				//cin >> A;
				return 0;
			}
		}
		cout << "Yes" << endl;
		//cin >> A;
		return 0;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner stdin = new Scanner(System.in);

        int N = stdin.nextInt();
        int flag = 0;
        
	        for(int i=1;i<10;i++) {
	        	for(int j=1;j<10;j++) {
	        		if(i*j == N) {
	        			flag = 1;
	        			break;
	        		}
	        	}
	        	if(flag == 1) break;
	        }
	    if(flag == 1) {
	    	System.out.println("Yes");
	    }
        else {
        	System.out.println("No");
        }
	}
}


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


int main() {
	int X;
	cin >> X;
	double ans = 1;
	for(int b = 2; b <= X; b++){
		for(int p = 2; ; p++){
			if(pow(b, p) > X){
				break;
			}
			ans = max(ans, pow(b, p));
		}
	}
	cout << ans << endl;
	return 0;
}

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

sum = 0
B = []

for index,value in enumerate(A):
    index += 1

    if index % 2 == 0:
        sum -= value
    else:
        sum += value

B.append(sum)

for i in range(N-1):
    sum = 2*A[i] - sum
    B.append(sum)

print(*B)

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

typedef long long ll;
const int len = 1e5+5;
int arr[len];

int main(){
    int n;
    scanf("%d", &n);
    ll sum = 0, op = (n*1LL*(n+1))/2, add;
    for (int i = 0; i < n; i++){
        scanf("%d", &arr[i]);
        sum += arr[i];
    }

    if (sum%op != 0){
        printf("NO\n");
        return 0;
    }

    add = sum/op;

    //printf("sum = %lld, op = %lld, add = %lld\n", sum, op, add);
    for (int i = 0; i < n; i++){
        ll dif = arr[(i+1)%n]-arr[i];
        if (dif-add > 0 || (dif-add)%(ll)n != 0){
            printf("NO\n");
            return 0;
        }
    }

    printf("YES\n");
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
    ll int jhogeo = 1;
    rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
    return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}

int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int N; cin>>N;
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  
  vector<int> dpa(N);
  vector<int> dpb(N);
  vector<int> dpc(N);
  
  rep(i,0,N){
    cin>>a[i]>>b[i]>>c[i];
    dpa[i]=0;
    dpb[i]=0;
    dpc[i]=0;
  }
  dpa[0]=a[0];
  dpb[0]=b[0];
  dpc[0]=c[0];
  rep(i,0,N){
    dpa[i]=max(dpb[i-1]+a[i],dpc[i-1]+a[i]);
    dpb[i]=max(dpa[i-1]+b[i],dpc[i-1]+b[i]);
    dpc[i]=max(dpb[i-1]+c[i],dpa[i-1]+c[i]);
  }
  cout<<max(dpa[N-1],max(dpb[N-1],dpc[N-1]));
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順

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


int main(){
  int ans=0;
  string s;
  cin>>s;
  int size = s.size();
  //小数点切捨て サイズは1から
  for(int i = 0;i<size/2;i++){
      if(s.at(i) == s.at(size-1-i)) continue;
      else ans++;
         }
  cout<<ans<<endl;
}



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

string target[4] = { "dream", "dreamer", "erase", "eraser" };

int main() {
    string s;
    cin >> s;
    for (string &t : target) reverse(t.begin(), t.end());
    reverse(s.begin(), s.end());
    while (s.size() >= 5) {
        if (s.substr(0,5) == target[0]) { s = s.substr(5); continue; }
        if (s.substr(0,7) == target[1]) { s = s.substr(7); continue; }
        if (s.substr(0,5) == target[2]) { s = s.substr(5); continue; }
        if (s.substr(0,6) == target[3]) { s = s.substr(6); continue; }
        cout << "NO" << endl;
        return 0;
    }
    cout << (s == "" ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3760
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        int[] X = new int[N];
        Arrays.setAll(X, i->nextInt());

        int max = -1;
        int min = 101;
        for(int i=0; i<N; i++){
            max = Math.max(max, X[i]);
            min = Math.min(min, X[i]);
        }

        int minSum = 0;
        for(int i=min; i<max; i++){
            int sum = 0;
            for(int j=0; j<N; j++){
                sum += Math.pow(X[j]-i, 2.0);
            }
            if(i == min){
                minSum = sum;
                continue;
            }
            minSum = Math.min(minSum, sum);
        }
        println(minSum);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 27220
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 D, E;
  while(cin >> D >> E, D) {
    double ab = 1e18;
    double ans;
    rep(x,0,D + 1) {
      i64 y = D - x;
      double len = sqrt(1.0 * x * x + y * y);
      if(ab > abs(len - E)) {
        ab = abs(len - E);
        ans = len;
      }
    }
    cout << fixed << setprecision(10);
    cout << ab << endl;
  }
}



Measured memory_bytes: 3288
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef unsigned long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)
 
int main() {
	ll A, B;
	scll(A), scll(B);
	printf("%lld", (A + B - 1)/B);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   long long int h,w;
   cin>>h>>w;
   int x=0;
   if((h%2==1)&&(w%2==1))
    x=1;

   if(h==1||w==1)
   {
       cout<<1;
       return 0;
   }
   if(x==1)
   {
     cout<<(h*w+1)/2;
   }
   else
   {
       cout<<h*w/2;
   }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  int l,r,d;
  cin >> l >> r >> d;

  int count = 0;

  for(int i = l; i < r + 1; i++) {
    if(i % d == 0) count++;
  }

  cout << count << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 400;
int valeur[MAXN];
int cumul[MAXN + 1];
int poids[MAXN][MAXN];

int recursion(int debut , int fin)
{
	if (poids[debut][fin] != -1)
	{
		return poids[debut][fin];
	}
	if (debut == fin)
	{
		return 0;
	}
	poids[debut][fin] = 1e18;
	for (int coupe = debut ; coupe < fin ; coupe++)
	{
		poids[debut][fin] = min(poids[debut][fin] , 
								recursion(debut , coupe) + recursion(coupe + 1 , fin) + cumul[fin + 1] - cumul[debut]);
	}
	return poids[debut][fin];
}
int32_t main()
{
	int N;
	cin >> N;
	for (int i = 0 ; i < N ; i++)
	{
		cin>>valeur[i];
		cumul[i + 1] = cumul[i] + valeur[i];
	}
	for (int i = 0 ; i < N ; i++)
	{
		for (int j = 0 ;j  < N ; j++)
		{
			poids[i][j] = -1;
		}
	}
	cout<<recursion(0 , N - 1)<<endl;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, W[100], COUNT = 0, SUM = 0, ANS = 1000000;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> W[i], SUM += W[i];
	for (int i = 0; i < N; i++) {
		//ANS = min(ANS, abs(COUNT - (SUM - COUNT)));
		COUNT += W[i];
		ANS = min(ANS, abs(COUNT - (SUM - COUNT)));
	}
	cout << ANS;
}


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

char b;

int main()
{
	cin>>b;
	if(b=='A') cout<<"T\n";
	else
	if(b=='T') cout<<"A\n";
	else
	if(b=='G') cout<<"C\n";
	else cout<<"G\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define MOD 1000000007
#define int long long
#define N 100005
signed main()
{
    int n;
    cin>>n;
    int i;
    int k;
    cin>>k;
    int a[n];
    int cnt=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=k)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int A[200001];
int n;

LL f(LL b)
{
    LL res = 0;
    for(int i = 1; i <= n; ++i)
        res += abs(A[i] -b -i);
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    for(int i = 1; i <= n; ++i)
        cin>>A[i];
    LL l = -2e9, r = 2e9;
    while(r-l > 3)
    {
        LL m1 = (l+l+r)/3, m2 = (l+r+r)/3;
        if(f(m1) < f(m2))
            r = m2;
        else
            l = m1;
    }
    LL ans = 1e18;
    for(LL i = l; i <= r; ++i)
        ans = min(ans, f(i));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;

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

    LL n, h;
    cin >> n >> h;
    LL max_v = 0;
    vector< LL > v;
    for( int i = 0; i < n; ++i ) {
        LL a, b;
        cin >> a >> b;
        max_v = max( max_v, a );
        v.pb( b );

    }
    sort( v.begin(), v.end(), greater< LL >() );
    LL min_res = L_INF;
    LL tmp = 0;
    bool flg = true;
    LL size = v.size() - 1;

    LL t = h / max_v;
    if( h % max_v ) ++t;
    min_res = min( min_res, t );

    for( LL i = 0; i < v.size(); ++i ) {
        tmp += v[i];
        if( h - tmp <= 0 ) {
            min_res = min( min_res, i + 1 );
            flg = false;
            break;

        } else {
            LL v_tmp = ( h - tmp ) / max_v;
            if( ( h - tmp ) % max_v ) ++v_tmp;

            min_res = min( min_res, i + v_tmp + 1 );

        }

    }


    cout << min_res << endl;
    return 0;
}



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

using namespace std;

#define rep(i , j , k) for (int i = j; i < k; i++)
#define pb push_back
#define for_all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef long double ld;

inline void fileIO(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

template<class T , class S>
inline void smin(T &a, S b) {
	if (a > b)
		a = b;
}

template<class T , class S>
inline void smax(T &a, S b) {
	if (a < b)
		a = b;
}

constexpr int N = 4e5 + 10;

int n;
vi adj[N];

inline void input() {
	cin >> n;
	rep(i , 1 , n) {
		int u , v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
}

int h[N];
void dfs(int v , int par = 0) {
	h[v] = h[par] + 1;
	for (auto e :adj[v])
		if (e ^ par)
			dfs(e , v);
}

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

	input();

	dfs(1);

	int me = max_element(h , h + n + 1) - h;
	
	dfs(me);

	me = *max_element(h , h + n + 1);

	cout << (me % 3 == 2 ? "Second" : "First") << endl;

	return 0;
}


Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1000000000000000
#define mod 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, m, ans = 0;
	cin >> n >> m;
	int x[1616], y[1616], z[1616];
	rep(i, n) cin >> x[i] >> y[i] >> z[i];
	rep(i, (1 << 3)) {
		int bit[4];
		rep(j, 3) bit[j] = i / (1 << j) % 2;
		vector<int>v;
		rep(j, n) {
			int cnt = 0;
			if (bit[0]) cnt += x[j];
			else cnt += x[j] * -1;
			if (bit[1]) cnt += y[j];
			else cnt += y[j] * -1;
			if (bit[2]) cnt += z[j];
			else cnt += z[j] * -1;
			v.push_back(cnt);
		}
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		int cnt = 0;
		rep(j, m) {
			cnt += v[j];
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<vector>

using namespace std;

int main() {
	string str;
	cin >> str;
	int f[26] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
	int n = str.size();
	for( int i=0; i<n; i++ ) {
		f[str[i]-'a']--;
	}
	bool flag = false;
	for( int i=0; i<26; i++ ) {
		if( f[i]<0 ) {
			flag = true;
			break;
		}
	}
	if( flag ) {
		cout << "no" << endl;
	}else {
		cout << "yes" << endl;
	}
	
//	int n, k;
//	cin >> n >> k;
//	vector<int> a, b;
//	vector<int> num;
//	int c, d;
//	for( int i=0; i<n; i++ ) {
//		cin >> c >> d;
//		a.push_back(c);
//		b.push_back(d);
//	}
//	for( int i=0; i<n-1; i++ ) {
//		for( int j=0; j<n-1-i; j++ ) {
//			if( a[j]>a[j+1] ) {
//				swap(a[j], a[j+1]);
//				swap(b[j], b[j+1]);
//			}
//		}
//	}
//	int sum = 0;
//	for( int i=0; i<n; i++ ) {
//		sum += b[i];
//		if( k<=sum ) {
//			cout << a[i];
//			break;
//		}
//	}
////	for( int i=0; i<n; i++ ) {
////		for( int j=0; j<b.at(i); j++ ) {
////			num.push_back(a.at(i));
////		}
////	}
////	sort(num.begin(), num.end());
////	cout << num.at(k-1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int n, m, q, a[53], b[53], c[53], d[53];

ll dfs(int* k, int p, int s) {
	int i, j, mr[13], t;
	ll res, ans;
	if (p == m) {
		if (s != n) {
			return 0ll;
		}
		t = 0;
		for (i = 1; i <= m; i++) {
			for (j = 0; j < k[i]; j++) {
				mr[t++] = i;
			}
		}
		ans = 0ll;
		for (i = 0; i < q; i++) {
			if (mr[b[i] - 1] - mr[a[i] - 1] == c[i]) {
				ans += d[i];
			}
		}
		return ans;
	}
	res = 0ll;
	for (i = 0; i <= n - s; i++) {
		k[p + 1] = i;
		res = max(res, dfs(k, p + 1, s + i));
	}
	k[p + 1] = 0;
	return res;
}

int main(void) {
	int i, k[13] = {};

	scanf("%d%d%d", &n, &m, &q);
	for (i = 0; i < q; i++) {
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	}

	printf("%lld\n", dfs(k, 0, 0));

	return 0;
}

Measured memory_bytes: 3828
# 解説AC
N,A,B,C,D = map(int, input().split())

flag = False
for i in range(N):
    L = i * C + (i - (N - 1)) * D
    H = (i - (N - 1)) * C + i * D

    if L <= B - A <= H:
        flag = True

if flag:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int pd(int n){
    int s=0;
	 for(int i=1;i<=n;i++){
	     if(n%i==0)
	        s++;
		  }
  return s;
}
int main(){
    int a,b,d;
  	cin>>a;
    for(int j=1;j<=a;j+=2){
    b=pd(j);
    	if(b==8)
    		d++;
    }
  	cout<<d<<endl;
  	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = ri()
	}
	dp := make([]int, len(h))
	dp[0] = 0
	dp[1] = abs(h[1] - h[0])
	for i := 2; i < len(h); i++ {
		dp[i] = smaller(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
	}
	fmt.Println(dp[len(dp)-1])
}


Measured memory_bytes: 2304
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val k = sc.nextInt()

  var l: Int
  if (k % 7 == 0) {
    l = 9 * k / 7
  } else {
    l = 9 * k
  }


  if (l % 2 == 0 || l % 5 == 0) {
    println(-1)
    return
  }

  var i = 1
  var tmp = 10L
  while (true) {
    if (tmp % l == 1L) {
      println(i)
      return
    }

    i++
    tmp = tmp % l * 10
  }

}

Measured memory_bytes: 36340
s = input()
s = s[::-1]
n = len(s)
#dream dreamer erase eraser
i = 0
ans = True
while True:
    if i >= n:
        break
    if s[i:i+7] == "remaerd":
        i += 7
    elif s[i:i+6] == "resare":
        i += 6
  
    elif s[i:i+5] == "maerd" or s[i:i+5] == "esare":
        i += 5
    else:
        ans = False
        break

if ans:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int a[10];

int main() {
	REP(i, 3) cin >> a[i];
	sort(a, a + 3);
	cout << a[0] + a[1] + a[2] * 10 << endl;
}

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

int n;
string s;
map <string, int> mmp;

inline void input (int &ret) {
	ret = 0; char ch = getchar ();
	while (!isdigit (ch)) ch = getchar ();
	while (isdigit (ch)) {
		ret = (ret << 1) + (ret << 3) + (ch ^ '0');
		ch = getchar ();
	}
	return;
}

int main () {
	input (n);
	for (register int i = 1; i <= n; ++ i) {
		cin >> s;
		++ mmp[s];
	}
	printf ("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n", mmp["AC"], mmp["WA"], mmp["TLE"], mmp["RE"]);
	return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<map>
#include<cmath>
#define ll long long
#define inf 0x7fffffff;
#define maxn 1005
using namespace std;
int n;
map<string,int> m; 
int read()
{
    int l=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
        w=-1;
        else
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        l*=10;
        l+=ch-'0';
        ch=getchar();
    }
    return l*w;
} 

int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		m[s]=1;
	}
	cout<<m.size()<<endl;
	return 0;
} 

Measured memory_bytes: 19228
#include<stdio.h>

/* ソート関数 */
int int_sort( const void * a , const void * b ) {
  /* 引数はvoid*型と規定されているのでint型にcastする */
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}

int main(void) {
  int n, k;
  scanf("%d %d", &n, &k);
  int* p;
  p = (int*)malloc(sizeof(int)*n);
  int i;
  for(i=0; i<n; i++) {
    scanf("%d", &p[i]);
  }
  qsort((void*)p, n, sizeof(int), int_sort);
  int ans = 0;
  for(i=0; i<k; i++) {
    ans += p[i];
  }
  printf("%d\n", ans);
  return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int A;
    cin >> A;
    N-=A;
  }
  if (N<0) cout << -1 << endl;
  else cout << N << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  string a,b,c,d;cin >>a>>b>>c>>d;
  string s = "=";
  long x = stol(a,NULL,16);
  long y = stol(b,NULL,16);
  if(x<y){
    s = "<";
  }else if(x>y){
    s = ">";
  }
  cout << s;
}



Measured memory_bytes: 256
N, K = list(map(int, input().split()))
ans = [0] * N
for i in range(K):
    d = int(input())
    Ai = list(map(int, input().split()))
    for j in range(d):
        Aij = Ai[j]
        ans[Aij-1] = 1
AC = 0
for i in range(N):
    if ans[i] == 0:
        AC += 1
print(AC)


Measured memory_bytes: 9192
#include<iostream>

using namespace std;

int main(void){

  int n,k,x,y;

  cin >> n >> k >> x >> y;

  int sum = 0;
  int add = x;
  for(int i=1;i<=n;i++){
    if(i > k)add = y;
    sum += add;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
# input処理を高速化する
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    lst_a = list(map(int, input().split()))
    # 石の個数が残りi個の局面で勝ちTrue 負け False　
    dp = [False] * (K+1)
    for i in range(1, K+1):
        for j in range(N):
            if i - lst_a[j] >= 0:
                dp[i] |= not(dp[i - lst_a[j]])
    
    if dp[K]:
        print('First')
    else:
        print('Second')
main()

Measured memory_bytes: 40304
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n ;
    cin >> n ;
    vector<int> a(n) , b(n) ;
    vector<int> xPlusy , xMinusy , yMinusx;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] ;
        xPlusy.emplace_back(a[i] + b[i]) ;
        xMinusy.emplace_back(a[i] - b[i]) ;
        yMinusx.emplace_back(b[i] - a[i]) ;
    }
    sort(xPlusy.begin(), xPlusy.end()) ;
    sort(xMinusy.begin(), xMinusy.end()) ;
    sort(yMinusx.begin(), yMinusx.end()) ;
    int ans = xPlusy.back() - xPlusy[0] ;
    ans = max(ans, xMinusy.back() + yMinusx.back()) ;
    // ans = max(ans, xMinusy.back() + yMinusx.back()) ;
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 11236
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)

int main() {
  for (;;) {
      int L; cin >> L; if (L == 0) break;
      int ans = -1;
      int have = 0;
      REP(step, 12) {
          int a, b; cin >> a >> b;

          have += a;
          have -= b;
          if (have >= L && ans == -1) {
              ans = step + 1;
          }
      }
      if (ans == -1) cout << "NA" << endl;
      else cout << ans << endl;
  }
  return 0;
}

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

int main(){
    while(1){
        int n;
        cin >> n;

        if(n == 0)  break;

        bool appear[n+1] = {};
        for(int i = 1; i < n; i++){
            appear[(i*i)%n] = true;
        }

        vector<int> p;
        for(int i = 0; i <= n; i++){
            if(appear[i])   p.push_back(i);
        }

        int len = p.size();
        int ans[(n-1)/2 + 1] = {};

        for(int i = 0; i < len; i++){
            for(int j = 0; j < len; j++){
                if(i == j)  continue;
                int diff = p[i] - p[j];
                if(diff < 0)        diff += n;
                if(diff > (n-1)/2)  diff = n - diff;
                ans[diff]++;
            }
        }

        for(int i = 1; i <= (n-1)/2; i++){
            cout << ans[i] << endl;
        }
    }

    return 0;
}


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

using namespace std;

using LL = long long;

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

    LL h, w, n;
    cin >> h >> w >> n;
    LL x = max(w, h);
    LL ans = n / x;
    if (n % x) ans++;
    cout << ans << endl; 

    return 0;
}

Measured memory_bytes: 256
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 line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = Integer.parseInt(line);
			long m = n;

			for (int i = n - 1; i > 0; i--) {
				m *= i;
			}
			System.out.println(m);
		}

	}

}

Measured memory_bytes: 16864
inf = 1e18

N = int(raw_input())
HP = sorted([map(int, raw_input().split()) for i in xrange(N)], key = lambda x:x[0] + x[1])
dp =[inf] * 5005

for i in xrange(N):
    H, P = HP[i]
    for j in xrange(N + 1, -1, -1):
        if dp[j] < inf and dp[j] <= H:
            dp[j + 1] = min(dp[j + 1], dp[j] + P)
    dp[1] = min(dp[1], P)

ans = max(i for i in xrange(N + 1) if dp[i] < inf)

print ans


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

int main() {
    int N;
    cin >> N;
    long C, K;
    cin >> C >> K;

    vector<long> T(N);
    for (int i = 0; i < N; i++)
    {
        cin >> T[i];
    }
    sort(T.begin(), T.end());

    int result = 0;
    for (int i = 0; i < N;)
    {
        result++;
        int t = i;
        while (i - t + 1  <= C && T[i] - T[t] <= K && i < N)
            i++;
    }
    cout << result << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    cout << fixed << setprecision(10) << PI*double(N*2) << enld;


    return 0;
}


Measured memory_bytes: 3788
#include <iostream>

using namespace std;

int m;
int n;
int a[128];

bool check(int x) {
  int sum = 0;
  int cnt = 1;

  for (int i = 0; i < n; i++) {
    if (a[i] > x)
      return false;
    sum += a[i];
    if (sum > x) {
      ++cnt;
      sum = a[i];
    }
  }
  
  return cnt <= m;
}

int solve() {

  int lo = 0;
  int hi = 1500000;

  while (hi - lo > 1) {
    int mi = (lo + hi) / 2;
    if (check(mi))
      hi = mi;
    else
      lo = mi;
  }

  return hi;
}


int main(int argc, char *argv[])
{
  while (1) {
    cin >> m >> n;
    if (!n && !m)
      break;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    cout << solve() << endl;
  }
  return 0;
}

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

using ll = long long;

int main(int argc, char **argv)
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  ll a, b, c, d; cin >> a >> b >> c >> d;
  a--;

  ll res = b-a;
  ll nres = 0;
  ll lcmcd = c*d/__gcd(c, d);

  nres += b/c + b/d - b/lcmcd;
  nres -= a/c + a/d - a/lcmcd;

  cout << res - nres << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int s = sc.nextInt();

        int cnt = s / 3;
        int remain = s % 3;
        int mod = (int)1e9 + 7;

        Comb comb = new Comb(s, mod);

        long res = 0;

        while (0 < cnt) {
            int div = cnt - 1;
            long tmp = comb.nCk1(div+remain, remain);
            res += tmp;
            res %= mod;
            cnt--;
            remain += 3;
        }

        System.out.print(res % mod);

    }


    public class Comb {
        int n;   //　要素数
        int MOD = (int)1e9+7;
        long[] facts;

        public Comb(int n, int MOD){
            this.n = n;
            this.MOD = MOD;
            facts = new long[n+1];
            facts[0] = 1;
            for (int i=1; i<n+1; i++){
                facts[i] = facts[i-1] * i % MOD;
            }
        }

        // O(log(MOD))
        public long modpow(long a, long b){
            if (b==0) return 1;
            else if (b==1) return a;
            long x = modpow(a, b/2);
            return b%2 == 0 ? x * x % MOD : x * (x*a%MOD) % MOD;
        }

        // 逆元。x^(-1)≡x^(p-2) (MOD p) xとpは互いに素。
        public long inv(long n){
            return modpow(n, MOD-2);
        }

        public long nCk1(int n, int k){
            return n < k ? 0: facts[n] * (inv(facts[n-k]) * inv(facts[k]) % MOD) % MOD;
        }

        // O(k)
        public long nCk2(int n, int k) {
            long ret = 1;
            for (int i=0; i<k; i++) {
                ret = ret * (n - i) % MOD * inv(k - i);
                ret %= MOD;
            }
            return ret % MOD;
        }

    }


}



Measured memory_bytes: 35792