akhauriyash/Code-Regression huggingface dataset:
import math

a,b,c=map(int,input().split())
if c<=90:
    print(b*math.sin(math.radians(c))*a/2)
    h=b*math.sin(math.radians(c))
    A=max(a,b)
    B=min(a,b)
    H=B*math.sin(math.radians(c))
    X=(B*B-H*H)**0.5
    C=((A-X)**2+H*H)**0.5
    print(C+a+b)
    print(h)
else:
    print(b*math.sin(math.radians(c))*a/2)
    A=a-b*math.cos(math.radians(c))
    h=b*math.sin(math.radians(c))
    x=(b*b-h*h)**0.5
    c=((A)**2+h*h)**0.5
    print(c+a+b)
    print(h)


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

int main(){
    int n;
    char s[101];
    cin >> n >> s;
    if(n%2) {
        cout << "No" << endl;
        return 0;
    } else {
        for(int i=0; i<n/2; i++) {
            if(s[i]!=s[n/2+i]){
                cout << "No" << endl;
                return 0;
            }
        }    
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string s;
int main()
{
     cin>>s;
if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') cout<<"Yes";
     else cout<<"No";
     return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int maxv = max({A, B, C});
    int sum = A + B + C - maxv;
    int K;
    cin >> K;
    while (K > 0) {
        maxv *= 2;
        K--;
    }
    cout << maxv + sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
#define MAX 10
using namespace std;
int cnt = 0;

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> S[N];
	int P[M];
	rep(i,0,M){
		int tmp;
		cin >> tmp;
		rep(j,0,tmp){
			int tmp1;
			cin >> tmp1;
			S[tmp1-1].push_back(i);
		}
	}
	rep(i,0,M){
		cin >> P[i];
	}

	rep(bit,0,1<<N){
		int K[M] = {};
		rep(shift,0,N){
			if(bit & (1<<shift)){
				rep(i,0,S[shift].size()){
					K[S[shift][i]]++;
				}
			}
		}
		int point=0;
		rep(i,0,M){
			if(K[i]%2 == P[i]){
				point++;
			}
		}
		if(point == M){
			cnt++;
		}
	}
	cout << cnt << endl;
}



Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

void Sequence() {
	int n;
	cin >> n;
	ll bt = 1;
	ll ba = 1;
	for (size_t i = 0; i < n; i++)
	{
		ll t, a;
		cin >> t >> a;
		ll g = gcd(t, a);
		ll ct = t / g;
		ll ca = a / g;
		ll mul = max(bt / ct, ba / ca);
		ll rt = ct * mul;
		ll ra = ca * mul;

		while (rt < bt || ra < ba)
		{
			rt += ct;
			ra += ca;
		}
		bt = rt;
		ba = ra;
	}
	cout << (bt + ba) << endl;
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var x,y,m int
  fmt.Scan(&x,&y)
  m = 2147483646
  if x <= y && m > y-x {
    m = y-x
  }
  if -x <= y && m > y+x+1 {
    m = y+x+1
  }
  if x <= -y && m > -y-x+1 {
    m = -y-x+1
  }
  if -x <= -y && m > -y+x+2 {
    m = -y+x+2
  }
  fmt.Println(m)
}

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

int main()
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;

    int turn = 0;
    while (1) {
        switch (turn) {
            case 0:
                if (sa.length() == 0) {
                    cout << 'A' << endl;
                    return 0;
                }
                turn = sa[0] - 'a';
                sa = sa.substr(1, sa.length() - 1);

                break;
            case 1:
                if (sb.length() == 0) {
                    cout << 'B' << endl;
                    return 0;
                }
                turn = sb[0] - 'a';
                sb = sb.substr(1, sb.length() - 1);

                break;
            case 2:
                if (sc.length() == 0) {
                    cout << 'C' << endl;
                    return 0;
                }
                turn = sc[0] - 'a';
                sc = sc.substr(1, sc.length() - 1);

                break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	    int W,H,x,y,r;
		Scanner scanner = new Scanner(System.in);
        W=scanner.nextInt();
        H=scanner.nextInt();
        x=scanner.nextInt();
        y=scanner.nextInt();
        r=scanner.nextInt();
		if(W>=x+r && H>=y+r && x>=r && y>=r ){
			System.out.println("Yes");
		}
		else System.out.println("No");
	}
}


Measured memory_bytes: 26404
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    string n;
    bool ans = false;
    cin >> n;
    if (n[0] == n[1] && n[1] == n[2]) ans = true;
    if (n[1] == n[2] && n[2] == n[3]) ans = true;
    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define UB upper_bound
#define LB lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;
const double PI=3.141592653589;

struct Edge{
  int src;int dst;int wei;
  Edge(int s=0,int d=0,int w=0):src(s),dst(d),wei(w){}
};
using Graph = vector<vector<Edge>>;

int par[100005];
int rnk[100005];


int root(int x){
  return par[x]==x?x:par[x]=root(par[x]);
}
void unite(int a,int b){
  par[root(a)]=root(b);
}

/*
void init(int n){
  REP(i,n){
    par[i]=i;
    rnk[i]=0;
  }
}

int find(int x){
  if(par[x]==x)return x;
  else return par[x]=find(par[x]);
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(rnk[x]<rnk[y])par[x]=y;
  else{
    par[y]=x;
    if(rnk[x]==rnk[y])rnk[x]++;
  }
}
*/


int Kruskal(Graph&g){
    vector<Edge> es;
    REP(i,g.size()){
      REP(j,g[i].size()){
        es.PB(g[i][j]);
      }
    }
    sort(es.begin(),es.end(),[](const Edge&a,const Edge&b){
      return a.wei<b.wei;
    });
    REP(i,g.size())par[i]=i;
    int sum=0;
    REP(i,es.size()){
      if(root(es[i].src)!=root(es[i].dst)){
        sum+=es[i].wei;
        unite(es[i].src,es[i].dst);
      }
    }
    return sum;
}

signed main(){
  int n;
  cin>>n;
  vector<pair<int,int>> vx(n),vy(n);
  int x,y;
  REP(i,n){
    cin>>x>>y;
    vx[i]=MP(x,i);
    vy[i]=MP(y,i);
  }
  sort(ALL(vx));
  sort(ALL(vy));

  Graph g(n);

  REP(i,n-1){
    int sx=vx[i].SEC;int dx=vx[i+1].SEC;
    int sy=vy[i].SEC;int dy=vy[i+1].SEC;
    g[sx].emplace_back(sx,dx,abs(vx[i].FIR-vx[i+1].FIR));
    g[sy].emplace_back(sy,dy,abs(vy[i].FIR-vy[i+1].FIR));
  }
//  init(n);

  cout<<Kruskal(g)<<endl;

  return 0;
}


Measured memory_bytes: 20592
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int k;
  cin >> s >> k;
  vector<string> v;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    string x = "";
    for (int j = 0; j < k; j++) {
      if (i + j >= n) break;
      x += s[i + j];
      v.push_back(x);
    }
  }
  
  sort(v.begin(), v.end());
  
  vector<string> t;
  string z = "A";
  int newstring = 0;
  for (int i = 0; i < v.size(); i++) {
    if (z != v[i]) {
      newstring++;
      z = v[i];
    }
    if (newstring == k) break;
  }
  
  cout << z << endl;
}

