akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

bool solve(int n, int a, int b, vector<int>& ans)
{
    vector<int> v(a, 1);
    v[0] = b;
    int m = n - (a + b - 1);
    if(m < 0)
        return false;

    for(int i=1; i<a; ++i){
        int x = min(b - 1, m);
        v[i] += x;
        m -= x;
    }
    if(m > 0)
        return false;

    ans.resize(n);
    for(int i=0; i<n; ++i)
        ans[i] = i + 1;

    int k = 0;
    for(int i=0; i<a; ++i){
        reverse(ans.begin() + k, ans.begin() + k + v[i]);
        k += v[i];
    }
    return true;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    vector<int> v;
    if(solve(n, a, b, v)){
        cout << v[0];
        for(unsigned i=1; i<v.size(); ++i)
            cout << ' ' << v[i];
        cout << endl;
    }
    else{
        cout << -1 << endl;
    }

    return 0;
}


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

using namespace std;

int main() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> pa(a);
	vector<int> pb(b);
	vector<int> pc(c);
	for(int i = 0; i < a; i++)
		cin >> pa[i];
	for(int i = 0; i < b; i++)
		cin >> pb[i];
	for(int i = 0; i < c; i++)
		cin >> pc[i];
	sort(pa.rbegin(), pa.rend());
	sort(pb.rbegin(), pb.rend());
	sort(pc.rbegin(), pc.rend());

	vector<int> v(x+y+c);
	for(int i = 0; i < x; i++)
		v[i] = pa[i];
	for(int i = 0; i < y; i++)
		v[x + i] = pb[i];
	for(int i = 0; i < c; i++)
		v[x+y + i] = pc[i];

	sort(v.rbegin(), v.rend());

	long long ans = 0;
	for(int i = 0; i < x+y; i++) {
		ans += v[i];
	}
	
	cout << ans << "\n";
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n;
    cin >> n;
    long long A[n],X[n],Y[n], minSum;
    for(int i=0;i<n;i++){
       cin >> A[i];
    }
    for(int i=0;i<n;i++){
        if(i==0){
            X[i]=A[i];
            Y[n-1-i]=A[n-1-i];
        }else{
            X[i]=X[i-1]+A[i];
            Y[n-1-i]=Y[n-i]+A[n-1-i];
        }
    }
    for(int i=0;i<n-1;i++){
        if(i==0){
            minSum = abs(X[i]-Y[i+1]);
        }else{
            minSum = min(minSum, abs(X[i]-Y[i+1]));
        }
    }
    cout << minSum << endl;
    return 0;
 
}


Measured memory_bytes: 4992
#include <cstdio>
using namespace std;
typedef unsigned long long ul;
ul n,t,ans;
ul gcd(ul a,ul b){if(b==0) return a;return gcd(b,a%b);}
ul lcm(ul a,ul b){return a/gcd(a,b)*b;}
inline ul read(){
	ul x=0;int w=0;char c=getchar();for(;c<'0'||c>'9';w^=c=='-',c=getchar());for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+(c^48),c=getchar());
	return w?-x:x;
}
int main(){
	n=read(),ans=read();n--;while(n--){t=read();ans=lcm(ans,t);}
	printf("%llu\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static boolean check(double a){
		double b;
		b = Math.sqrt(a);
		if(b>1.0 && b<2.0) return true;

		for(int i=2;i<=(int)Math.floor(b);i++){
			if((a%2.0) == 0.0) return false;
			if((a%(double)i) == 0.0) return false;
		}
		return true;
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int i,c=0,n;
		double tmp;
		n = sc.nextInt();

		for(i=0;i<n;i++){
			tmp = sc.nextDouble();
			if(check(tmp)) c++;
			else continue;
		}
		System.out.println(c);
	}

}


Measured memory_bytes: 65896
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    string hon = "24579";
    if(count(hon.begin(), hon.end(), S.back())) {
        cout << "hon" << endl;
    } 

    string pon = "0168";
    if(count(pon.begin(), pon.end(), S.back())) {
        cout << "pon" << endl;
    } 

    string bon = "3";
    if(count(bon.begin(), bon.end(), S.back())) {
        cout << "bon" << endl;
    } 

}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
  int n,sum,i;
  sum = 0;

  while(1){
    scanf("%d",&n);
    if(n == 0) break;
    for(i=1;i*i <= n;i++){
      if(n % i == 0){
        if(i == 1) sum = 1;
        else if(n == i * i) sum += i;
        else sum += (i+(n / i));
      }
    }
    if(n == 1) sum = 0;
    if(n == sum) printf("perfect number\n");
    if(n > sum) printf("deficient number\n");
    if(n < sum) printf("abundant number\n");
  }

  return 0;
}

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


const int N = 1e6 + 9;
int n, ans = 1, mx, q[N], he = 1, ta, tag;
char s[N], t[N];
deque<int>Q;

