akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <cassert>

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;

int sz[100001];
int col;
int cc[100000];
int n, m;
vector <int> g[100000];
int hh[100000];
int oo[100000][2];

bool dfs(int cur, int curCol, int flag) {
	if (cc[cur] != 0) {
		if (flag != hh[cur]) return true;
		return false;
	}
	sz[curCol]++;
	cc[cur] = curCol;
	hh[cur] = flag;
	oo[curCol][flag]++;
	bool ans = false;
	for (int i = 0; i < g[cur].size(); i++) {
		if (dfs(g[cur][i], curCol, 1 - flag)) ans = true;
	}
	return ans;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) if (cc[i] == 0) {
		col++;
		if (dfs(i, col, 0)) {
			ans += 1LL * sz[col] * (sz[col] - 1) / 2;
		} else {
			ans += 1LL * oo[col][0] * oo[col][1];
		}
	}
	cout << ans - m << endl;
	return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  cin >> n;
  ll sumb=0,summae=0,sumato=0;
  priority_queue<ll>mae;
  priority_queue<ll,vector<ll>,greater<ll>>ato;
  rep(i,n){
    int s;
    cin >> s;
    if(s==1){
      ll a,b;
      cin >> a >> b;
      sumb+=b;
      if(mae.size()>ato.size()){
        ll t=mae.top();
        if(t>a){
          mae.pop();
          summae-=t;
          mae.push(a);
          summae+=a;
          ato.push(t);
          sumato+=t;
        }
        else{
          ato.push(a);
          sumato+=a;
        }
      }
      else{
        if(mae.empty()){
          mae.push(a);
          summae+=a;
        }
        else{
          ll t=ato.top();
          if(a<t){
            mae.push(a);
            summae+=a;
          }
          else{
            ato.pop();
            sumato-=t;
            ato.push(a);
            sumato+=a;
            mae.push(t);
            summae+=t;
          }
        }
      }     
    }
    else{
      ll x=mae.top();
      ll res =(x*mae.size()-summae)+(sumato-x*ato.size())+sumb;
      cout << x << " " << res <<  endl;
    }
  }
}


Measured memory_bytes: 3828
import sys
input = sys.stdin.readline
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD=10**9+7

a,p=rl()
print((3*a+p)//2)

Measured memory_bytes: 3064
import math
import itertools
n = int(input())
a = []
for i in range(n):
	x,y = map(int, input().split())
	a.append([x,y])
x = 0
y = 0
s = 0
b = []
c = 0
for i in itertools.permutations(a):
	x = i[0][0]
	y = i[0][1]
	s = 0
	c += 1
	for xx,yy in i[1:]:
		s += math.sqrt((x-xx)**2 + (y-yy)**2)
		x = xx
		y = yy
	b.append(s)
print (sum(b)/c)

Measured memory_bytes: 4404
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
 
using namespace std;
int main(void){
    double N;
    // Your code here!
    cin >> N;     
    if((int)N % 2 == 0){
        cout << 0.5 << endl;
    }else{
        cout << ((int)N/2 + 1)/N << endl;
    }
    
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }
int abo[4];
	
int main() {
	string str;
	for(;~scanf("%*f");){
		getchar();
		cin>>str;
		if(str=="A")abo[0]++;
		if(str=="B")abo[1]++;
		if(str=="AB")abo[2]++;
		if(str=="O")abo[3]++;
	}
	cout<<abo[0]<<endl;
	cout<<abo[1]<<endl;
	cout<<abo[2]<<endl;
	cout<<abo[3]<<endl;
	return 0;
}

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

int main()
{

    std::vector<std::vector<int>> map(3,std::vector<int>(3));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            std::cin>>map[i][j];
        }
    }
    bool res = false;
    std::vector<int> a(3);
    for(a[0] = 0;a[0] <= 100;a[0]++){
        for(a[1] = 0;a[1] <= 100;a[1]++){
            for(a[2] = 0;a[2] <= 100;a[2]++){
                bool flag = true;
                std::vector<int> b(3);
                for(int i=0;i<3;i++)b[i] = map[0][i] - a[0];
                for(int i=1;i<3;i++){
                    for(int j=0;j<3;j++){
                        if(b[j] != map[i][j] - a[i])flag = false;
                    }
                } 
                //std::cout<<a[0]<<" : "<<a[1]<<" : "<<a[2]<<std::endl;
                //std::cout<<b[0]<<" : "<<b[1]<<" : "<<b[2]<<std::endl;
                if(flag)res = true;
            }
        }
    }
    std::cout << (res ? "Yes" : "No") << std::endl;
}

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

