akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;

int main(){
    int N;
    cin >>N;
    if(N==2)  cout <<0.5<<endl<<0.5<<endl;
    else{
    vl x(N),y(N);
    rep(i,N) cin >>x[i]>>y[i];
    rep(i,N){
        vector<double>  angle,dangle;
        rep(j,N){
            if(i==j) continue;
            angle.PB(atan2(y[j]-y[i],x[j]-x[i]));      
        }
        sort(all(angle));

        rep(i,N-2){
            dangle.PB(angle[i+1]-angle[i]);
        }
        dangle.PB(angle[0]+2*M_PI-angle[N-2]);
        double M = *max_element(all(dangle))/(2*M_PI)-0.5;
        double zero=0;
        cout << fixed<<setprecision(10)<<max (M,zero) <<endl;
    }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
bool f[100];

int main(){
	REP(i, 28){
		cin >> n;
		f[n] = 1;
	}
	for (int i = 1; i < 31; i++){
		if (!f[i])cout << i << endl;
	}
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

int main() {
	string s, t;
	cin >> s >> t;
	rep(i, s.size()) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3560
(function main() {
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n1 = Number(lines.shift());
  const arr1 = lines.shift().split(' ').map(Number);
  const n2 = Number(lines.shift());
  const arr2 = lines.shift().split(' ').map(Number);

  const solve = (i, m) => {
    if (m == 0) return true;
    if (i >= n1) return false;
    return solve(i + 1, m) || solve(i + 1, m - arr1[i]);
  };

  arr2.map(m => solve(0, m) ? 'yes' : 'no').forEach(res => console.log(res));
})();



Measured memory_bytes: 16932
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int s = (100 * (N - M) + 1900 * M) * (int) Math.pow(2, M);
		System.out.println(s);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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


int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    unordered_map<ll, ll> mp;
    rep(i, n){
        cin >> a[i];
        if (mp.find(a[i]) != mp.end()){
            mp[a[i]] += 1;
        }else{
            mp[a[i]] = 1;
        }
    }

    ll ans=0;
    for(auto x: mp){
        if (x.second % 2 == 1){
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}


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

int main(){
  int n;cin>>n;
  int mat[n][3],m[n][3];
  for (int i=0;i<n;i++){
      cin>>mat[i][0];cin>>mat[i][1];cin>>mat[i][2];}
  m[0][0]=mat[0][0];m[0][1]=mat[0][1];m[0][2]=mat[0][2];
  for (int i=1;i<n;i++){
    m[i][0]=mat[i][0]+max(m[i-1][1],m[i-1][2]);
    m[i][1]=mat[i][1]+max(m[i-1][0],m[i-1][2]);
    m[i][2]=mat[i][2]+max(m[i-1][0],m[i-1][1]); 
  }
    
  int mi=INT_MIN;
  for (int i=0;i<3;i++)
    mi=max(mi,m[n-1][i]);
  cout<<mi<<endl;
 
 return 0; 
}

Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int main() {
	ll N, W;
	cin >> N >> W;
	vector<vector<ll>> v(4);
	ll w0, v0;
	cin >> w0 >> v0;
	v[0].push_back(v0);
	for (ll i = 1; i < N; i++) {
		ll a, b;
		cin >> a >> b;
		v[a - w0].push_back(b);
	}

	for (ll i = 0; i < 4; i++) sort(RALL(v[i]));

	vector<vector<ll>> sum(4);
	for (ll i = 0; i < 4; i++) sum[i].push_back(0);

	ll ans = 0;
	for (ll i = 0; i < 4; i++) {
		for (ll j = 0; j < (ll)v[i].size(); j++) sum[i].push_back(sum[i][j] + v[i][j]);
	}

	for (ll i = 0; i <= (ll)v[0].size(); i++) {
		for (ll j = 0; j <= (ll)v[1].size(); j++) {
			for (ll k = 0; k <= (ll)v[2].size(); k++) {
				for (ll l = 0; l <= (ll)v[3].size(); l++) {
					ll tmp_w = i*w0 + j*(w0+1)+ k*(w0+2) + l*(w0+3);
					if (tmp_w <= W) ans = max(ans, sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);
				}
			}
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

template<int MAX_V>
class SCC {
  vector<int> G[MAX_V];
  vector<int> rG[MAX_V];
  vector<int> vs;
  bool used[MAX_V];

  int V;
  vector<int> cmp;

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

  void rdfs(int v, int k){
    used[v] = true;
    cmp[v] = k;
    for(int i=0; i<rG[v].size(); i++)
      if(!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
public:
  //SCC(int V):V(V),cmp(V){}
  SCC():V(MAX_V),cmp(MAX_V){}
  
  void set_V(int V_){ V = V_; }
  
  int size(){ return V; }

  vector<int> get_edge(int from){ return G[from]; }
  vector<int> get_cmp(){ return cmp; }

  void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
  }

  int calc(){
    for(int i=0; i<MAX_V; i++) used[i] = 0;
    vs.clear();
    for(int v=0; v<V; v++)
      if(!used[v]) dfs(v);
    for(int i=0; i<MAX_V; i++) used[i] = 0;
    int k = 0;
    for(int i=vs.size()-1; i>=0; i--)
      if(!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }

  vector<int> depth(){
    vector<pair<int,int>> order;
    vector<int> dp(V, 1);

    int res = calc();
    if(res != V) return vector<int>();

    for(int i=0; i<V; i++){
      order.push_back(make_pair(cmp[i],i));
    }
    sort(order.begin(), order.end());

    for(int i=0; i<V; i++){
      int node = order[i].second;
      rep(j,G[node].size()){
        dp[G[node][j]] = max(dp[G[node][j]], dp[node]+1);
      }
    }
    return dp;
  }
};

SCC<1000005> scc;

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

  scc.set_V(N*N);
  
  rep(i,N){
    vector<int> v;
    rep(j,N-1){
      int a;
      cin >> a;
      a--;
      v.push_back(a);
    }
    rep(j,v.size()-1){
      int x = i;
      int y = v[j];
      int z = v[j+1];

      int a = min(x,y) * N + max(x,y);
      int b = min(x,z) * N + max(x,z);

      scc.add_edge(a,b);
      
    }
  }

  int mx = 0;
  vector<int> ret = scc.depth();

  if(ret.size() == 0){
    cout << -1 << endl;
    return 0;
  }
  
  rep(i,ret.size()){
    mx = max(mx, ret[i]);
  }
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 100992
public class Main {

  private static void solve() {

    int s = ni();
    int w = ni();

    if (s <= w) {
      System.out.println("unsafe");
    } else {
      System.out.println("safe");
    }

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

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

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 36692
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <ctype.h>

int n,i,j,p,answer;

int main(){
    char p[250000];
    for(i=2;i<250000;i++){
        p[i]=1;}
    p[0]=p[1]=0;
    
    for(i=2;i*i<=250000;i++){
        if(p[i]==1){
            for(j= i*2;j<=250000;j+=i){
                p[j] = 0;
            }
        }
    }
    
    
    
    

    while(1){
        answer=0;
        scanf("%d", &n);
        if(n==0)break;
        
        for(i=n+1;i<=n*2;i++){
            answer+=p[i];
        }
        printf("%d\n",answer);
        
    }
    return 0 ;
}



Measured memory_bytes: 2852
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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 (b<a) { a=b; return 1; } return 0; }

int main(){
    string S; cin >> S;
    int n = S.size();
    vector<int> s(n);
    rep(i,n) s[i] = S[i] - '0';
    vector<int> pow(n+1);
    pow[0] = 1;
    rep(i,n){
        pow[i+1] = (pow[i]*10) % 2019;
    }
    vector<int> num(n+1);
    rrep(i,n) {
        num[i] = (num[i+1] + pow[n-i-1]*s[i]) % 2019;
    }
    vector<ll> cnt(2019);
    rep(i,n+1) {
        cnt[num[i]]++;
    }
    ll ans = 0;
    rep(i,2019){
        ll k = cnt[i];
        ans += k*(k-1)/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5892
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N; 
  cin >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  vector<int> o(N);
  iota(ALL(o), 0);

  sort(ALL(o), [&](int const & l, int const & r){
      return A[l] < A[r];
      });


  set<int> s;
  s.insert(-1);
  s.insert(N);

  int ans = 0;
  REP(i, N){
    int I = o[i];
    auto it = s.upper_bound(I);
    int r = *it;
    it--;
    int l = *it;

    ans += A[I]*(I-l)*(r-I);
    s.insert(I);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 12800
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a > mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int k,c;
	cin>>k>>c;
	string s;
	cin>>s;
	vi a(k);
	vi b(k);
	int inf = 1e9;
	int pos = 0;
	int last = -1*inf;
	rep(i,n){
		if(pos == k)break;
		if(s[i] == 'o' && i > last + c){
			last = i;
			a[pos] = i;
			pos++;
		}
	}
	pos = k-1;
	last = inf;
	repr(i,n){
		if(pos == -1)break;
		if(s[i] == 'o' && i < last - c){
			last = i;
			b[pos] = i;
			pos--;
		}
	}
	rep(i,k){
		//cout<<a[i]<<" "<<b[i]<<"\n";
		if(a[i] == b[i]){
			cout<<a[i]+1<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3348
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,f,k;
    int e[2];
    cin>>a>>b>>c>>k;
     d=max(a,b);
     e[0] =max(c,d);
     e[1]=e[0];
   for(int i=0;i<k;i++)
   {
      
     e[1]=e[1]*2;
   }
   int q=a+b+c;
   cout<<q-e[0]+e[1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

ll A[100];

pair<ll,ll> moneyfirst(pair<ll,ll> p,pair<ll,ll> q){
   if(p.first > q.first) return p;
   else if (q.first > p.first) return q;
   else if(p.second > q.second) return p;
   else if(q.second > p.second) return q;

   return p;
}

pair<ll,ll> stockfirst(pair<ll,ll> p,pair<ll,ll> q){
   if(p.second > q.second) return p;
   else if (q.second > p.second) return q;
   else if(p.first > q.first) return p;
   else if(q.first > p.first) return q;

   return p;
}
 
int main(){
   ll N;
   cin >> N;
   rep(i,N) cin >> A[i];
   pair<ll,ll> money,stock;
   money = make_pair(1000,0);
   stock = make_pair(1000,0);
   rep(i,N){
      pair<ll,ll> M = money,S = stock;
      money = moneyfirst(M,make_pair(S.first + S.second * A[i],0));
      stock = stockfirst(S,make_pair(M.first % A[i],M.first / A[i]));
   }
   cout << max(money.first,stock.first + stock.second * A[N-1]) << endl;
}

Measured memory_bytes: 3616
n = int(input())
a = list(map(int, input().split()))

d = [0]*(int(n/2)) + a[int(n/2):]

for i in range(int(n/2), 0, -1):
    i_sum = sum(d[i-1::i])
    if a[i-1] == 1 and i_sum%2 == 0:
        d[i-1] = 1
    elif a[i-1] == 0 and i_sum%2 == 1:
        d[i-1] = 1

m = d.count(1)
print(m)
if m != 0:
    print(*[i+1 for i in range(n) if d[i] == 1])

Measured memory_bytes: 14420
#include<bits/stdc++.h>
using namespace std;
main(){
  int N;
  cin>>N;
  auto A=vector<int>(N);
  for(auto&x:A)cin>>x;
  int n_max=-1;
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      if(i==j)continue;
      const int difference=abs(A[i]-A[j]);
      n_max=max(n_max,difference);
    }
  }
  cout<<n_max<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define max_v(v) *max_element(all(v));
#define min_v(v) *min_element(all(v));
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl
template <typename T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}
template<typename T> ostream& operator << (ostream& os, vector<T>& vec) {
    for(int i = 0; i < vec.size(); i++) {
        os << vec.at(i) << (i + 1 == vec.size() ? "" : " ");
    }
    return os;
}

int main() {
    int L, R, D;
    cin >> L >> R >> D;
    
    int cnt = 0;
    repi(i, L, R + 1) {
        if(i % D == 0) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3588
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;
int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

int H, W;
int dp[303][303];
vector<int>v[2][303];
int calc(string &S, string &T) {
	REP(i, 2)REP(j, H)v[i][j].clear();
	REP(i, H) {
		FOR(j, i, H) {
			if (S[i] == T[j]) {
				v[0][j - i].push_back(H - i - 1);
			}
		}
	}
	REP(j, H) {
		FOR(i, j, H) {
			if (T[j] == S[i]) {
				v[1][i - j].push_back(H - j - 1);
			}
		}
	}
	REP(i, H) {
		VSORT(v[0][i]);
		VSORT(v[1][i]);
	}
	REP(i, H + 1) {
		REP(j, H + 1)dp[i][j] = INF;
	}
	dp[0][0] = 0;
	REP(i, H + 1)REP(j, H + 1) {
		if (i >= j) {
			int cnt = 0;
			int M = v[0][i - j].size();
			cnt = v[0][i - j].end() - lb(v[0][i - j], i);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt);
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt);
		}
		else {
			int cnt = 0;
			cnt = v[1][j - i].end() - lb(v[1][j - i], j);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cnt);
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cnt);
		}
	}
	return dp[H][H];
}
char C[303][303];
string S[303];
void solve() {
	cin >> H >> W;
	REP(i, H)REP(j, W) {
		cin >> C[i][j];
		S[j] += C[i][j];
	}
	ll ans = 0;
	REP(j, W - 1) {
		//print(calc(S[j], S[j + 1]));
		ans += calc(S[j], S[j + 1]);
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #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); } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int A, B;
	cin >> A >> B;
	cout << A * B << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

typedef long long ll;
using namespace std;

int main() {
    int n, p;
    cin >> n >> p;
    ll odd = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2)
            odd++;
    }
    if (odd == 0) {
        if (p) {
            cout << 0;
        } else {
            cout << (ll)pow(2, n);
        }
    } else {
        cout << (ll)pow(2, n - 1);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<vector>
#include<string>
#include<algorithm>
#include<bitset>
typedef long long ll;

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define MOD 1000000007;
using namespace std;
ll n;
int main(){
    cin>>n;
    ll ans=0;
    rep(i,1,n+1){
        if(i%3!=0&&i%5!=0)ans+=i;
    }
    puts(ans);
}



Measured memory_bytes: 3588
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    FAST_IO
    
    ll a,b,h;
    cin >> a >> b >> h;

    cout << ((a+b) * h)/2 << endl;
    return 0;
}

Measured memory_bytes: 3160
#include<iostream>
using namespace std;
int main () {
  int N;
  cin >> N;
  int sum = 0;
  int max = 0;
  for (int i = 0; i < N; i ++) {
    int k;
    cin >> k;
    sum += k;
    if (max < k) max = k;
  }
  max *= 2;
  if (max < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll long long
#define endl '\n'
#define pi 3.14159265
ll n,m;
vector<ll> v[200000];
ll vis[200000]={0};
ll dp[200000]={0};
void dfs(ll node)
{
    vis[node]=1;
    for(ll i=0;i<v[node].size();i++)
    {
        if(vis[v[node][i]]==0)
            dfs(v[node][i]);
        dp[node]=max(dp[node],dp[v[node][i]]+1);
    }
}
int main()
{
    IOS;
    cin>>n>>m;
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        v[x].push_back(y);
    }
    for(ll i=1;i<=n;i++)
    {
        if(vis[i]==0)
            dfs(i);
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
        ans=max(ans,dp[i]);
    cout<<ans;
}

Measured memory_bytes: 12416
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int T = 1;
        int n,k,res;
        String s1;
        while(T-->0){
            res=1;
            s1=s.next();
            long sum=0;
            for(int i=0;i<s1.length();i++){
                sum+=Character.getNumericValue(s1.charAt(i));
            }
            if(sum%9!=0)
                res=0;
            if(res==1)
                System.out.println("Yes");
            else
                System.out.println("No");
        }



    }
    static int gcd(int a, int b)
    {
        if(b==0) {
            return a;
        }
        return gcd(b,a%b);
    }
    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 31292
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
bool sortbysecdesc(const pair<string,ll> &a,const pair<string,ll> &b)
{
       return a.second>b.second;
}
int main() {
	int res=1,n;
	string s;
	cin>>n>>s;
	loop(n,i,1){
		if(s[i]!=s[i-1])res++;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
#define N 100005
#define ll long long
#define MOD 1000000007
ll x,y;
map<ll,bool> vis;
ll p[N];
int pn;
ll gcd(ll a,ll b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main()
{
	scanf("%lld %lld",&x,&y);
	ll d=gcd(x,y);
	int ans=1;
	if(d%2==0) ans++;
	while(d%2==0)
		d/=2;
	for(int i=3;i<=d/i;i+=2)
		if(d%i==0)
		{
			ans++;
			while(d%i==0)
				d/=i;
		}
	if(d!=1) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;


int main()
{
    int x1,x2,y1,y2,x3,x4,y3,y4;
    cin>>x1>>y1>>x2>>y2;
    pair<int,int> vec;
    vec.first=x2-x1;
    vec.second=y2-y1;
    x4=x1-vec.second;
    y4=vec.first+y1;
    x3=x2-(x1-x4);
    y3=y2-(y1-y4);
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
//#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define FOR(i, s, e) for (ll i = ll(s); i < ll(e); ++i)
#define REP(i, e) FOR(i, 0, e)
//#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
#define AST(exp, msg) if(!(exp)){EPR((msg))} assert((exp));
#define TAST(exp, msg) if(!(exp)){EPR((msg))} while(!(exp)){}
#define EPR(msg) cerr << (msg) << endl;
using namespace std;
using ll = long long; using ull = unsigned long long;
//using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>;
using vs = vector<string>;
//using pii = pair<int, int>; 
using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  string S; cin>>S;

  string ans = "No";
  if (S[2]==S[3] && S[4]==S[5]) ans = "Yes";

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
int cmp3(T lhs, T rhs) { return (lhs == rhs) ? 0 : (lhs > rhs) ? 1 : -1; }

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

int main() {
  int N; cin >> N;
  lli oc, mt, hw;
  oc = mt = hw = 0;
  REP(i, N) {
    lli A, B, C; cin >> A >> B >> C;
    lli noc = A + max(mt, hw),
        nmt = B + max(oc, hw),
        nhw = C + max(oc, mt);
    oc = noc, mt = nmt, hw = nhw;
  }
  cout << max({oc, mt, hw}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,u,v;
    cin >> N >> u >> v;
    u--;v--;
    vector<vector<int>> t(N);
    REP(i, N-1){
        int A,B;
        cin >> A >> B;
        A--;B--;
        t[A].pb(B);
        t[B].pb(A);
    }

    vector<int> U(N, -1);
    vector<int> V(N, -1);

    queue<int> qu;
    qu.push(u);
    U[u] = 0;
    while(!qu.empty()){
        auto f = qu.front();qu.pop();
        for(auto&& c: t[f]){
            if(U[c] == -1){
                U[c] = U[f]+1;
                qu.push(c);
            }
        }
    }

    queue<int> qv;
    qv.push(v);
    V[v] = 0;
    while(!qv.empty()){
        auto f = qv.front();qv.pop();
        for(auto&& c: t[f]){
            if(V[c] == -1){
                V[c] = V[f]+1;
                qv.push(c);
            }
        }
    }
    
    int ans = 0;
    REP(i, N){
        if(U[i] < V[i]){
            ans = max(ans, V[i]);
        }
    }
    pr(ans-1);
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
const int ms = 1e5+9;
int dp[ms][3], n;
int activity[ms][3];

int solve(int pos, int action){

  if(pos == n)
    return 0;

  int &ans  = dp[pos][action];
  if(~ans) return ans;
  
  ans = 0;

  int next_action = (action + 1) %3;
  int prev_action = (action + 2) %3;

  ans = max(activity[pos][next_action] + solve(pos+1, next_action), activity[pos][prev_action] + solve(pos + 1, prev_action));

  return ans;
}



int main(){

  cin >> n;
  for(int i = 0; i < n ; i++){
    for(int j = 0; j < 3; j++) cin >>activity[i][j];
  }

  memset(dp, -1, sizeof dp);

  int ans = 0;

  for(int i = 0; i < 3; i++){
    ans = max(ans, solve(0, i));
  }

  cout<<ans;


}

Measured memory_bytes: 7296
from collections import defaultdict

class TwoSat:
    def __init__(self, N):
        self.N = N
        self.ans = None
        self.__e = []
        self.__v = list(range(N))

    def add_clause(self, i, f, j, g):
        self.__e.append((2*i + (0 if f else 1), 2*j + (1 if g else 0)))
        self.__e.append((2*j + (0 if g else 1), 2*i + (1 if f else 0)))

    @staticmethod
    def scc(V, E):
        g = defaultdict(list)
        rg = defaultdict(list)
        for u, v in E:
            g[u].append(v)
            rg[v].append(u)

        o = []
        done = set()
        for u in V:
            if u in done:
                continue

            s = [(u, True)]
            while s:
                u, f = s.pop()
                if f:
                    if u in done:
                        continue
                    done.add(u)
                    s.append((u, False))
                    for v in g[u]:
                        if v in done:
                            continue
                        s.append((v, True))
                else:
                    o.append(u)

        done = set()
        ans = []
        while o:
            u = o.pop()
            if u in done:
                continue

            s = [u]
            vv = [u]
            done.add(u)
            while s:
                u = s.pop()
                for v in rg[u]:
                    if v in done:
                        continue
                    vv.append(v)
                    s.append(v)
                    done.add(v)
            ans.append(vv)

        return ans


    def satisfiable(self):
        scc = TwoSat.scc(self.__v, self.__e)
        cid = [-1] * (self.N)

        for i, s in enumerate(scc):
            for v in s:
                cid[v] = i

        for i in range(self.N//2):

            if cid[2*i] == cid[2*i+1]:
                self.ans = None
                return False

        self.ans = []
        for i in range(self.N//2):
            self.ans.append(cid[2*i] < cid[2*i+1])

        return True




def atcoder_practice2_h():
    N, D = map(int, input().split())
    XY = [list(map(int, input().split())) for _ in range(N)]


    ts = TwoSat(2*N)
    for i, (x1, y1) in enumerate(XY):
        for j in range(i+1, N):
            x2, y2 = XY[j]
            if abs(x1 - x2) < D:
                ts.add_clause(i, False, j, False)

            if abs(y1 - y2) < D:
                ts.add_clause(i, True, j, True)

            if abs(x1 - y2) < D:
                ts.add_clause(i, False, j, True)

            if abs(y1 - x2) < D:
                ts.add_clause(i, True, j, False)

    if not ts.satisfiable():
        print('No')
    else:
        print('Yes')
        for i, b in enumerate(ts.ans):
            print(XY[i][0 if b else 1])




if __name__ == "__main__":
    atcoder_practice2_h()


Measured memory_bytes: 71084
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int n,k,c;
string s;
int l[200010];
int r[200010];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k >> c >> s;
	int cnt = 1;
	for(int i = 0;i < n && cnt <= k;i++){
		if(s[i] == 'o'){
			l[i] = cnt++;
			i += c;
		}else{
			continue;
		}
	}
	cnt--;
	for(int i = n - 1;i >= 0 && cnt >= 1;i--){
		if(s[i] == 'o'){
			r[i] = cnt--;
			i -= c;
		}else{
			continue;
		}
	}
	for(int i = 0;i < n;i++){
		if(l[i] != 0 && r[i] != 0 && l[i] == r[i]){
			cout << i + 1 << endl;
		}
	}
	return 0;
}

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

int main(){
  int n,k,s;
  cin >> n >> k >> s;

  
  for (int i = 0; i < k; i++)
  {
    cout << s << " ";
  }

  int out = s+1;
  if(s==1000000000) out = 1;
  for (int i = 0; i < n-k; i++)
  {
    cout << out << " ";
  }
  cout << endl;  
}

Measured memory_bytes: 1280
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	while(true){
	    double x = sc.nextDouble();
	    double h = sc.nextDouble();
	    if(x==h && x==0) break;
	    double l = Math.sqrt((x/2)*(x/2)+h*h);
	    System.out.println(x*x + (x*l/2)*4);
	}
    }
}
			       

Measured memory_bytes: 18556
#include<bits/stdc++.h>
#define ll long long int
ll a[1000000+9];
using namespace std;
int main()
{
    ll n,t,d,i,x=0;
    cin>>n>>t;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }

    for (i=1; i<n; i++)
    {
        d=a[i]-a[i-1];

        if (d<=t)
        {
            x+=d;
        }
        else
        {
            x+=t;
        }
    }
    cout<<x+t<<endl;
    return 0;
}


Measured memory_bytes: 1792
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}

int main()
{
    ios;
    ll n,k;
    cin>>n;
    int a[n];
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]=i;

    }
    map<int,int>::iterator it;
    for(it=m.begin();it!=m.end();it++)
        cout<<it->ss+1<<" ";
    cout<<endl;



}






Measured memory_bytes: 8696
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int inf = 1 << (30);
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int a[MAX_N], b[MAX_N];

  vector<int> G[N];
  int aa, bb;
  REP(i, N - 1) {
    cin >> aa >> bb;
    aa--, bb--;
    a[i] = aa, b[i] = bb;
    G[a[i]].push_back(b[i]);
  }

  vector<bool> visited(N);
  map<int, map<int, bool>> mp;
  map<int, map<int, int>> ans;

  map<int, int> usedColors;
  int colors = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    // if (visited[u]) continue;
    visited[u] = true;
    for (auto v : G[u]) {
      if (visited[v]) continue;
      q.push(v);
      // u - v
      int cidx = inf;
      // find edge color
      for (int i = usedColors[u]; i < N; i++) {
        if (!mp[u][i]) {
          cidx = i;
          colors = max(colors, cidx);
          usedColors[u]++;
          mp[u][i] = true, mp[v][i] = true;
          break;
        }
      }
      ans[u][v] = cidx;
    }
  }

  cout << colors + 1 << endl;
  REP(i, N - 1) { cout << ans[a[i]][b[i]] + 1 << endl; }

  return 0;
}


Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
    int n;
    cin >> n;
    if(n%2 == 1)cout << n/2 << endl;
    else cout << n/2 - 1 << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

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

Measured memory_bytes: 256
def calc(left, right, N):
    def left_match(x):
        return int(str(x)[0]) == left
    def right_match(x):
        return x % 10 == right
    cnt = 0
    n = 1
    while n <= N:
        if not left_match(n):
            length = len(str(n))
            n += 10**(length - 1)
        elif not right_match(n):
            n += 1
        else:
            cnt += 1
            n += 1
    return cnt


def main():
    N = int(input())
    counter = dict()
    for left in range(1, 10):
        for right in range(1, 10):
            counter[(left, right)] = calc(left, right, N)
    answer = 0
    for left in range(1, 10):
        for right in range(1, 10):
            answer += counter[(left, right)] * counter[(right, left)]
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064