int main () {
	scanf("%d", &n);
	scanf("%s%s", s + 1, t + 1);
	if (strcmp(s + 1, t + 1) == 0) return puts("0"), 0;
	for (int i = n, la = 1e9, j = n; i; --i) {
		if (i > 1 && t[i] == t[i - 1]) continue ;
		if (j > i) j = i;
		while (j && s[j] != t[i]) --j;
		if (!j) return puts("-1"), 0;
		--tag; Q.push_front(j - tag);
		while (!Q.empty() && Q.back() + tag >= la)
		Q.pop_back();
//		if (he <= ta && i >= q[ta]) q[ta + 1] = q[ta] - 1, ++ta;
//		ans = j == i ? 0 : ans + 1;
//		if (ans > mx) mx = ans;
		if (Q.size() > mx) mx = Q.size();
		la = i - 1;
	}
	printf("%d\n", mx);
	return 0;
}
/*
8
asdfadsa
aadffdsa
*/

Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn=100005;
int n,mx,mn,a[maxn];
int main() {
	scanf("%d",&n);
	mx=0,mn=n;
	rep(i,1,n) {
		scanf("%d",a+i);
		mx=max(mx,a[i]),mn=min(mn,a[i]);
	}
	if(mx-mn>1) return puts("No"),0;
	if(mx==mn) {
		if(mx==n-1||n%mx==0) puts("Yes");
		else puts("No");
	}
	else {
		int cnt=0;
		rep(i,1,n) cnt+=(a[i]==mn);
		if(n-cnt==1) puts("No");
		else {
			if(cnt+1<=mx&&mx<=cnt+(n-cnt)/2) puts("Yes");
			else puts("No");
		}
	}
	return 0;
}

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

int main() {
    int k, x;
    cin >> k >> x;

    if (500 * k >= x) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ',') cerr << *sdbg++; cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

ll a[100];

int main(){
	ll K;
	scanf("%lld", &K);
	int n = 50;

	fill_n(a, n, n - 1 + K / n);
	int rem = K % n;
	for (int i = 0; i < rem; ++i){
		a[i] += n;
		for (int j = 0; j < n; ++j)
			a[j] -= i != j;
	}
	printf("%d\n", n);
	for (int i = 0; i < n; ++i)
		printf("%lld%c", a[i], "\n "[i + 1 < n]);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int h, w, i, j;
	while (1)
	{
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0) {
			return 0;
		}
		else {
			for (i = 1;i <= h;i++) {
				for (j = 1;j <= w;j++) {
					if (i == 1 || i == h || j == 1 || j == w) {
						printf("#");
					}
					else {
						printf(".");
					}
				}
				printf("\n");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2548
import java.util.*;
public class Main {
		
		public static int gcd(int a, int b) {
			return b == 0 ? a: gcd(b, a % b);
		}

		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] A = new int[N];
			int ans = 0;
			for(int i = 0; i < N; i++)
				A[i] = Integer.parseInt(sc.next());
			int[] L = new int[N+1];
			int[] R = new int[N+1];
			for(int i = 0; i < N; i++)
				L[i+1] = gcd(L[i],A[i]);
			for(int i = N-1; i > 0; i--)
				R[i] = gcd(R[i+1], A[i]);
			for(int i = 0; i < N; i++)
				ans = Math.max(ans, gcd(L[i],R[i+1]));
			System.out.println(ans);
		}

	}


Measured memory_bytes: 47608
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll dp[101][10];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, k;
    cin >> h >> w >> k;
    dp[0][0] = 1;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            for (int k = 0; k < (1 << w - 1); k++)
            {
                bool flg = true;
                for (int l = 0; l < w - 2; l++)
                {
                    if (((k >> l) & 1) && ((k >> (l + 1)) & 1))
                    {
                        flg = false;
                    }
                }
                if (flg)
                {
                    if (j >= 1 && ((k >> (j - 1)) & 1))
                    {
                        (dp[i + 1][j - 1] += dp[i][j]) %= MOD;
                    }
                    else if (j <= w - 2 && ((k >> j) & 1))
                    {
                        (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
                    }
                    else
                    {
                        (dp[i + 1][j] += dp[i][j]) %= MOD;
                    }
                }
            }
        }
    }
    cout << dp[h][k - 1] << endl;
}

Measured memory_bytes: 256
def insert(tree,node):
    parent=None
    child=root
    while child is not None:
        parent=child
        if node<child:child=tree[parent][0]
        else:child=tree[parent][1]
    if node<parent:tree[parent][0]=node
    else:tree[parent][1]=node


def In_order(node):
    if node is None:return
    In_order(tree[node][0])
    print(" {}".format(node), end="")
    In_order(tree[node][1])


def Pre_order(node):
    if node is None:return
    print(" {}".format(node), end="")
    Pre_order(tree[node][0])
    Pre_order(tree[node][1])