Measured memory_bytes: 1660
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
/*#define s second*/
#define PB pop_back
#define pb push_back
#define mp make_pair
/*#define int long long*/
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 2e3 + 10;
int n , m , q , ans , x , y , x2 , y2 , t[MAXN][MAXN] , p[MAXN][MAXN];
char s[MAXN][MAXN];
int32_t main()
{
	IOS
    cin >> n >> m >> q;
    for(int i = 0 ; i < n ; i ++)
		cin >> s[i];
	for(int i = 0; i < m ; i ++)
	{
		t[i][0] = p[i][0] = 0;
		for(int j = 1 ; j <= n ; j ++)
		{
			t[i][j] = t[i][j - 1] , p[i][j] += p[i][j - 1];
			if(s[j - 1][i] == '1')
			{
				if(j - 2 >= 0)
				{
					if(s[j - 2][i] == '0')
						t[i][j] ++;
				}
				else
					t[i][j] ++;
				if(i and s[j - 1][i - 1] == '1')
					p[i][j] ++;
			}
		}
	}
	for(int i = 0 ; i < q ; i ++)
	{
		cin >> x >> y >> x2 >> y2 , ans = 0;
		for(int j = y - 1 ; j <= y2 - 1 ; j ++)
		{
			ans += t[j][x2] - t[j][x - 1];
			if(x - 2 >= 0 and s[x - 2][j] == '1' and s[x - 1][j] == '1')
				ans ++;
			if(j and j - (y - 1))
				ans -= p[j][x2] - p[j][x - 1];
		}
		cout << ans << '\n';
	}
	return cout << '\n' , 0;
}


Measured memory_bytes: 37248
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);

int a, p;

int main(){
    cin >> a >> p;
    p += a*3;
    cout << p/2;
    return 0;
}


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

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

    int n;
    cin >> n;

    cout << (n>=1000? "ABD": "ABC") << endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()

typedef long long ll;
typedef pair<ll, int> P;