using ll = long long;
const int MOD = 998244353;

ll powmod(ll a, ll b) {
  a %= MOD;
  ll res = 1;
  while (b > 0) {
    if (b % 2 == 1) res = res * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return res;
}
ll fact[200005];
void cominit() {
  fact[0] = 1;
  for (int i = 0; i < 200000; i++) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r) return 0;
  if (n < 0 or r < 0) return 0;
  return fact[n] * powmod(fact[r] * fact[n - r], MOD - 2) % MOD;
}

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  cominit();
  ll ans = 0;
  for (int i = 0; i < k + 1; i++) {
    ll res = nCr(n - 1, i);
    res *= m * powmod(m - 1, n - i - 1) % MOD;
    res %= MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
}

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

int main(){
  
	long long int N;
  	cin >> N;
  
  	int rN = (int)(sqrt(N));
  	long long int res = N - 1LL;
    
  	for( int i = rN ; i > 1 ; i--){
      if( N % i == 0 ){
        res = N/i + i - 2;
      	break;
      }
    }
	
	cout << res << endl;
  
}

Measured memory_bytes: 256
(function(stdin){
  var input = stdin.split("\n");
  var n = parseInt(input[0], 10);
  var a = input[1].split(" ");

  for (var i = 0; i < n; i++) {
    a[i] = parseInt(a[i], 10);
  }

  var ans = 1;
  var up = false;
  var down = false;
  for (var i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      up = true;
    }

    if (a[i] > a[i + 1]) {
      down = true;
    }

    if (up && down) {
      up = down = false;
      ans++;
    }
  }

  console.log(ans);
})(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17484
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			dist = new int[h][w];
			map = new char[h][w];
			for (int i = 0; i < h; i++) {
				char[] cs = scanner.next().toCharArray();
				for (int j = 0; j < w; j++) {
					dist[i][j] = -1;
					char c = cs[j];
					map[i][j] = c;
					if (c == 'S') {
						sy = i;
						sx = j;
						map[i][j] = '.';
					} else if (c == 'G') {
						gy = i;
						gx = j;
						map[i][j] = '.';
					}
				}
			}
			int ID = 1;
			ice = new int[h * w];
			id = new int[h][w];
			ice[0] = INF;
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++) {
					if (id[i][j] == 0 && map[i][j] == 'X') {
						mark(i, j, ID);
						if (ice[ID] == 1)
							map[i][j] = '#';
						ID++;
					}

				}
			Deque<Point> deque = new ArrayDeque<Main.Point>();
			deque.offer(new Point(gy, gx));
			dist[gy][gx] = 0;
			while (!deque.isEmpty()) {
				Point p = deque.poll();
				for (int[] m : move) {
					int ny = p.y + m[0];
					int nx = p.x + m[1];
					if (!isOK(ny, nx))
						continue;
					if (map[ny][nx] != '#' && dist[ny][nx] == -1) {
						dist[ny][nx] = dist[p.y][p.x] + 1;
						deque.offer(new Point(ny, nx));
					}

				}
			}
			ans = dist[sy][sx];
			hit = new int[h * w];
			while (true) {
				Arrays.fill(hit, 0);
				b = new boolean[h][w];
				b[sy][sx] = true;
				if(f(sy, sx, 0))
					break;
				ans++;
			}
			System.out.println(ans);

		}
	}

	private boolean f(int y, int x, int depth) {
		if (ans < depth + dist[y][x])
			return false;
		if (y == gy && x == gx)
			return true;
		for (int[] m : move) {
			int ny = y + m[0];
			int nx = x + m[1];
			if (!isOK(ny, nx))
				continue;
			if (b[ny][nx] || map[ny][nx] == '#')
				continue;
			if (ice[id[ny][nx]] / 2 > hit[id[ny][nx]]) {
				hit[id[ny][nx]]++;
				b[ny][nx] = true;
				if (f(ny, nx, depth + 1))
					return true;
				hit[id[ny][nx]]--;
				b[ny][nx] = false;
			}
		}
		return false;
	}

	private void mark(int i, int j, int ID) {
		ice[ID]++;
		id[i][j] = ID;
		for (int[] m : move) {
			int ny = i + m[0];
			int nx = j + m[1];
			if (!isOK(ny, nx))
				continue;
			if (map[ny][nx] == 'X' && id[ny][nx] == 0)
				mark(ny, nx, ID);
		}
	}

	private boolean isOK(int y, int x) {
		if (0 <= y && y < h && 0 <= x && x < w)
			return true;
		return false;
	}

	int h, w, sx, sy, gx, gy, INF = 1 << 24, ans;
	char[][] map;
	int[][] dist, id;
	int[] ice, hit;
	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
	boolean[][] b;

	class Point {
		int y, x;

		public Point(int y, int x) {
			super();
			this.y = y;
			this.x = x;
		}

		@Override
		public String toString() {
			return "Point [y=" + y + ", x=" + x + "]";
		}

	}
}