n=int(input())
tree,root={},None
for i in range(n):
    order=input().split()
    if order[0]=="print":
        In_order(root);print()
        Pre_order(root);print()
    elif order[0]=="insert":
        num=int(order[1])
        if root is None:
            root=num
            tree[root]=[None,None]
        else:
            tree[num]=[None,None]
            insert(tree,num)


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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) (in).begin(),(in).end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
  int n,l;
  cin >> n >> l;
  vector<string> vec(n);
  REP(i,n)cin >> vec.at(i);
  sort(vec.begin(),vec.end());

  REP(i,n)cout << vec.at(i);
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] sa = s.next().split("");
        String[] sb = s.next().split("");
        String[] sc = s.next().split("");

        int idxA = 0;
        int idxB = 0;
        int idxC = 0;
        String turn = "a";
        while (true) {
            if ("a".equals(turn)) {
                if (idxA == sa.length) {
                    System.out.println("A");
                    return;
                }
                turn = sa[idxA];
                idxA++;
            } else if ("b".equals(turn)) {
                if (idxB == sb.length) {
                    System.out.println("B");
                    return;
                }
                turn = sb[idxB];
                idxB++;
            } else if ("c".equals(turn)) {
                if (idxC == sc.length) {
                    System.out.println("C");
                    return;
                }
                turn = sc[idxC];
                idxC++;
            }
        }
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define pb push_back
#define pc __builtin_popcount
#define pcll __builtin_popcountll
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
using namespace std;
ll n, m, ok, h[500005];
set<ll> k[500005];
int main() {
  speed;
  oprecision;
  // code
  cin >> n >> m;
  forn(n) cin >> h[i];
  forn(m) {
    int u, v;
    cin >> u >> v;
    k[u].insert(h[v]);
    k[v].insert(h[u]);
  }
  forn(n) if (!k[i].size() || *prev(k[i].end()) < h[i]) ok++;
  cout << ok;
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 37216
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
    
        
        long long int n,m,o=0,l,d=1,i,j,p=0,k,f;
       double pie=3.141592653589793238;
    long long int MOD=1000000007;
    cin>>n>>k;
    p=1000000;
    if((-1*1000000)>k-n+1)
    j=-1000000;
    else
    j=k-n+1;
    for(j=j;j<=min(p,k+n-1);j++)
    cout<<j<<" ";
    
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  	int N, Y;
    cin >> N >> Y;

    for(int i=0;i<=N;i++){
      for(int j=0;j<=N-i;j++){
        if(N-i-j<=N && Y-10000*i-5000*j==1000*(N-i-j)){
          cout << i << " " << j << " " << N-i-j <<endl;
          return 0;
        }
      }
    }
    cout << -1 << " " << -1 << " " << -1 <<endl;

  	return 0;
}




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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  auto modpow = [&](long long a, long long b, long long MOD) -> int {
    long long res = 1;
    while (b) {
      if (b & 1) {
        res = (res % MOD * a % MOD) % MOD;
        res %= MOD;
      }
      a = (a % MOD * a % MOD) % MOD;
      b >>= 1;
    }
    res %= MOD;
    return (int) res;
  };
  int cnt = count(s.begin(), s.end(), '1');
  int inc = 0, dec = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1') {
      inc += modpow(2, n - i - 1, cnt + 1);
      inc %= (cnt + 1);
      if (cnt > 1) {
        dec += modpow(2, n - i - 1, cnt - 1);
        dec %= (cnt - 1);
      }
    }
  }
  auto solve = [&](int num) {
    int res = 0;
    while (num != 0) {
      ++res;
      num %= __builtin_popcount(num);
    }
    return res;
  };
  for (int i = 0; i < n; i++) {
    long long val;
    if (s[i] == '0') {
      val = modpow(2, n - i - 1, cnt + 1) + inc;
      while (val < 0)
        val += cnt + 1;
      val %= (cnt + 1);
    } else {
      if (cnt > 1) {
        val = dec - modpow(2, n - i - 1, cnt - 1);
        while (val < 0)
          val += cnt - 1;
        val %= (cnt - 1);
      } else {
        cout << "0\n";
        continue;
      }
    }
    cout << solve(val) + 1 << '\n';
  }
  return 0;
}

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

int search(int arr[],int n,int key){
    for(int i=0;i<n;i++){
        if(arr[i]==key)
        return 0;
    }
    return 1;
}