int n;
bool c[8];
int cnt;

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

	REP(i,8) c[i]=false;

	cin>>n;
	REP(i,n) {
		int a; cin>>a;
		if(a<400) c[0]=true;
		else if(a<800) c[1]=true;
		else if(a<1200) c[2]=true;
		else if(a<1600) c[3]=true;
		else if(a<2000) c[4]=true;
		else if(a<2400) c[5]=true;
		else if(a<2800) c[6]=true;
		else if(a<3200) c[7]=true;
		else cnt++;
	}
	int sum=0;
	REP(i,8) {
		sum+=(c[i]?1:0);
	}
	if(sum==0) cout<<"1 "<<cnt<<endl;
	else cout<<sum<<' '<<sum+cnt<<endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    if 0 in A:
        print('0')
        return
    prod=1
    for a in A:
        prod*=a
        if prod> 1000000000000000000:
            print('-1')
            return
    print(prod)

ans=main()


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

using namespace std;

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

    int year  = stoi(S.substr(0, 4));
    int month = stoi(S.substr(5, 2));
    int day   = stoi(S.substr(8, 2));

    bool Heisei = false;
    if (year < 2019) Heisei = true;
    if (year == 2019 && month < 4) Heisei = true;
    if (year == 2019 && month == 4 && day <= 30) Heisei = true;

    if (Heisei)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
// #pragma GCC target("avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define MOD2 1000000014000000049LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, ll M>
struct ModFact {
    int inv[N+1];
    int fact[N+1];
    int ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        ll f = 1;
        fact[0] = f;
        for (int i = 0; i < N; i++) {
            f = f*(i+1)%M;
            fact[i+1] = f;
        }
        f = power(f, M-2);
        ifact[N] = f;
        for (int i = N-1; i >= 0; i--) {
            f = f*(i+1)%M;
            ifact[i] = f;
        }
        inv[0] = 0;
        for (int i = 0; i < N; i++) {
            f = ll(fact[i])*ll(ifact[i+1])%M;
            inv[i+1] = f;
        }
    }
    constexpr ll power(ll a, ll b) {
        ll r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
};

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ModFact<100000, MOD> fact;

int main() {
    ll ans = 0;
    int a, N, prev, now;
    N = getint();
    prev = getint();
    REP(i, N-1) {
        now = getint();
        a += fact.inv[i+1];
        if(a > MOD) a -= MOD;
        ans += a * ll(now - prev);
        if(ans > MOD2) ans -= MOD2;
        prev = now;
    }
    printf("%lld\n", ((ans%MOD)*fact.fact[N-1])%MOD);
	return 0;
}