Measured memory_bytes: 22976
from math import log2, ceil

N, K = map(int, input().split())

ans = 0

for i in range(1, N+1):
    if K <= i: ans += 1 
    else:
        x = log2(K/i)
    
        ans += 2 ** -ceil(x)
    
print(1/N * ans)    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

template<unsigned int mod_>
struct ModInt{
	using uint = unsigned int;
	using ll = long long;
	using ull = unsigned long long;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
	friend istream& operator>>(istream &o,ModInt& x){
		ll tmp;
		o>>tmp;
		x=ModInt(tmp);
		return o;
	}
	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;

mint C[2010][2010];
mint f[2010][2010];

mint solve1(int A,int B){
	if(A==0 || B==0) return 1;
	return f[B-1][A];
}

int main(){
	rep(i,2010){
		C[i][0] = C[i][i] = 1;
		rep1(j,i-1) C[i][j] = C[i-1][j-1] + C[i-1][j];
	}
	int A,B;
	cin>>A>>B;

	rep(X,B){
		mint now = 0;
		rep(y,A+2){
			if(X>=y) now += C[X][y];
			f[X][y] = (y==0?0:f[X][y-1]) + now;
		}
	}

	mint ans = 0;
	rep(P,A+1){
		rep(x,A-P+1){
			if(x>B-1) break;
			ans += C[B-1][x] * solve1(A-P-x,x);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 31744
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort(reverse=True)
    return divisors

a,b,k=map(int,input().split())

a_list=make_divisors(a)
b_list=make_divisors(b)
#print(a_list,b_list)
a_and_b=set(a_list) & set(b_list)
#print(a_and_b)
ans=sorted(list(a_and_b),reverse=True)
print(ans[k-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 998244353
#pragma GCC optimize("-O2")
#define mod3 127
#define mod 1000000007
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector<vector<int>>
#define v4096 vector<vector<lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli, lli>
#define m32 map<int, int>
#define m64it map<lli, lli>::iterator
#define m32it map<int, int>::iterator
#define fastio                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ist insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define p_q priority_queue
#define min_p_q priority_queue<int, vt<int>, greater<int>>
using namespace std;
using namespace __gnu_pbds;
lli tmod(lli x, lli y)
{
    return (x % y + y) % y;
}
template <typename T>
void DEBUG_ARR(vt<T> a)
{
    f(i, 0, a.size()) cout << a[i] << " ";
    cout << "\n";
}
lli power(lli x, lli y) 
{
    lli res = 1;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;
    }
    if(res<0)res+=mod;
    return res; 
}

int main()
{
    fastio;
    int a,b;
    cin>>a>>b;
    string s1,s2;
    f(i,0,b)s1.push_back('0'+a);
    f(i,0,a)s2.push_back('0'+b);
    if(s1<s2)cout<<s1;
    else cout<<s2;
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;
fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();

    let mut K: i32 = iter.next().unwrap().parse().unwrap();
    let mut X: i32 = iter.next().unwrap().parse().unwrap();
    if 500 * K >= X {
        println!("Yes")
    } else {
        println!("No")
    }

}



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

void print_vec(vector<int> b, int m)
{
  for (int i = 0; i < m+1; i++)
  {
    cout << b[i] << " ";
  }
  cout << endl;  
}

int main()
{
  ll n;
  cin >> n;
  vector<int> a(n+1,0);
  for (ll i = 1; i <= n; i++)
  {
    cin >> a[i];
  }

  vector<int> b(n+1,0);
  for (ll x = n; x > 0; x--)
  {
    int tmp = 0;
    ll y = x;
    while(y<=n)
    {
      tmp = (tmp + b[y])%2;
      y += x;
    }
    b[x] = (a[x]&1) ^ (tmp&1);
    //print_vec(b,n);
  }
 

  ll m = 0;
  for (ll i = 0; i < n+1; i++)
  {
    m += b[i];
  }

  cout << m << endl;
  if(m==0) return 0;
  for (ll i = 1; i < n+1; i++)
  {
    if(b[i]==1) cout << i << " ";
  }
  cout << endl;
  
  
  

  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
      lint n,g;
      cin>>n>>g;
      lint p[n];
      lint c[n];
      rep(i,n)cin>>p[i]>>c[i];
      lint ans=INF;
      rep(bit,1<<n){
          bool x[n];
          fill(x,x+n,false);
          rep(i,n)if(bit&(1<<i))x[i]=true;
          lint cost=0;
          lint comp=0;
          rep(i,n){
              if(x[i]){
                cost+=p[i]*(i+1)*100+c[i];
                comp+=p[i];
              }
          }
        for(lint i=n;i>=0;i--){
            if(x[i])continue;
            rep(j,p[i]){
                if(cost>=g)break;
                cost+=(i+1)*100;
                comp++;
            }
        }


          ans=min(ans,comp);
      }
      cout<<ans<<endl;
  }
      

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
void hukasa(vector<vector<int>> s,vector<vector<int>> table,int &ans,pii frm,int n,int m){
  int x,y;
  tie(x,y) = frm;
  set<pii> se;
  if(x-1 >= 0)se.insert(pii(x-1,y));
  if(x+1 < n)se.insert(pii(x+1,y));
  if(y-1 >= 0)se.insert(pii(x,y-1));
  if(y+1 < m)se.insert(pii(x,y+1));
  for(auto t:se){
    int tx,ty;
    tie(tx,ty) = t;
    if(s.at(tx).at(ty) && table.at(tx).at(ty) == -1){
      table.at(tx).at(ty) = table.at(x).at(y) + 1;
      ans = max(ans,table.at(tx).at(ty));
      hukasa(s,table,ans,t,n,m);
      table.at(tx).at(ty) = -1;
    }
  }
}
void daiku(int frm,vector<vector<pii>> g,vector<int> &cost,int n){
  priority_queue<pii,vector<pii>,greater<pii>> q;
  q.push(pii(cost.at(frm),frm));
  vector<bool> kakutei(n,false);
  while(!q.empty()){
    pii now = q.top();
    q.pop();
    int n1,n2;
    tie(n1,n2) = now;
    if(kakutei.at(n2))continue;
    kakutei.at(n2) = true;
    for(auto t:g.at(n2)){
      int tx,ty;
      tie(tx,ty) = t;
      if(cost.at(tx) > n1 + ty){
        cost.at(tx) = n1 + ty;
        q.push(pii(cost.at(tx),tx));
      }
    }
  }
}

int main(){
  long long a;
  cin >> a;
  double b;
  cin >> b;
  long long bb;
  for(int i=0;i<=1000;i++){
    if(abs(b*100-i) < 0.1){
      bb = i;
    }
  }
  long long c = a * bb / 100;
  cout << c << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    string s;
    cin >> s;
    int ans = 0;
    rep(i,3){
        if(s.at(i) == 'R') ans++;
    }
    if (ans == 1) cout << ans << endl;
    else if(ans == 2 && s.at(1) != 'R') cout << 1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
int main(){

    int h,a;
    cin>>h>>a;
    int temp=h/a;
    if(h-temp*a>0) temp++;
    cout<<temp<<endl;
    
}

Measured memory_bytes: 256
x, y = (int(_) for _ in input().split())
mon = {1:3, 2:2, 3:1}
if x == 1 and y == 1:
    print((3 + 3 + 4)*10**5)
elif x < 4 and y < 4:
    print((mon[x] + mon[y])*10**5)
elif x < 4:
    print(mon[x]*10**5)
elif y < 4:
    print(mon[y]*10**5)
else:
    print(0)
    

Measured memory_bytes: 3060
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [0]+[int(x) for x in input().split()]

count = sum(a)
p = n-1
ans = 0
judge = True
for i in range(m+1):
  flag = False
  count += b[i]
  while count > k and judge:
    count -= a[p]
    p -= 1
    if p == -1:
      if count > k:
        flag = True
      else:
        judge = False
      break
  if count > k:
    break
  if flag:
    break
  sub = p+1+i
  if ans < sub:
    ans = sub
print(ans)
  
  

Measured memory_bytes: 111944
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, u[200005] = {}, v[200005] = {}, w[200005] = {}, o = 0, d[500005] = {};
    vector<pii> g[500005] = {};
    map<pii, int> p;
    deque<int> q;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) p[{i, 0}] = ++o;
    for (int i = 1; i <= m; i++) cin >> u[i] >> v[i] >> w[i], p[{u[i], w[i]}] = ++o, p[{v[i], w[i]}] = ++o, g[o].push_back({v[i], 0}), g[u[i]].push_back({p[{u[i], w[i]}], 1}), g[v[i]].push_back({p[{v[i], w[i]}], 1}), g[p[{u[i], w[i]}]].push_back({u[i], 0}), g[p[{v[i], w[i]}]].push_back({v[i], 0});
    for (int i = 1; i <= m; i++) g[p[{u[i], w[i]}]].push_back({p[{v[i], w[i]}], 0}), g[p[{v[i], w[i]}]].push_back({p[{u[i], w[i]}], 0});
    for (int i = 1; i <= o; i++) {
        //cout << i << ' ';
        //for (pii j : g[i]) cout << j.first << ',' << j.second << ' '; cout << '\n';
    }
    q.push_back(1);
    for (int i = 1; i <= o; i++) d[i] = 890328;
    d[1] = 1;
    while (!q.empty()) {
        int x = q.front();
        q.pop_front();
        for (pii i : g[x]) {
            if (d[x] + i.second < d[i.first]) {
                if (i.second) d[i.first] = d[x] + 1, q.push_back(i.first);
                else d[i.first] = d[x], q.push_front(i.first);
            }
        }
        //for (int i = 1; i <= o; i++) cout << d[i]; cout << '\n';
    }
    if (d[n] == 890328) cout << -1;
    else cout << d[n] - 1;
}


Measured memory_bytes: 73088
local S={}
S["a"]=io.read()
S["b"]=io.read()
S["c"]=io.read()

local discard="a"
while true do
    if S[discard]=="" then
        print(discard:upper())
        break
    end
    discard,S[discard]=S[discard]:sub(1,1),S[discard]:sub(2)
end

Measured memory_bytes: 256
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
B = [[0 for i in range(3)] for j in range(3)]
for i in range(N):
  a = int(input())
  for m in range(3):
    for n in range(3):
      if a == A[m][n]:
        B[m][n] = 1
p = 'No'
for i in range(3):
  cnt1 = 0
  cnt2 = 0
  for j in range(3):
    if B[i][j] == 1:
      cnt1 += 1
    if B[j][i] == 1:
      cnt2 += 1
  if cnt1 == 3 or cnt2 == 3:
    p = 'Yes'
    break
cnt3, cnt4 = 0, 0
for i in range(3):
  if B[i][i] == 1:
    cnt3 += 1
  if B[i][2-i] == 1:
    cnt4 += 1
if cnt3 == 3 or cnt4 == 3:
  p = 'Yes'
print(p)



Measured memory_bytes: 3064
package main

import (
	"fmt"
	"os"
)

func main() {
	var s string
	fmt.Scan(&s)

	m := make(map[byte]int)

	for i := 0; i < len(s); i++ {
		m[s[i]]++
	}

	if len(m) == 2 {
		for _, value := range m {
			if value != 2 {
				fmt.Println("No")
				os.Exit(0)
			}
		}
		fmt.Println("Yes")
		os.Exit(0)
	}

	fmt.Println("No")
}

Measured memory_bytes: 512
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(" ");
        int n = Integer.parseInt(s1[0]);
        int d = Integer.parseInt(s1[1]);


        int result=n/(2 * d + 1);

        if (n % (2*d+1) == 0) {
        	result=n/(2 * d + 1);
        } else {
        	result=n/(2 * d + 1) +1;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 20820
#n = int(input())
n,k = map(int,input().split())
p_L = list(map(int,input().split()))

mydata = []

kazu = list(range(1,1001))
for i in p_L:

    kitai = sum(kazu[0:i])/i
    mydata.append(kitai)

res = [0] * (n+1)

res[0] = mydata[0]
for i in range(len(mydata)-1):
    res[i+1] = res[i] + mydata[i+1]

# print(mydata)
# print(res)
# print("----")
ans = 0
for i in range(n):
    tmp = res[i] - res[i-k]
    ans = max(ans,tmp)
    #print(mydata[i:i+k])
print(ans)

Measured memory_bytes: 86024
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int d[1010][1010];

void init() {
  rep(i, 1010) rep(j, 1010) d[i][j] = inf;
}

int h, w;
char a[1010][1010];

void bfs() {
  queue<pair<int, int>> q;
  rep(i, h) {
    rep(j, w) {
      if (a[i][j] == '#') {
        d[i][j] = 0;
        q.push({i, j});
      }
    }
  }
  while (!q.empty()) {
    int y = q.front().first, x = q.front().second;
    q.pop();
    rep(k, 4) {
      int ry = y + dy[k], rx = x + dx[k];
      if (ry < 0 || ry >= h || rx < 0 || rx >= w) continue;
      if (chmin(d[ry][rx], d[y][x] + 1)) {
        q.push({ry, rx});
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  init();

  cin >> h >> w;
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }

  bfs();
  int ans = 0;
  rep(i, h) rep(j, w) chmax(ans, d[i][j]);
  cout << ans << '\n';




  
  return 0;
}

Measured memory_bytes: 13456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int>v(n,0);
  for(int i=0;i<n;i++){
    for(;;){
      if(a[i]%2==1) break;
      if(a[i]%2==0) v.at(i)++;
      a[i]/=2;
    }
  }
  int sum=0;
  for(int i=0;i<n;i++) sum+=v.at(i);
  cout<<sum<<endl;
}

Measured memory_bytes: 384
#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()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

//素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= n; i++) {
        if(n % i != 0) continue;
        ll ex = 0;

        while(n % i == 0) {
            ex++;
            n /= i;
        }

        res.push_back({i, ex});
    }

    if(n != 1) res.push_back({n, 1});
    return res;
}
//const auto &res = prime_factorize(n);

const ll MOD = 1e9 + 7;

//二項係数 nCk mod p
//aのp乗を求める
ll modpow(ll a, ll p) {
   if(p == 0) return 1;
   if(p % 2 == 0) {
      ll halfP = p / 2;
      ll half = modpow(a, halfP);
      //a^(p/2)をhalfとして、half*halfを計算
      return half * half % MOD;
   } else {
      //pが奇数のときは偶数にするために1減らす
      return a * modpow(a, p-1) % MOD;
   }
}
//二項係数の計算
//10C3 (10*9*8) / (3*2*1)
//(10*9*8):ansMul (3*2*1):ansDiv
ll calcComb(ll a, ll b) {
   if(b > a - b) return calcComb(a, a - b);

   ll ansMul = 1;
   ll ansDiv = 1;
   rep(i, b) {
       ansMul *= (a - i);
       ansDiv *= (i + 1);
       ansMul %= MOD;
       ansDiv %= MOD;
   }
   //ansMul / ansDiv をしたい
   //ansDivの逆元を求める
   ll ans = ansMul * modpow(ansDiv, MOD - 2) % MOD;

   return ans;
}

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

    const auto &res = prime_factorize(m);
    ll ans = 1;
    for(auto p : res) {
        ll tmp = calcComb(p.second + n - 1, n - 1);
        ans = (ans * tmp) % MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
ga=math.radians(90-30*(h+m/60))
gb=math.radians(90-6*m)
xa=a*math.cos(ga)
ya=a*math.sin(ga)
xb=b*math.cos(gb)
yb=b*math.sin(gb)
print(math.sqrt((xa-xb)**2+(ya-yb)**2))

Measured memory_bytes: 9516
import java.util.Scanner;

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

		int cnt = 0;
		for(int i = a; i <= b; i++) {
			int num = i;
			int dig1 = num % 10;
			int dig2 = (num / 10) % 10;
			int dig4 = (num / 1000) % 10;
			int dig5 = num / 10000;
			if( dig1 == dig5 && dig2 == dig4)
				cnt++;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
long long factorial(long long n){
    long long ans=1;
    long long m = n;
    while(m!=0){
        ans *= m;
        ans = ans%1000000007;
        m = m-1;
    }
    return ans;
}
int main(){
    int n,m;
    cin >> n >> m;
    long long ans;
    if(abs(n-m) >1){
        ans = 0;
    }
    else if(abs(n-m) == 1){
        ans = (factorial(n)*factorial(m))%1000000007;
    }
    else{
        ans = (factorial(n)*factorial(m)*2)%1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ull = unsigned long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vull = vector<ull>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    int A,B,C,X,Y,xym=0,cnt=0;
    cin >>A>>B>>C>>X>>Y;
    
    if(X<Y) xym=1;
    
    if(A+B>C+C) {
        cnt+=(C*2*min(X,Y));
    }
    if(A+B<=C+C) {
        cnt+=((A+B)*min(X,Y));
    }
    if(xym==0) cnt+=min(A,C*2)*(X-Y);
    if(xym==1) cnt+=min(B,C*2)*(Y-X);
    cout <<cnt;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<P,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll C[100005]={};

vector<P> v;
vector<ll> ma2;

ll ma[100005]={};
ll a[100005]={},b[100005]={};
bool c[100005]={};
ll n,k;
ll t[100005],d[100005],z=0;
int main() {
	cin>>n>>k;
	rep(i,0,n){
		cin>>t[i]>>d[i];
		if(t[i]>z)z=t[i];
		ma[t[i]-1]=max(ma[t[i]-1],d[i]);
	}
	rep(i,0,n){
		if(c[t[i]-1]||ma[t[i]-1]!=d[i])v.push_back(P(d[i],t[i]));
		else c[t[i]-1]=true;
	}
	ll x=z;
//	cout<<z<<endl;
	rep(i,0,z){
		if(ma[i]!=0)ma2.push_back(ma[i]);
		else x--;
	}
	z=x;
	sort(ma2.rbegin(),ma2.rend());
	sort(v.rbegin(),v.rend());
	for(int i=1;i<=v.size();++i){
		a[i]=a[i-1]+v[i-1].first;
	}
	rep(i,1,z+1){
		b[i]=b[i-1]+ma2[i-1];
	}
	ll ans=0;
	rep(i,1,z+1){
		if(i>k)break;
		if(k-i>v.size())continue;
		ll g=0;
		g+=i*i;
		g+=a[k-i];

		g+=b[i];
		ans=max(ans,g);
//		cout<<g<<" "<<a[k-c[i]]<<" "<<b[i]<<" "<<c[i]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6004
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
if X>=Y:
    print("War")
    exit()
for Z in range(X,Y):
    if max(x)<=Z<min(y):
        print("No War")
        exit()
print("War")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
 
int main(){
	int N;
  	cin>>N;
  int x[200001];
  	rep(i,N)cin>>x[i];
  	int count;
  int j=1;
 	rep(i,N){
    	if(x[i]!=j){
        count++;
        }
      else{
      	j++;
      }
      
    }
  if(j==1){cout<<-1<<endl;}
  else{cout<<count<<endl;}
  
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int x = atoi(s.substr(5,2).c_str());
  if(x<=4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline

def main():
    N = int(input())
    X = list(map(int, input().split()))
    Y = X.copy()
    Y.sort()
    m1 = Y[N//2-1]
    m2 = Y[N//2]
    for x in X:
        if x <= m1:
            print(m2)
        elif x >= m2:
            print(m1)

if __name__ == '__main__':
    main()


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

int main() {
  long n,t,a,ans=1;
  cin >> n >> t >> a;
  vector<long double> h(n);
  for(long i=0;i<n;i++) cin >> h[i];

  for(long i=1;i<n;i++) {
    if(fabs(t-a-(h[ans-1]*0.006))>fabs(t-a-(h[i]*0.006))) ans=i+1;
  }

  cout << ans << endl;
}

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

using ll=long long;

ll n;
vector<ll> a(3300);
ll dp[3300][3300];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  rep(i,n) cin >> a[i];

  for(int width = 1; width <= n; width++){
    for(int l = 0; l + width <= n; l++){
      ll r = l + width;
      if(width%2 == n%2) dp[l][r] = max(dp[l+1][r]+a[l], dp[l][r-1]+a[r-1]);
      else dp[l][r] = min(dp[l+1][r]-a[l], dp[l][r-1]-a[r-1]);
    }
  }
  cout << dp[0][n] << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
int N;
	cin >> N;
	
	for (int i = 1; i <= N;i++) {
		if (i*(i+1)/2>=N) {
			int miss = i * (i + 1) / 2 - N;
			for (int x = 1; x <= i;x++) {
				if (x!=miss) {
					ce(x)
				}
			}
			return 0;
		}
	}
    return 0;
}



Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,d=0,x=0,y=0,z=0;
  double c = 0;
  string s="",t="";
  //

  // ここから
  IN(n);
  OUT(3*n*n);
}


Measured memory_bytes: 256
mod stdin_reader {
  use std::io::stdin;
  use std::io::Read;

  pub struct StdinReader {
    pub buf: Vec<String>,
    pub cursor: usize,
  }

  pub fn new() -> StdinReader {
    StdinReader::new()
  }

  impl StdinReader {
    pub fn new() -> Self {
      let mut s = String::new();
      let stdin = stdin();
      stdin.lock().read_to_string(&mut s).unwrap();
      let buf = s.split_whitespace().map(|s| s.to_string()).collect();
      return StdinReader { buf: buf, cursor: 0 }
    }

    pub fn read_all(&self) -> Vec<String> {
      return self.buf.clone()
    }

    pub fn next(&mut self) -> Option<String> {
      let val = self.buf.get(self.cursor).cloned();
      self.cursor += 1;
      return val
    }

    pub fn as_i64(&mut self) -> Option<i64> {
      self.next().and_then(|s| s.parse::<i64>().ok())
    }

    pub fn as_f64(&mut self) -> Option<f64> {
      self.next().and_then(|s| s.parse::<f64>().ok())
    }

    pub fn as_usize(&mut self) -> Option<usize> {
      self.next().and_then(|s| s.parse::<usize>().ok())
    }
  }
}

mod utils {
  pub fn is_int(n: f64) -> bool {
    let trunc = (n.trunc() as i64) as f64;
    return (n - trunc) < 0.0001
  }
}

fn main() {
  // stdout
  use std::io::{stdout, Write, BufWriter};
  let stdout = stdout();
  let mut writer = BufWriter::new(stdout.lock());

  // stdin
  let mut reader = stdin_reader::new();

  let n = reader.as_usize().unwrap();
  let a_list: Vec<i64> = (0..n).map(|_| reader.as_i64().unwrap()).collect();
  let sum: i64 = a_list.iter().sum();
  let even_a_sum: i64 = a_list.iter().enumerate().filter(|&(i, val)| (i+1) % 2 == 0).map(|(i, val)| val).sum();
  let mut x: i64 = sum - 2 * even_a_sum;
  let mut result = format!("{}", x);

  for i in 0..(n-1) {
    x = 2 * a_list[i] - x;
    result.push_str(&format!(" {}", x));
  }

  writeln!(writer, "{}", result);
}

Measured memory_bytes: 12632
//#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MAXVAL = 400;

int dp[1 + MAXVAL][1 + MAXVAL];

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        for (int i = MAXVAL - a; i >= 0; i--)
            for (int j = MAXVAL - b; j >= 0; j--)
                if (dp[i][j] != -1 && (dp[i + a][j + b] == -1 || dp[i + a][j + b] > dp[i][j] + c))
                    dp[i + a][j + b] = dp[i][j] + c;
    }
    int answer = -1;
    for (int i = 1; i <= MAXVAL; i++)
        for (int j = 1; j <= MAXVAL; j++)
            if (dp[i][j] != -1 && i * mb == j * ma && (answer == -1 || dp[i][j] < answer))
                answer = dp[i][j];
    cout << answer << "\n";
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

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

    ll N;
    cin >> N;
    ll A[N];
    rep(i, 0, N) cin >> A[i];
    sort(A, A + N);

    ll rsl = 1e18;
    rep(i, 1, N) {
        rsl = min(rsl, gcd(A[i], A[0]));
    }
    cout << rsl << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define SZ(x) ((int)(x).size())
#define TC(tc) while (tc--)
#define VI vector<int>
#define PII pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;
const ull num = 1e18;

int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int x, n; cin >> x >> n;
	unordered_set<int> us;
	FOR(i, 0, n)
	{
		int a; cin >> a;
		us.insert(a);
	}
	int mn = x, mx = x;
	while (1)
	{
		if (us.find(mn) == us.end()) { cout << mn; break; }
		if (us.find(mx) == us.end()) { cout << mx; break; }
		mn--;
		mx++;
	}
	return 0;
}

Measured memory_bytes: 3668