int main(){
    int x,n,i;
    cin>>x>>n;
    int arr[n];
    for(i=0;i<n;i++)
    cin>>arr[i];
    int min=INT_MAX,value=0;
    for(i=0;i<=1000;i++){
        int temp=search(arr,n,i);
        if(temp){
            int l=abs(x-i);
            if(l<min){
                min=l;
                value=i;
            }
        }
    }
    cout<<value;
    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int SURP = 1000000007;

int main(){
	int N;
	cin >> N;
	int a[N];
	FOR(i,0,N){
		cin >> a[i];
	}

	sort(a,a+N);

	long long int ret = 0;

	if(N%2 == 1){
		if(a[0] != 0){
			cout << ret << endl;
			return 0;
		}
		FOR(i,1,N){
			if( (i+1)/2 *2 != a[i]){
				cout << ret << endl;
				return 0;
			}
		}

		if (N>1){
			ret = 2;
			FOR(i,0,(N-1)/2-1){
				ret = (ret*2)%SURP;
			}
		}else{
			ret = 1;
		}

	}else{
		if(a[0] != 1){
			cout << ret << endl;
			return 0;
		}
		FOR(i,0,N){
			if( i/2 *2 != a[i]-1){
				cout << ret << endl;
				return 0;
			}
		}
		ret = 2;
		FOR(i,0,(N-1)/2){
			ret = (ret*2)%SURP;
		}
	}

	cout << ret << endl;
	return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define maxe(a,b,c) max(a,max(b,c))
#define eb emplace_back
#define em emplace
#define print(x) cout<<x<<endl;
#define fill(a,val) memset(a,val,sizeof(a))
#define in(k) int k;cin>>k
#define edl cout<<"\n"
#define ll  long long
#define ld  long double
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const ll mod=1e9+7;
signed main()
{
    //cout<<fixed<<setprecision(20);
    fastio;
    in(n);
    ll a[n];
    fr(i,0,n-1)
    cin>>a[i];
    ll d1[n][n];
    ll d2[n][n];
    fr(i,0,n-1)
    {
        d2[i][i]=0;
        d1[i][i]=a[i];
    }
    fr(i,0,n-2)
    {
        int x=0,y=i+1;
        for(int j=n-2;j>=i;j--)
        {
            d1[x][y]=max(a[y]+d2[x][y-1],a[x]+d2[x+1][y]);
            if(a[y]+d2[x][y-1]>a[x]+d2[x+1][y])
            d2[x][y]=d1[x][y-1];
            else
            d2[x][y]=d1[x+1][y];
            x++;y++;
        }
    }
    print(d1[0][n-1]-d2[0][n-1]);
    //printclock;
    return 0;
}

Measured memory_bytes: 140928
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, K;
  cin >> N >> K;
  vector<ll> H(N);
  for(int i=0; i<N; i++)
    cin >> H[i];
  sort(H.begin(), H.end());
  // for(int i=0; i<N; i++)
  //   cout << H[i] << ' ';
  // cout << endl;
  ll ans = 1000000000;
  for(int i=0; i<N-K+1; i++) {
    if(H[i+K-1] - H[i] < ans)
      ans = H[i+K-1] - H[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String args[]){//double 处理果盘
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),j;
		if (n % 2 == 0){
			j = n/2;
		}else{
			j = 1 + (n -1 )/2;
		}
		float x = (float)j/n;
		System.out.println(x);
		
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <vector>
#include "string"

using namespace std;

typedef long long ll;

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

    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    vector<ll> h(N);

    int hi, xi, yi;

    for (int i = 0; i < N; i++) {
        cin >> x[i];
        cin >> y[i];
        cin >> h[i];
        if (h[i] > 0) {
            xi = x[i];
            yi = y[i];
            hi = h[i];
        }
    }

    bool flag = true;
    int ans = 0;

    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            flag = true;
            ans = hi + abs(i - xi) + abs(j - yi);
            for (int k = 0; k < N; k++) {
                if (max(ans - abs(x[k] - i) - abs(y[k] - j), 0) != h[k]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                cout << i << " " << j << " " << ans;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

W, H, N = map(int, input().split())

# print(W)
# print(H)
# print(N)

width = []
height = []

for i in range(0, W):
    width.append(0)
    
for i in range(0, H):
    height.append(0)
    
for i in range(0, N):
    # pass
    x, y, a = map(int, input().split())
    # print(x)
    # print(y)
    # print(a)
    
    if a == 1:
        for j in range(0, len(width)):
            if j < x:
                width[j] = 1
    elif a == 2:
        for j in range(0, len(width)):
            if j >= x:
                width[j] = 1
    elif a == 3:
        for j in range(0, len(height)):
            if j < y:
                height[j] = 1
    elif a == 4:
        for j in range(0, len(height)):
            if j >= y:
                height[j] = 1
    
# print(width.count(0))
# print(height.count(0))

print(width.count(0) * height.count(0))

Measured memory_bytes: 3064
N, K = list(map(int, input().split()))
D = list(map(int, input().split()))
flag = True
ans = N
while flag:
    ans_nums = []
    x = ans
    while x>=1:
        ans_nums.append(x%10)
        x = (int)(x/10)
    #print(ans_nums)
    a = list(set(ans_nums) & set(D))
    #print(a)
    if len(a) == 0:
        flag = False
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int dp[50][50];
int main()
{
    int n;
    while(scanf("%d", &n), n)
    {
        memset(dp, 50, sizeof(dp));
        for(int i = 0; i < n; i++)
        {
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            dp[a][b] = dp[b][a] = min(dp[a][b], c);
        }
        for(int k = 0; k <= 15; k++)
            for(int i = 0; i <= 15; i++)
                for(int j = 0; j <= 15; j++)
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
        int a = 0, b = 10000;
        for(int i = 0; i <= 15; i++)
        {
            int tmp = 0;
            for(int j = 0; j <= 15; j++)
            {
                if(dp[i][j] < 1000000 && j != i)
                    tmp += dp[i][j];
            }
            if(tmp && tmp < b)
            {
                a = i;
                b = tmp;
            }
        }
        printf("%d %d\n", a, b);
    }
    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
char s[100100];
int main(){
	scanf("%s",s);
	char x=0;
	for(int c='a';c<='z';c++){
		bool flag=true;
		for(int i=0;s[i];i++){
			if(s[i]==c){
				flag=false;
				break;
			}
		}
		if(flag){
			x=c;
			break;
		}
	}
	if(x) printf("%c\n",x);
	else puts("None");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
  ll s;
  cin >> s;
  if(s < 3){ cout << 0 << endl; return 0; }
  ll dp[2000];
  dp[0] = dp[1] = dp[2] = 1;
  for(int i=3; i<=s-3; ++i){
    dp[i] = (dp[i-1]+dp[i-3])%mod;
  }
  cout << dp[s-3] << endl;
}

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

int main(){

	int N, M;
	cin >> N >> M;
	int A[100];
	for(int i = 0; i < N; i++)
		cin >> A[i];

	for(int k = 1; k <= M; k++){
		for(int i = 0; i < N - 1; i++){
			if(A[i] % k > A[i+1] % k){
				swap(A[i], A[i+1]);
			}
		}
	}
	
	for(int i = 0; i < N; i++)
		cout << A[i] << endl;

	return 0;
}


Measured memory_bytes: 3032
N, Y = map(int, input().split())

result = None
num = 10000 * N - Y
flag = False
for i in range(N+1):
    if flag:
        break
    for j in range(N-i+1):
        if 9000 * i + 5000 * j == num:
            result = str(N-i-j) + ' ' + str(j) + ' ' + str(i)
            flag = True
            break
        elif 9000 * i + 5000 * j > num:
            break

print(result if result else '-1 -1 -1')
            


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

int main() {
  int x,a,b; cin >> x >> a >> b;
  if(b<=a) cout << "delicious" << endl;
  else if(a+x>=b) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main() {
    long n;
    long s[1000]={0};


    while(1){
        cin >> n;
        if (n==0)break;
        double sum = 0;
        for (int i = 0; i < n; ++i) {
            cin >> s[i];
            sum += s[i];
        }

        //ave
        double ave = sum / n;

        //Dispersion
        double alpha = 0;
        for (int i = 0; i < n; ++i) {
            alpha += (s[i] - ave) * (s[i] - ave) / n;
        }
        cout << fixed << setprecision(9) << sqrt(alpha) << endl;
    }
     return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int N;
      cin >> N;
      vector<vector<int>> hapiness (N,vector<int>(3));
      for(int i = 0;i < N;i++){
          cin >> hapiness[i][0] >> hapiness[i][1] >> hapiness[i][2];
      }

      vector<vector<int>> dp (N+1,vector<int>(3,0));//dp[日数][0=a,1=b,2=c]
      for(int i = 1;i <= N;i++){
          dp[i][0] = max(dp[i-1][1],dp[i-1][2])+hapiness[i-1][0];
          dp[i][1] = max(dp[i-1][0],dp[i-1][2])+hapiness[i-1][1];
          dp[i][2] = max(dp[i-1][0],dp[i-1][1])+hapiness[i-1][2];
      }
      cout << max(dp[N][0],max(dp[N][1],dp[N][2])) << endl;
}


Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {
	static int[][] a = new int [100010][3];
	static long[][]dp= new long [100010][3];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j]=Integer.parseInt(sc.next());
			}
		}
		sc.close();

		for (int i = 0; i < n; i++) {
	        for (int j = 0; j < 3; j++) {
	            for (int k = 0; k < 3; k++) {
	                if (j == k) continue;
	                dp[i + 1][k] = Math.max(dp[i + 1][k], dp[i][j] + a[i][k]);
	            }
	        }
	    }
		long res = 0;
	    for (int j = 0; j < 3; ++j) res = Math.max(res, dp[n][j]);

	    System.out.println(res);
	}

}


Measured memory_bytes: 72280
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < n; ++i)
#define rep(i, n) rep_init(i, 0, n)

void Main()
{
	string S;
	cin >> S;

	rep(i, S.size())
	{
		if (i % 2 == 0) cout << S[i];
	}
	cout << endl;
}

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

	Main();
	return 0;
}

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

int main() {
	int N, red=0, blue=0;
	string s;
	cin >> N >> s;

	for (int i = 0; i < N; i++) {
		if (s[i] == 'R') {
			red++;
		}
		else {
			blue++;
		}
	}

	if (red > blue) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import math
def gcd(a,b):
    if b>a:
        a,b=b,a
    while b:
        a,b=b, a%b
    return a

a,b=map(int,input().split())
x=gcd(a,b)
s=set()
for i in range(2, min(x+1,int(math.sqrt(x))+2) ):
    while x%i==0:
        x=x//i
        s.add(i)
    if x==1: break
if x>1: s.add(x)
print(len(s)+1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main() {
    char S[10];
    scanf("%s", S);
    if (!strcmp(S, "Sunny")) {
          printf("%s\n", "Cloudy");
    } else if(!strcmp(S, "Cloudy")) {
          printf("%s\n", "Rainy");
    } else {
          printf("%s\n", "Sunny");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifdef APURBA
#define HERE cout<<"here - "<<__LINE__<<"\n";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)
{
    cout<<endl;
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cout << *it << " = " << a << " ";
    err(++it, args...);
}
#else
#define HERE
#define debug(args...)
#endif
const ll mod = 1e9+7 ;
const int N = (1<<17);
typedef pair<int,int> pii;

int fun(string s, string t)
{
    if(s.size()!=t.size())
        return 1e9;
    int cnt = 0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }
    return cnt;
}

void TEST_CASES(int cas)
{
    string s,t;
    cin>>s>>t;
    int ans = 1e9;
    for(int i=0;i<s.size();i++)
    {
        ans = min(ans , fun(s.substr(i,t.size()) , t));
    }
    printf("%d\n",ans);
}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }
    return 0;
}



template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}



Measured memory_bytes: 3756
/* KYA CODEFORCES MERE BAS KI BAT NHI HAI  */
 
 #include<iostream>
 #include<cstring>
 #include<string>
 #include<vector>
 #include<utility>
 #include<stdlib.h>
 #include<limits.h>
 #include<cmath>
 #include<set>
 #include<initializer_list>
 #include<unordered_set>
 #include<unordered_map>
 #include<map>
 #include<iomanip>
 #include<algorithm>
 #include<queue>
 #include<stack>
#include <cstdint>
  
 #define sze 1000005
 #define ld long double
 //#define ll unsigned long long
 #define ll long long
 #define endl "\n"
 #define pb push_back
 #define mkp make_pair
 #define mod 1000000007
 #define ff first
 #define ss second
 #define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
 #define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
 #define all(c) (c).begin(),(c).end()
 #define pi                   pair<int,int>
 #define pll                  pair<ll,ll>
 #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
 using namespace std;
 
//cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
 //const ll inf=1ll<<60;
 //const double pi = 3.14159265358979323846;


 int main()
 {
     ll n; cin>>n;
     ll sum=0;
     for(ll i=1;i<n;i++)
     {
         sum += (n-1)/i;
     }
     cout<<sum<<endl;
 }


Measured memory_bytes: 3524
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> lpair;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B;
    cin >> A >> B;
    if(A <= 9 && B <= 9){
        print(A*B);
    }else{
        print(-1);
    }
    

}


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	long long f;
	int n;
	int i;
	
	scanf("%d", &n);
	
	f = 1;
	for (; n > 1; n--){
		f *= n;
	}
	printf("%u", f / 1000000000);
	printf("%u\n", f % 1000000000);

	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;