Measured memory_bytes: 1536
import java.awt.Point;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

		while (true) {
			final int m = sc.nextInt();
			
			if(m == 0){
				break;
			}
			
			Point[] points = new Point[m];
			for (int i = 0; i < m; i++) {
				points[i] = new Point(sc.nextInt(), sc.nextInt());
			}
			
			int d_x = points[0].x;
			int d_y = points[0].y;
			for (int i = 0; i < m; i++) {
				points[i].x = points[i].x - d_x;
				points[i].y = points[i].y - d_y;
			}

			final int n = sc.nextInt();

			Point[] global = new Point[n];
			for (int i = 0; i < n; i++) {
				global[i] = new Point(sc.nextInt(), sc.nextInt());
			}

			for (int i = 0; i < n; i++) {
				//System.out.println(i);
				
				int dx = global[i].x;
				int dy = global[i].y;

				// move
				for (int j = 0; j < n; j++) {
					global[j].x -= dx;
					global[j].y -= dy;
				}

				//System.out.println(Arrays.toString(global));
				//System.out.println(x)
				
				boolean check = true;
				for (int p = 0; p < m; p++) {
					boolean found = false;
					for (int j = 0; j < n; j++) {
						if (points[p].x == global[j].x && 
								points[p].y == global[j].y) {
							found = true;
							break;
						}
					}
					
					if (!found) {
						check = false;
						break;
					}
				}

				if (check) {
					System.out.println((dx - d_x) + " "
							+ (dy - d_y));
					break;
				}

				// rev_move
				for (int j = 0; j < n; j++) {
					global[j].x += dx;
					global[j].y += dy;
				}
			}
		}
	}
}

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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), d(N, 0);
    rep(i, 0, N) cin >> A[i];
    // Check if -1
    if(A[0] > 0){
        cout << -1 << endl;
        return 0;
    }
    // main
    ll ans = A[N-1];
    rep(i, 1, N){
        if(A[i] == A[i-1] + 1){
            ;
        }else if(A[i] > A[i-1] + 1){
            cout << -1 << endl;
            return 0;
        }else{
            // A[i] + 1 < A[i+1]
            ans += A[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
// Code for E - NEQ
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

constexpr int MOD = 1000000007;
constexpr int MAX = 500005;

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

long long fact[MAX], invfact[MAX];

void init()
{
  fact[0] = 1;
  for (ll i = 1; i < MAX; ++i) {
    fact[i] = fact[i-1] * i % MOD;
  }

  invfact[MAX-1] = modpow(fact[MAX-1], MOD-2, MOD);
  for (ll i = MAX-1; i >= 1; --i) {
    invfact[i-1] = invfact[i] * i % MOD;
  }
}

long long nCr(long long n, long long r)
{
  return fact[n] * invfact[r] % MOD * invfact[n-r] % MOD;
}
 
long long nPr(long long n, long long r)
{
  return fact[n] * invfact[n-r] % MOD;
}

int main() {
  init();

  int n, m;
  cin >> n >> m;

  ll ans = 0;
  REP(k, n + 1) {
    ll tmp = (nCr(n, k) * nPr(m, k) % MOD * modpow(nPr(m-k, n-k), 2, MOD) % MOD);

    if (k % 2 == 0) ans += tmp;
    else ans -= tmp;
    ans %= MOD;
  }

  cout << ( ans + MOD) % MOD << endl;
  return 0;
}


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

typedef long long int ll;
typedef double d;

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)

#define be(a) a.begin(),a.end()
#define sz(x) x.size()

#define nl cout<<"\n";
#define sp cout<<" ";

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    su;
    int n,m;
    cin>>n>>m;
    n=n*(n-1)/2;
    m=m*(m-1)/2;
    cout<<n+m;
    nl;
    return 0;
}


Measured memory_bytes: 256
// Problem : 
// 			U - Grouping
// 			Editorial
// 		
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_u
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	int n;
	cin >> n;
	int a[n][n];
	rep(i,0,n)
		rep(j,0,n)
			cin >> a[i][j];
	int dp[(1<<n)];
	memset(dp,0,sizeof(dp));
	for(int mask=1;mask<(1<<n);mask++)
	{
		vector<int> v;
		int tmp=0;
		for(int i=0;i<n;i++)
		if((mask&(1<<i)))
			v.pb(i);
		for(auto x:v)
			for(auto y:v)
				tmp+=a[x][y];
		tmp /= 2;
		for(int i=mask;i>0;i=((i-1)&mask))
			tmp = max(tmp,dp[i]+dp[mask^i]);
		dp[mask] =tmp;	
	}
	cout << dp[(1<<n)-1];
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 4084
#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;

struct point {
  int x, y;
};

const int dir[6][2] = { {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {0, 1}, {0, -1} };

int main() {
  int t, n;
  while(scanf("%d%d", &t, &n) != EOF && t) {
    bool visited[200][200]; // 障害物＝もう訪れた、とする。
    fill(&visited[0][0], &visited[0][0]+200*200, false);
    for (int i=0; i<n; i++) {
      int tx, ty;
      scanf("%d%d", &tx, &ty); tx += 100; ty += 100;
      visited[tx][ty] = true;
    }
    queue<pair<point,int>> Q; // 幅優先探索で解く。
    int sx, sy;
    scanf("%d%d", &sx, &sy); sx += 100; sy += 100;
    point p = { sx, sy };
    Q.push(make_pair(p, 0));
    int count = 0;
    while (! Q.empty()) {
      int times = Q.front().second;
      if (times > t) break;
      p = Q.front().first;
      Q.pop();
      if (! visited[p.x][p.y]) {
	visited[p.x][p.y] = true;
	count++;
	// cerr << "Visited (" << p.x << "," << p.y << ")" << " at " << times << endl;
	for (int i=0; i<6; i++) {
	  int tx = p.x+dir[i][0];
	  int ty = p.y+dir[i][1];
	  if (! visited[tx][ty]) {
	    point temp = {tx, ty};
	    Q.push(make_pair(temp, times+1));
	  }
	}
      }
    }
    printf("%d\n", count);
  }
}

Measured memory_bytes: 1236
def main():
    N = input()
    if N%10 != 0:
        print(digitSum(N))
    else:
        print(digitSum(N)*10)

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

if __name__ == '__main__':
    main()


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

const int N=1e5+20;

int n,u,v,ans[N];
vector <pair <int,int>> adj[N];

void dfs(int node,int parent,int old_color)
{
	int current_color=1;
	for(auto p:adj[node])
	{
		int child=p.first,edge=p.second;
		if(child==parent) continue;
		if(current_color==old_color) current_color++;
		ans[edge]=current_color;
		dfs(child,node,current_color);
		current_color++;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back({v,i});
		adj[v].push_back({u,i});
	}

	dfs(1,0,0);
	printf("%d\n",*max_element(ans,ans+n-1));
	for(int i=0;i<n-1;i++) printf("%d\n",ans[i]);
}

Measured memory_bytes: 9344
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	int N,i;
	cin>>N;
	vector<int> d(N);
	for (i=0;i<N;i++){
		cin>>d[i];
	}
	int ans=0;
	int j;
	for (i=0;i<N-1;i++){
		for (j=i+1;j<N;j++){
			ans+=d[i]*d[j];
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a[5];
	for(int i=0;i<5;i++)cin>>a[i];
	sort(a,a+5);
	for(int i=4;i>=0;i--)(i==0)?cout<<a[i]<<endl:cout<<a[i]<<" ";
	return 0;
}

Measured memory_bytes: 1176
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdlib.h>
#include<set>

using namespace std;

int main(void)
{
    int N;
    cin>>N;
    
    int a[N];
    int max=0,second_max=0;
    int max_num=1;
    
    for(int i=0;i<N;i++){
        cin>>a[i];
        if(a[i]>max){
            second_max=max;
            max=a[i];
            max_num=1;
        }
        else if(a[i]==max){
            max_num++;
        }
        else{
            if(a[i]>second_max){
                second_max=a[i];
            }
        }
    }
    
    for(int i=0;i<N;i++){
        if(a[i]==max && max_num>1){
            cout<<max<<endl;
        }
        else if(a[i]==max && max_num==1){
            cout<<second_max<<endl;
        }
        else{
            cout<<max<<endl;
        }
    }
}


Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, k, s;
	cin >> n >> k >> s;
	
	for(int i = 0; i < k; ++i) {
		cout << s << " ";
	}
	
	if( s != 1e9 ) {
		for(int i = 0; i < n - k; ++i) {
			cout << 1000000000 << " ";
		}
	} else {
		for(int i = 0; i < n - k; ++i) {
			cout << 1 << " ";
		}
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <random>
#include <chrono>
using namespace std;

int n;
int x, y;
const int maxn = 2005;
int cnt[maxn];

int main(){
    cin >> n >> x >> y;
    for(int i = 1; i <= n;i++){
        for(int j = i + 1;j <= n;j++){
            int dis = j - i; 
            dis = min(dis, abs(i - x) + abs(j - y) + 1);
            dis = min(dis, abs(i - y) + abs(j - x) + 1);
            cnt[dis]++;
        }
    }
    for(int i = 1;i < n;i++){
        printf("%d\n", cnt[i]);
    }
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=1e5+10;
char S[MAXN];
int ls,Root,Ds;
int main()
{   scanf("%s",S+1),ls=strlen(S+1);
	if(S[ls]=='1'||S[1]=='0') {   puts("-1");   return 0;   }
	for(rg int i=1;i<ls;i++)
		if(S[i]!=S[ls-i]){   puts("-1");   return 0;   }
	puts("1 2"),Root=2;
	for(rg int i=3;i<=ls;i++)
	{   printf("%d %d\n",Root,i);
		if(S[i-1]=='1') Root=i;
	}
}


Measured memory_bytes: 1536
n = int(input())
t, a = map(int, input().split())
H = list(map(int, input().split()))
ans = []
for i in range(n):
    average_tmp = t - H[i] * 0.006
    diff = abs(a - average_tmp)
    ans.append(diff)
print(ans.index(min(ans)) + 1)


Measured memory_bytes: 9256
#include <iostream>
//#include <iomanip>

using namespace std;
//#define

int main() {
	int h, w;

	while(1){
		cin >> h >> w;
		if(h==0 && w==0) break;

		for(int i=0;i<h;i++){
			for(int k=0;k<w;k++){
				if(i==0 || i==h-1 || k==0 || k==w-1){
					cout << '#';
				}else{
					cout << '.';
				}
			}
			cout << "\n";
		}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 1120
#pragma GCC optimize("trapv")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>

using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 + 100, INF = 1e9 * 1e9 + 10, MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

char grid[502][502], ansBl[502][502], ansR[502][502];
bool usd[502];

signed main()
{
    fastInp;

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

    ll ans = INF;

    if (a % 2 == 0 || c % 2 == 0 || b % 2 == 0) {
        cout << "0";
        return 0;
    }

    ll m = a / 2;
    ans = min(ans, b * c);
    ans = min(ans, c * a);
    ans = min(ans, b * a);

    cout << ans;
    return 0;
}

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

int main(){
  	string n;
  	cin>>n;
  if(n.at(0)=='7'||n.at(1)=='7'||n.at(2)=='7'){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end



int main(){
   ll a,b,c,k; cin>>a>>b>>c>>k;
   if(k<a)cout<<k<<endl;
   else if(k<a+b)cout<<a<<endl;
   else cout<<a-(k-a-b)<<endl;
   return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int test)
{
  cin >> n;
  int x[20], y[20];
  for (int i = 0; i < n; ++i) {
   cin >> x[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> y[i];
  } 
  int ans = -inf;
  for (int i = 0; i < (1 << n); ++i) {
    int cur = 0;
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j)) {
        cur += x[j] - y[j];
      }
    }
    ans = max(ans, cur);
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
N, C = map(int, input().split())
XV = [list(map(int, input().split())) for _ in range(N)]

R = [[0 for _ in range(4)] for _ in range(N)]
L = [[0 for _ in range(4)] for _ in range(N)]

for i in range(N):
  R[i][3] = 0
  L[i][3] = 0

for i in range(N):
  R[i][0] = XV[i][0]
  R[i][1] = XV[i][1]
  L[i][0] = C - XV[i][0]
  L[i][1] = XV[i][1]
L.sort()

for i in range(N):
  R[i][2] = R[i - 1][2] + R[i][1]
  L[i][2] = L[i - 1][2] + L[i][1]
for i in range(N):
  R[i][2] -= R[i][0]
  L[i][2] -= L[i][0] 
  R[i][3] = max(R[i - 1][3], R[i][2])
  L[i][3] = max(L[i - 1][3], L[i][2])
#print("R:", R)
#print("L:", L)

answer = []
for i in range(N):
  if i != N - 1:
    answer.append(R[i][2] + max(L[N - 2 - i][3] - R[i][0], 0))
  else:
    answer.append(R[i][2])

L, R = R, L
for i in range(N):
  if i != N - 1:
    answer.append(R[i][2] + max(L[N - 2 - i][3] - R[i][0], 0))
  else:
    answer.append(R[i][2])

answer = max(answer)
print(answer if answer > 0 else 0)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

int N;
string moji = "abcdefghijklmnopqrstuvwxyz";
void dfs(string s, int num, int mx){
  s.push_back(moji[num]);
  if (s.size() == N){
    cout << s << endl;
  }else{
    rep(i, mx + 2){
      dfs(s, i, max(i, mx));
    }
  }
}

int main(){
  cin >> N;
  string s;
  dfs(s, 0, 0);
}
  

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

const int N = 1005;
int h,w;
char g[N][N];
const int mod = 1e9+7;
ll ans = 0;
ll dp[N][N];

ll sol(int i,int j)
{
  if(i == h && j == w)  return 1;
  if(i>h || j>w) return 0;
  if(g[i][j] == '#')  return 0;
  ll &res = dp[i][j];
  if(res != -1) return res;
  res = sol(i+1,j)%mod;
  res = (res + sol(i,j+1)%mod)%mod;
  return res;
}

void solve()
{
  cin >> h >> w;
  for(int i=1;i<=h;i++)
  {
    for(int j=1;j<=w;j++)
    {
      cin >> g[i][j];
    }
  }
  memset(dp,-1,sizeof(dp));
  ans = sol(1,1);
  cout << ans;
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t = 1;
  //cin >> t;
  //int tc = 1;
  while(t--)
  {
    //cout << "Case #" << tc << ": ";
    solve();
    //tc++;
  }
  return 0;
}
/*==============================================================================================================================================================*/


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)

int main(){
	//input
	ll A,B,C,D; cin>>A>>B>>C>>D;
	if(abs(A-C)<=D) cout<<"Yes";
	else{
		if(abs(A-B)<=D && abs(B-C)<=D) cout<<"Yes";
		else cout<<"No";
	}
}

Measured memory_bytes: 256
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    org_a = sum(a)
    for i in range(n):
        amari = b[i] - a[i]
        a[i] = max(0, a[i] - b[i])
        if amari > 0:
            a[i + 1] = max(a[i + 1] - amari, 0)
    return org_a - sum(a)


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 18624
import numpy as np
n = int(input())
s = list(input())
j = []
now = 0
unclosen = 0
opened = 0
for i in s:
    if i == ")":
        now -= 1
        if opened:
            opened -= 1
        else:
            unclosen += 1
    else:
        now += 1
        opened += 1
j = np.array(j)
print("(" * unclosen + "".join(s) + ")" * opened)

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

int main() {
  string s,t;
  cin>>s>>t;
  if(t==s+"q"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"w"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"e"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"r"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"t"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"y"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"u"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"i"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"o"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"p"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"a"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"s"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"d"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"f"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"g"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"h"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"j"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"k"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"l"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"z"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"x"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"c"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"v"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"b"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"n"){
    cout<<"Yes"<<endl;
  }
  else if(t==s+"m"){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}


Measured memory_bytes: 3540
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define pb push_back
#define mp make_pair
using pii = pair<int,int>;
const int N = 100005;
const int Inf = 1e17+7;
#ifndef M_PI
#define M_PI 3.1415926535
#endif
#define F first
#define S second

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//		cout << setprecision(10) << fixed;
}

int n, k, s;

int gcd(int x, int y)
{
	int r;
	while (y > 0)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

signed main()
{
	io();
	cin >> k;
	for (int i = 1; i <= k; ++i)
	{
		for (int j = 1; j <= k; ++j)
		{
			for (int t = 1; t <= k; ++t)
			{
				s += gcd(gcd(i, j), t);
			}
		}
	}
	cout << s;
}

Measured memory_bytes: 3640
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String SDash = sc.next();
        String T = sc.next();

        // なるべく後ろにTを入れたい
        StringBuilder S = new StringBuilder(SDash);
        boolean isRestorable = false;
        for (int i = S.length() - 1; i >= 0; i--) {
            boolean isRestorableTmp = true;
            for (int j = 0; j < T.length(); j++) {
                if (!(i + j < S.length() && (S.charAt(i + j) == '?' || S.charAt(i + j) == T.charAt(j)))) {
                    isRestorableTmp = false;
                    break;
                }
            }

            if (isRestorableTmp) {
                for (int j = 0; j < T.length(); j++) {
                    S.setCharAt(i + j, T.charAt(j));
                }
                isRestorable = true;
                break;
            }
        }

        if (isRestorable) {
            for (int i = 0; i < S.length(); i++) {
                if (S.charAt(i) == '?') {
                    S.setCharAt(i, 'a');
                }
            }
            out.println(S.toString());
        } else {
            out.println("UNRESTORABLE");
        }
    }
}

Measured memory_bytes: 23124
#include<stdio.h>
#define N 8
int Get_Solution(int);
int check(int,int);
int a[N][N]={0};

int main(){
  int n,i,j;
  int x,y;
  int d=0;
	
  scanf("%d",&n);	
  for(i=0;i<n;i++){
    scanf("%d %d",&y,&x);
    a[y][x]=1;
  }	
  i=Get_Solution(d);  
  return 0;
}

void printboard(){
  int i,j;
	
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(a[i][j]==1)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
	return;	
}


int check(int y,int x){
  int i,j;
     
  for(i=0;i<N;i++){
    if(i!=x && a[y][i]==1)return 0;
  }
  
  for(i=0;i<N;i++){
    if(i!=y && a[i][x]==1)return 0;
  }
	
  i=y-1; j=x+1;
  while(i>=0 && j<N){
    if(a[i--][j++]==1)return 0;
  }
	
  i=y-1; j=x-1;
  while(i>=0 && j>=0){
    if(a[i--][j--]==1)return 0;
  }
	
  i=y+1; j=x-1;
  while(i<N && j>=0){
    if(a[i++][j--]==1)return 0;
  }
	
  i=y+1; j=x+1;
  while(i<N && j<N){
    if(a[i++][j++]==1)return 0;
  }
  return 1;	
}


int Get_Solution(int d){
  int i;
	
  for(i=0;i<N;i++){
    if(a[d][i]==1){
      if(!Get_Solution(d+1))return 0;
    }
  }
  if(d==N){
    printboard();
    return 1;
  }
  else {
    for(i=0;i<N;i++){
      if(a[d][i]==0 && check(d,i)){
	a[d][i]=1;
	if(!Get_Solution(d+1)){
	  a[d][i]=0;
	}
      }
    }
  }	
  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
const int N=2E5+7;
double arr[N];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        arr[i]=(x+1)/double (2.0);
    }
    double sum=0;
    for(int i=1;i<=k;i++){
        sum+=arr[i];
    }
    double ans=0;
    ans=max(ans,sum);
    int l=1,r=k+1;
    while(r<=n){
        sum-=arr[l];
        sum+=arr[r];
        ans=max(ans,sum);
        r++;
        l++;
    }
    printf("%.12lf\n",ans);

    return 0;
}


Measured memory_bytes: 1792
n = int(input())
line = input()
arr= line.split(" ")
nums = []
for c in range(n):
    nums.append(int(arr[c]))

flag = "true"
convert_n = 0
while flag == "true":
    flag = "false"
    for i in range(len(nums)-1, 0, -1):
        if nums[i] < nums[i-1]:
            tmp = nums[i]
            nums[i] = nums[i-1]
            nums[i-1] = tmp
            flag = "true"
            convert_n += 1
            
n_list_str = ""
for num in nums:
    n_list_str += str(num)
    n_list_str += " "
print(n_list_str.rstrip(" "))
print(convert_n)

Measured memory_bytes: 5600
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (a, b, c, d) = readListOfInt()

    val isAble = (Math.abs(a-b) <= d && Math.abs(b-c) <=d) || Math.abs(a-c) <= d
    println(if(isAble) "Yes" else "No")
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }


// Extensions
fun<T> List<T>.toBuckets(bucketKeys: List<T>): Map<T, Int> {
    val buckets = bucketKeys.associate { t -> Pair(t, 0) }.toMutableMap()
    this.forEach { t ->
        buckets[t] = buckets[t]!! + 1
    }
    return buckets
}

fun <K, V> Map<K, V>.toMutableMap(): MutableMap<K, V> = HashMap(this)

// Util Functions
fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun Double.isDecimal(): Boolean = ((this - Math.floor(this)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


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

int main()
{
    string s, t;
    cin >> s >> t;

    if (s.size() + 1 != t.size())
    {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != t[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
using namespace std;
const int N=105;
int a[N];
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	
	for(i=1;i<=n;i++)
		if(a[i]%2==0){
			if(a[i]%3!=0 && a[i]%5!=0){
				printf("DENIED");
				return 0;
			}
		}
	printf("APPROVED");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>

int A[20000003], size = 0;
void insert(int *, int);
void increase(int *, int, int);
int extract(int *);
int parent(int);
void maxheapify(int *, int);
int left(int *, int);
int right(int *, int);

main() {
  int n, i;
  char com[20];

  while(1) {
    scanf("%s", com);
    if(com[0] == 'i') {
      scanf("%d", &n);
      insert(A, n);
    }
    else if(com[0] == 'e' && strlen(com) > 5) {
      printf("%d\n", extract(A));
    }
    else {
      break;
    }
  }
  return 0;
}

void insert(int *A, int key) {
  size = size + 1;
  A[size] = INT_MIN;;
  increase(A, size, key);
}

void increase(int *A, int i, int key) {
  int tmp, p;
  if(key < A[i]) {
    printf("error");
  }
  A[i] = key;
  while(i > 1 && A[parent(i)] < A[i]) {
    tmp = A[parent(i)];
    A[parent(i)] = A[i];
    A[i] = tmp;
    i = parent(i);
  }
}

int extract(int *A) {
  int max;
  if(size < 1) {
    printf("error");
    return 0;
  }
  max = A[1];
  A[1] = A[size];
  size = size - 1;
  maxheapify(A, 1);
  return max;
}

int parent(int i) {
  return i / 2;
}
int left(int *a, int i) {
    return 2 * i;
}
int right(int *a, int i) {
    return 2 * i + 1;
}

void maxheapify(int *a, int i) {
  int largest, l, r, tmp;
  l = left(a, i);
  r = right(a, i);
  if(l <= size && a[l] > a[i]) {
    largest = l;
  }
  else {
    largest = i;
  }
  if(r <= size && a[r] > a[largest]) {
    largest = r;
  }
  if(largest != i) {
    tmp = a[i];
    a[i] = a[largest];
    a[largest] = tmp;
    maxheapify(a, largest);
  }
}

Measured memory_bytes: 4692
n = int(input())
arr = [ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(arr[n-1])

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

using namespace std;

#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)

const int MC = 200010;
int N, M;
bool x[MC], y[MC];

bool judge() {
	repp(v, 2, N) {
		if (x[v] && y[v]) return 1;
	}
	return 0;
}

int main() {
	scanf("%d%d", &N, &M);
	repp(i, 0, M) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a == 1) x[b] = 1;
		if (b == N) y[a] = 1;
	}
	printf("%s\n", judge() ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 640
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		cs1: Chars,
		cs2: Chars,
		cs3: Chars,
	}

	println!("{}{}{}", cs1[0], cs2[1], cs3[2]);
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double

using namespace std;

    const ll N = 1e2 + 7;
    const ll mod = 1e9 + 7;
    const ld eps = 1e-9;



void solve(){
    ll x , k , d;
    cin >> x >> k >> d;
    x = abs(x);
    ll n = x / d;
    if(k < n){
        cout << x - (k * d);
        return;
    }
    x -= n * d;
    k -= n;
    if(k % 2 == 0){
        cout << abs(x);
    }
    else{
        cout << min(abs(x - d) , abs(x + d));
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tt = 1;
    //cin >> tt;
    while(tt --){
            solve();
    }
}

/**

**/


Measured memory_bytes: 3644
n, w = list(map(int, input().split()))
warr = [0]*(n+1)
varr = [0]*(n+1)
for i in range(n):
    wi, vi = list(map(int, input().split()))
    warr[i+1] = wi
    varr[i+1] = vi
    
dp = [[0]*(w+1) for _ in range(n+1)]

for i in range(1,n+1):
    for j in range(1,w+1):
        jw = j-warr[i]
        if jw <0:
            dp[i][j] = dp[i-1][j]
            continue
        dp[i][j] = max(dp[i-1][jw] + varr[i], dp[i-1][j])
        
print(dp[n][w])

Measured memory_bytes: 120044