int main(){
    int N, M;
    cin>>N>>M;
    int X;
    if(M<10){
        X=10*N+M;
    }
    else if(M<100){
        X=100*N+M;
    }
    else{
        X=1000*N+M;
    }
    int XX=pow(X, 0.5);
    if(X==XX*XX){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>



int main()
{
    long long int i,j;

    char a[1000];

    while(gets(a))
    {
        for(i=0;i<strlen(a);i++)
        {
            if(a[i]==','){printf(" ");}
            else{printf("%c",a[i]);}
        }
        printf("\n");
    }
            return 0;
        }

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
	int order[5];
	int ordercut[5];
	for (int i = 0; i < 5; i++)
	{
		scanf("%d", &order[i]);
		ordercut[i] =  ((order[i]/10)*10)==order[i] ? order[i] : ((order[i]/10)+1)*10;
	}
	int min = 888;
	for (int i = 0; i < 5; i++)
	{
		int tmin = 0;
		for (int j = 0; j < 5; j++)
		{
			if (j == i)
			{
				tmin += order[j];
			}
			else
			{
				tmin += ordercut[j];
			}
		}
		min = min > tmin ? tmin : min;
	}
	printf("%d\n", min);
}

Measured memory_bytes: 256
#上から貪欲
n = int(input())
a=[];b=[]
for _ in range(n):
    ai,bi=map(int, input().split( ))
    a.append(ai)
    b.append(bi)

#毎回すべてのaiに足すと間に合わない
tmp = 0
ans = 0
for i in range(n-1,0,-1):
    c = a[i]//b[i]
    if a[i]>b[i]*c:
        c+=1
    #print(b[i]*c-a[i])
    ans += b[i]*c-a[i]
    tmp += b[i]*c-a[i]
    a[i-1] += tmp
c = a[0]//b[0]
if b[0]*c<a[0]:
    c+=1
ans += b[0]*c-a[0]
print(ans)

Measured memory_bytes: 56920
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 08/29/20 20:54:54
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s,t; cin>>s>>t;
  int ans = t.size();
  for (int i = 0; i < s.size()-t.size()+1; i++) {
    int cnt = 0;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j])
        cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1);
int f[100];
int main()
{
  //  cout << atan(1)*180/PI;
    double a,b,x;
    cin >> a>> b >>x;
    double shangdi=x*2/a/a-b;

    if(shangdi<=0){

        shangdi=2*x/a/b;
   //  cout << shangdi << endl;
      //  cout << 90.0-atan(shangdi/b)*180.0/PI << endl;
        printf("%.10f",atan(b/shangdi)*180.0/PI);
    }else{

        shangdi=b-shangdi;
       // cout << shangdi << endl;
      //  cout << 90.0-atan(aangdi)*180.0/PI << endl;
        printf("%.10f",atan(shangdi/a)*180.0/PI);
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define S second
#define F first

using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
set<int> v[2];
int seq[3000];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(false);
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1;i <= n;i++){
        cin >> seq[i];
        sum += seq[i];
    }
    bitset<2000001> a,b;
    a[0] = 1;
    for (int i= 1;i <= n;i++){
        b = a;
        b <<= seq[i];
        a |= b;
    }
    int mx;
    for (int i  = sum/ 2;i > -1;i--){
        if (a[i]){
            mx = i;
            break;
        }
    }
    cout << sum  -  mx << endl;
    return 0;
}


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

int main() {
	int N;
	int a;
	int p;

	cin >> N;
	p=0;
	for(int i = 0; i < N; i++) {
		cin >> a;
		if((i%2)==1) continue;
		if((a%2)==1) p++;
	}
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

#define MAN 200000

signed main(){
  int N,H,W;
  cin>>N>>H>>W;
  int a,b;
  int res=0;
  LOOP(i,N){
    cin>>a>>b;
    if(a>=H && b>=W){
      res++;
    }
  }
  cout << res;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct edge {
    int to,rev;
    int cap;
    edge() {}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev) {}
};

struct Dinic{
    int N;
    vector<vector<edge>> G;
    vector<int> level; // min distance from s
    vector<int> iter;

    Dinic(int _N):N(_N) {
        G.resize(N),level.resize(N), iter.resize(N);
    }

    void add_edge(int a,int b,int c){
        // only directed edge
        G[a].push_back((edge){b,c,(int)G[b].size()});
        G[b].push_back((edge){a,0,(int)G[a].size() - 1});
    }

    void _bfs(int s){
        fill(level.begin(),level.end(),-1);
        queue<int> q;
        q.push(s);
        level[s] = 0;
        while (!q.empty()){
            int v = q.front(); q.pop();
            for (int i = 0;i < G[v].size(); ++i){
                edge &e = G[v][i];
                if (e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    
    int _dfs(int v,int t,int f){
        if (v == t) return f;
        for (int &i = iter[v];i < G[v].size(); ++i) {
            edge &e = G[v][i];
            if (e.cap > 0 && level[e.to] > level[v]){
                int d = _dfs(e.to,t,min(f,e.cap));
                if (d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int maxflow(int s,int t){
        int flow = 0;
        for (;;){
            _bfs(s);
            if (level[t] < 0) return flow; // no augmenting path
            fill(iter.begin(),iter.end(),0);
            int f;
            while ((f = _dfs(s,t,INF)) > 0) flow += f;
        }
    }
};

int main() {
    int N; cin >> N;
    Dinic dn(2*N + 2);
    rep(i,N) dn.add_edge(0,i + 1,1);
    rep(i,N) dn.add_edge(N + i + 1,2*N + 1,1);
    vector<P> A(N),B(N);
    rep(i,N) {
        int a,b; cin >> a >> b;
        A[i] = make_pair(a,b);
    }
    rep(i,N) {
        int a,b; cin >> a >> b;
        B[i] = make_pair(a,b);
    }
    rep(i,N)rep(j,N) {
        if (A[i].first < B[j].first && A[i].second < B[j].second) dn.add_edge(i + 1,N + j + 1,1);
    }
    cout << dn.maxflow(0,2*N + 1) << '\n';
}

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

int main()
{
	int N;
	cin>>N;
	int arr[N][3];
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>arr[i][j];
		}
	}
	for(int i=1;i<N;i++)
	{
		for(int j=0;j<3;j++)
		{
			int temp = INT_MIN;
			for(int k=0;k<3;k++)
			{
				if(j!=k)
				{
					temp = max(temp, arr[i-1][k]);
				}
			}
			arr[i][j]+=temp;
		}
	}
	// for(int i=0;i<N;i++)
	// {
	// 	for(int j=0;j<3;j++)
	// 	{
	// 		cout<<arr[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	int ans = max(arr[N-1][0],max(arr[N-1][1],arr[N-1][2]));
	cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a[100010];

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

int solve(){
	int c=0;
	REP(i,0,n) c+=a[i]%2;
	if((n-c)%2==1) return 1;
	if(c>1) return 0;
	REP(i,0,n){
		if(a[i]%2&&a[i]!=1) a[i]--;
		else if(a[i]==1) return 0;
	}
	int g=a[0];
	REP(i,0,n) g=gcd(g,a[i]);
	REP(i,0,n) a[i]/=g;
	
	return !solve();
}
		
int main(){
	cin >> n;
	REP(i,0,n) cin >> a[i];
	
	cout << (solve()?"First":"Second") << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N;
int X[20],Y[20],Z[20];
int dpx[20][20],dpy[20][20];
int ans[20];
signed main(){
	cin>>N;
	rep(i,N)cin>>X[i]>>Y[i]>>Z[i];
	rep(i,N+1)ans[i]=inf;
	X[N]=inf;Y[N]=inf;
	X[N+1]=-inf;Y[N+1]=-inf;
	rep(i,1<<N){
		vector<P>x,y;
		rep(j,N){
			if(i>>j&1)x.push_back({X[j],j});
			else y.push_back({Y[j],j});
		}
		x.push_back({inf,N});y.push_back({inf,N});
		x.push_back({-inf,N+1});y.push_back({-inf,N+1});
		sort(all(x));sort(all(y));
		rep(j,N+4)rep(k,N+4){
			dpx[j][k]=inf;
			dpy[j][k]=inf;
		}
		dpx[0][0]=0;
		rep(j,len(x)){
			rep(k,j+1){
				for(int l=j+1;l<=len(x);l++){
					int sum=0;
					for(int p=j;p<l;p++){
						if(!p||p==len(x)-1)continue;
						sum+=min({abs(x[p].first),abs(x[p].first-x[j].first),abs(x[p].first-(l!=len(x)?x[l].first:inf))})*Z[x[p].second];
					}
					chmin(dpx[l][k+1],dpx[j][k]+sum);
				}
			}
		}
		dpy[0][0]=0;
		rep(j,len(y)){
			rep(k,j+1){
				for(int l=j+1;l<=len(y);l++){
					int sum=0;
					for(int p=j;p<l;p++){
						if(!p||p==len(y)-1)continue;
						sum+=min({abs(y[p].first),abs(y[p].first-y[j].first),abs(y[p].first-(l!=len(y)?y[l].first:inf))})*Z[y[p].second];
					}
					chmin(dpy[l][k+1],dpy[j][k]+sum);
				}
			}
		}
		REP(j,len(x)+1)REP(k,len(y)+1)chmin(ans[j+k-2],dpx[len(x)][j]+dpy[len(y)][k]);
	}
	rep(i,N+1)cout<<ans[i]<<"\n";
}

Measured memory_bytes: 3588
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#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()

int main()
{
	ll N, M;
	cin >> N >> M;
	ll ans = 0;
	if (N == 1 && M == 1) {
		ans = 1;
	} else if (N > 1 && M > 1) {
		ans = (N - 2)*(M - 2);
	} else if (N > 1) {
		ans = N - 2;
	} else {
		ans = M - 2;
	}
	//vector<vector<bool>> bits(N, vector<bool>(M));

	//static const int dx[] = { 1, 0,-1, 0, 1,-1,-1, 1 };
	//static const int dy[] = { 0, 1, 0,-1, 1, 1,-1,-1 };
	//rep(i, N) {
	//	rep(j, M) {
	//		bits[i][j] = !bits[i][j];
	//		rep(k, 8) {
	//			int x = dx[k] + j;
	//			int y = dy[k] + i;
	//			if (x >= 0 && x < M && y >= 0 && y < N) {
	//				bits[y][x] = !bits[y][x];
	//			}
	//		}
	//	}
	//}
	//ll ans = 0;
	//rep(i, N) {
	//	rep(j, M) {
	//		if (bits[i][j])
	//			ans++;
	//	}
	//}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256