akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <numeric>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#define mod 1000000007
using namespace std; 

int main(){
    int a,b; cin >> a >> b;
	vector<int> A;
	vector<int> B;
	for (int i=0;i<1009;i++){
		double s=i*0.08;
		if (s<a+1 && s>=a){
			A.push_back(i);
		}
	}
	for (int i=0;i<1009;i++){
		double f=i*0.1;
		if (f<b+1 && f>=b){
			B.push_back(i);
		}
	}
	for (auto z : A){
		for (auto x : B){
			if (z==x){
				cout << z << "\n";
				return 0;
			}
		}
	}
	cout << -1 << "\n";
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define ll long long
#define bpm %1000000007

using namespace std;

ll powAns(ll,ll);

int main(){
    int n;
    ll j;
    int count=0;
    ll k=2;
    bool e;
    cin>>n;
    vector<ll> number;

    rep(i,n){
    cin>>j;
    number.push_back(j);
    }

    rep(i,n){
        e=true;
        while(k<=sqrt(number[i])){
        if(sqrt(number[i]%k ==0)){
            e=false;
            break;
        }
        k+=1;
        }
        if(e){
            count+=1;
        }
        k=2;
    }
    cout<<count<<endl;
}

ll powAns(ll m ,ll n){
    ll res=1;
    while(n>0){
        if(n & 1)res = res*m bpm;

        m=m*m bpm;
        n>>=1;
    }

    return res;
}



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

int main(){
    int n, k;
    cin >> n >> k;
    set<int> S;
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            S.insert(a);
        }
    }
    int ans = n - S.size();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>
#include <stdlib.h>

int compare( const void *, const void * );

int main( void ) {
	int i, data[ 5 ];

	for ( i = 5; i--; scanf( "%d", data + i ) ) ;

	qsort( data, 5, sizeof(int), &compare );

	for ( i = 5; i-- > 1; printf( "%d ", data[ i ] ) ) ;
	printf( "%d\n", data[ 0 ] );

	return 0;
}

int compare( const void *a, const void *b ) {
	return *(int *)a - *(int *)b;
}

Measured memory_bytes: 600
import sys
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))

n,k = Mi()
a = Li()
b = [1]
b.append(a[0])
flag = False
for i in range(n):b.append(a[b[-1]-1])
if len(b) > k:
  print(b[k])
  exit(0)
for j in range(len(b)):
  if b[j] == a[b[-1]-1]:
    break
    
roop = len(b)-j
roopk = (k-j)%roop
print(b[roopk+j])

Measured memory_bytes: 29416
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

#define rep(i, n) for(int i = 0; i < n; i++)
using ll = long long;

using namespace std;

int main()
{
    ll n;   cin >> n;
    ll rn = pow(n, 1.0/2.0);
    vector<ll> a(rn);
    vector<ll> b(rn);

    int m = 0;
    for(int i = 1; i <= rn; i++){
        if(n % i == 0){
            a[m] = i;
            b[m++] = n / i;
        }
    }

    vector<ll> c(m);
    for(int i = 0; i < m; i++){
        c[i] = a[i] + b[i];
    }

    sort(c.begin(), c.begin() + m);

    cout << c[0] - 2 << endl;
}

Measured memory_bytes: 15872
'use strict';
(function(stdin) {
  var lines = stdin.toString().split('\n');
 
  var result = (function(word,data) {
    return data.split(' ')
      .filter(function(v) {
        return v === word;
      })
      .length;

  }(
    lines.shift().toLowerCase()
    ,lines.join(' ').split('END_OF_TEXT')[0].trim().toLowerCase()
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7908
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MAX = 3234566667;

typedef pair<int, int> P;

set<ll> ru;
void dfs(ll s) {
    if (s > MAX) return ;
    if (ru.count(s) != 0) return ; 
    ru.insert(s);
    ll ct = s % 10;
    for (ll i = ct - 1; i <= ct + 1; i++) {
        if (i < 0 || i > 9) continue;
        dfs(s * 10LL + i);
    }
}
int main()
{
    ll K;
    cin >> K;

    repd(i, 1, 10) {
        dfs(i);
    }

    ll cnt = 1;
    for (auto itr = ru.begin(); itr != ru.end(); itr++) {
        if (cnt == K) {
            cout << *itr << endl;
            break;
        }
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N,K;
  cin>>N>>K;
  bool flag=true;
  int count=0;
  long long NN=N;
  while(flag){
    if(NN/K==0){
      flag=false;
    }
    else{
      NN=NN/K;
      count=count+1;
    }
  }
  cout<<count+1<<endl;
}

Measured memory_bytes: 256
n = int(input())
u = []
v = []
for i in range(n-1):
    i1, i2 = map(int, input().split())
    u.append(i1)
    v.append(i2)

V = 0

for i in range(1,n+1):
    V = V + i*(n-i+1)

E = 0

for i in range(n-1):
    if u[i] > v[i]:
        a = v[i]
        b = u[i]
    else:
        a = u[i]
        b = v[i]
    E = E + a*(n-b+1)

print(V - E)

Measured memory_bytes: 24940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n;
ll k,a[N],L,R;
int main(){
    scanf("%d%lld",&n,&k);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    sort(a,a+n);
    L=-1e18,R=1e18;
    while(L+1!=R){
        ll Mid=(L+R)/2;
        ll cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]<0){//小于0则向下找
                int l=i,r=n;
                while(l+1!=r){
                    int mid=(l+r)/2;
                    if(a[i]*a[mid]<=Mid) r=mid;
                    else l=mid;
                }
                cnt+=n-r;
            }
            else{
                int l=i,r=n;
                while(l+1!=r){//大于0向上找
                    int mid=(l+r)/2;
                    if(a[i]*a[mid]<=Mid) l=mid;
                    else r=mid;
                }
                cnt+=l-i;
            }
        }
        if(cnt<k) L=Mid;
        else R=Mid;
    }
    printf("%lld",R);
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

const int MAX_N = 2e2;
const int INF = 1e9;
int G[MAX_N][MAX_N];

vector<int> Rv;
bool visited[MAX_N];

int dfs(int cur)
{
    int ret = INF;
    visited[cur] = true;

    for (int next : Rv)
        if (!visited[next])
            ret = min(ret, dfs(next) + G[cur][next]);

    visited[cur] = false;

    if (ret == INF)
        ret = 0;

    return ret;
}


int main(void)
{
    cin.sync_with_stdio(false); cin.tie(NULL);
    int N, M, R;    cin >> N >> M >> R;
    int v1, v2, v3;

    for (int i = 0; i < N; i++)
    {
        fill(G[i], G[i] + N, INF);
        G[i][i] = 0;
    }

    for (int i = 0; i < R; i ++)
    {
        cin >> v1;
        v1--;
        Rv.push_back(v1);
    }

    for (int i = 0; i < M; i ++)
    {
        cin >> v1 >> v2 >> v3;
        v1--, v2--;

        G[v1][v2] = v3;
        G[v2][v1] = v3;
    }

    for (int k = 0; k < N; k ++)
        for (int i = 0; i < N; i ++)
            for (int j = 0; j < N; j ++)
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);

    int res = INF;

    for (int item : Rv)
        res = min(res, dfs(item));

    cout << res << endl;
}


Measured memory_bytes: 384
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
hako = [1]*(n+1)
iro = ['white']*(n+1)
iro[1] = 'red'

for _ in range(m):
    
    x,y = map(int,input().split())
    if iro[x] == 'red':
        iro[y] ='red'
    elif iro[x] == 'white' and hako[y] == 0:
        iro[y] = 'white'
    hako[x] -= 1
    hako[y] += 1
ans = 0
for i in range(1,n+1):
    if hako[i] > 0 and iro[i] == 'red':
        ans += 1
print(ans)

Measured memory_bytes: 42972
H,W = map(int,(input().split()))
List = [list(map(str,input().split())) for i in range(H)]
n = 0
for i in range(H*2):
  if(i % 2 == 0):
    List2 = List[n]
    for a in List2:
      if(n != 0):
        print("")
        print(a,end = "")
      else:
        print(a,end = "")
  else:
    List2 = List[n]
    for a in List2:
      print("")
      print(a,end = "")
      n += 1

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

void solve() {
    int n; sc(n);
    int a[n]; fo(i, n) sc(a[i]);
    int maxIdx1 = 0;
    fo(i, n) if (a[i] > a[maxIdx1]) maxIdx1 = i;
    int maxIdx2 = (maxIdx1 == 0) ? 1 : 0;
    fo(i, n) {
        if (i == maxIdx1) continue;
        if (a[i] > a[maxIdx2]) maxIdx2 = i;
    }
    int max1 = a[maxIdx1];
    int max2 = a[maxIdx2];
    fo(i, n) {
        if (i == maxIdx1) printf("%d\n", max2);
        else printf("%d\n", max1);
    }
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 2432
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define flash ios_base::sync_with_stdio(false);     cin.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define f first
#define s second



using namespace std;

int main()
{
  flash
  ll n,k;
  cin>>n>>k;

  std::vector<int> v(n);
  for(int i=0;i<n;i++){

    cin>>v[i];

  }
  ll dp[n]={0};
  dp[0]=0;
  dp[1]=abs(v[1]-v[0]);

  for(int i=2; i<n;i++){

    std::vector<ll> temp;
    ll jh = -1;
    ll mx = 1e18;
    for(int j=1;j<=k && i-j>=0 ;j++){
      ll tempi = abs(v[i]-v[i-j]) + dp[i - j];
      if(tempi<mx){
        mx= tempi;
        jh = j;
      }
    }
    dp[i] = abs(v[i]-v[i-jh]) + dp[i - jh];

  }

  cout<<dp[n-1]<<"\n";

}


Measured memory_bytes: 4508
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

const int MAX=100005;
const int oo=100000;
int alturas[MAX];
int dp[MAX];
int n;

int distancia(int i){
    if(i<0) return oo;
    if(i==0) return 0;
    if(dp[i]!=-1) return dp[i];
    dp[i]=min(distancia(i-1)+abs(alturas[i]-alturas[i-1]),distancia(i-2)+abs(alturas[i]-alturas[i-2]));
    return dp[i];
}

int main() {
    #ifndef LOCAL
    fastIO;
    #endif
    memset(dp,-1,sizeof(dp));
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> alturas[i];
    }
    cout << distancia(n-1) << endl;
    return 0;
}

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

int main(void){
	while(true){
		int x,y,s;
		cin >> x >> y >> s;
		if(x == 0 && y == 0 && s == 0)break;
		int ret = 0;
		for(int i=1;i<s;i++){
			for(int j=i;j<s;j++){
				if(i * (100+x) / 100 + j * (100+x) / 100 == s){
					ret = max(i * (100+y) / 100 + j * (100+y)/ 100,ret);
				}
			}
		}
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 3068
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

score = 0
for i in range(0,N-1):
    if A[i+1] - A[i] == 1:
        score += C[A[i] - 1]
print(score + sum(B))

Measured memory_bytes: 3064
// 2020-06-28 14:24:37
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ld a, b;
  cin >> a >> b;
  cout << ll(a*b*100+0.5)/100 << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3784
/* ex 3_4
  kt125 */

#include<stdio.h>

int main(void){
  int n;
  scanf("%d", &n);
  
  int exist = 0;
  for(int i = 0; i < 9; i++){
    for(int j = 0; j< 9; j++){
      if(n == (i+1) * (j+1)){
        exist++ ; break;
      }
    }
  }
  
  if (exist == 0)
    printf("No");
  else
    printf("Yes");

}
    

Measured memory_bytes: 128
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include <bits/stdc++.h>

using namespace std;

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

const ll maxn =9e5+100;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n;

int main(){
    migmig
    cin >> n;
    cout << (n + 1)/2;



    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


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

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

	int r = 0;
	string s, t;
	cin >> s >> t;

	for(int i = 0; i < s.size(); i++){
		if(s[i] != t[i]) r++;
	}

	cout << r << "\n";

  	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()

const int MAX = 2e5+10;
const int MOD = 1e9+7;

int N;
vi S;
vi lt;

ll solve() {
    int flip = 0;
    REP (i, 2*N) {
        if ((flip + S[i]) % 2 == 0) {
            lt.PB(0);
            flip--;
        } else {
            lt.PB(1);
            flip++;
        }
        if (flip < 0) return 0;
    }
    if (flip != 0) return 0;

    ll res = 1;
    int cnt = 0;
    REP (i, 2*N) {
        if (lt[i]) {
            cnt++;
        } else {
            res *= cnt;
            res %= MOD;
            cnt--;
        }
    }

    FOR (i, 1, N+1) {
        res *= i;
        res %= MOD;
    }
    return res;
}

int main() {
    string s;
    cin >> N >> s;
    REP (i, 2*N) {
        S.PB(s[i] == 'B');
    }
    cout << solve() << endl;
}

Measured memory_bytes: 5108
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

bool flag[330][330][330];
int n;
double dp[330][330][330];
double dfs(int c1,int c2,int c3){
    if(c1+c2+c3==0) return dp[c1][c2][c3] = 0;
    if(flag[c1][c2][c3]) return dp[c1][c2][c3];
    flag[c1][c2][c3] = 1;
    double sum = c1+c2+c3;
    double ans = (double)n/sum;
    double a=0;
    if(c1 > 0) a += dfs(c1-1,c2,c3) * (double)c1/sum;
    ans = a + ans;
    if(c2 > 0) ans += dfs(c1+1,c2-1,c3) * c2/sum;
    if(c3 > 0) ans += dfs(c1,c2+1,c3-1) * c3/sum;
    return dp[c1][c2][c3] = ans;
}

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

    cin >> n;
    vector<int> a(4,0);

    rep(i,n){
        int x;
        cin >> x;
        a[x]++;
    }

    double res = dfs(a[1],a[2],a[3]);
    cout << fixed << setprecision(10) << res << endl;


    cout << endl;
    return 0;
}


Measured memory_bytes: 240384
use std::io::stdin;
use std::str::FromStr;
use std::cmp::max;

fn main(){
    let (k, a, b): (i64, i64, i64) = get_triple();

    let m = k - a + 1;
    let wei = max(2, b - a);

    let ans = if m < 0 {
        k + 1
    } else {
        a + (m/2)*wei + m%2
    };

    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


Measured memory_bytes: 4352
program coins
  implicit none
  integer :: a, b, c, x, i, j, k, m = 0
  read(*,*) a
  read(*,*) b
  read(*,*) c
  read(*,*) x
  x = x/50
  do i = 0, a
    if (10*i > x) exit
    do j = 0, b
      if (10*i+2*j > x) exit
      k = x-(10*i+2*j)
      if (k <= c) m = m+1
    end do
  end do
  write(*,'(i0)') m
end program coins

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

int main(){
    ll N; cin >> N;
    vector<ll> A(N+1),B(N);
    rep(i,N-1) cin >> B[i];
    ll ans = 0;
    rep(i,N){
        if(i == 0){
            ans += B[0];
            continue;
        }
        if(i == N-1){
            ans += B[N-2];
            continue;
        }
        ans += min(B[i],B[i-1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAXLEN = 2000;

const int dxs[] = {0, -1, -1,  0};
const int dys[] = {0, -1,  0, -1};

/* typedef */

/* global variables */

int dp[MAXLEN + 1][MAXLEN + 1], prvs[MAXLEN + 1][MAXLEN + 1];

/* subroutines */

/* main */

int main() {
  string str;
  while (cin >> str) {
    int len = str.length();

    memset(dp, 0, sizeof(dp));
    memset(prvs, 0, sizeof(prvs));

    for (int i = 0; i < len; i++)
      for (int j = 0; j < len - i; j++) {
	if (str[i] == str[len - 1 - j]) {
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	  prvs[i + 1][j + 1] = 1;
	}
	else if (dp[i][j + 1] >= dp[i + 1][j]) {
	  dp[i + 1][j + 1] = dp[i][j + 1];
	  prvs[i + 1][j + 1] = 2;
	}
	else {
	  dp[i + 1][j + 1] = dp[i + 1][j];
	  prvs[i + 1][j + 1] = 3;
	}
      }

    int maxdp = 0, si, sj;

    for (int i = 1; i <= len; i++) {
      int j = len + 1 - i;
      int dp0 = 2 * dp[i][j] - 1;
      if (maxdp < dp0) {
	maxdp = dp0;
	si = i, sj = j;
      }
    }

    for (int i = 1; i < len; i++) {
      int j = len - i;
      int dp0 = 2 * dp[i][j];
      if (str[i - 1] == str[len - j] && maxdp < dp0) {
	maxdp = dp0;
	si = i, sj = j;
      }
    }
    //printf("maxdp=%d, si=%d, sj=%d\n", maxdp, si, sj);

    string ans;

    while (si > 0 && sj > 0) {
      int prv = prvs[si][sj];
      if (prv == 1) {
	string ss = str.substr(si - 1, 1);
	if (si + sj == len + 1)
	  ans = ss;
	else
	  ans = ss + ans + ss;
      }

      si += dxs[prv];
      sj += dys[prv];
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 32492
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <complex>


using namespace std;
typedef long long ll;

int main() {
	const int SIZE = 20005;
	int H, N; cin >> H >> N;

	vector<int> v(SIZE);// v[i] : 体力をi減らすときに必要な魔力
	for (int i = 0; i < SIZE; i++) {
		v[i] = 1000000000;
	}
	v[0] = 0;

	for (int j = 0; j < N; j++) {
		int a, b; cin >> a >> b;
		for (int i = a; i < SIZE; i++) {
			v[i] = min(v[i], v[i - a] + b);
		}
	}

	int ans = 1000000000;
	for (int i = H; i < SIZE; i++) {
		ans = min(ans, v[i]);
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int x;
  cin >> x;
  int cnt500, cnt5;
  cnt500 = x / 500;
  cnt5 = (x - x / 500 * 500) / 5;
  int ans = cnt500 * 1000 + cnt5 * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3560
import collections
n = int(input())
ans = ''

tmp1 = input()
cnt = collections.Counter(tmp1)

for i in range(n-1):
    tmp2 = input()
    cnt2 = collections.Counter(tmp2)
    for k,v in cnt.items():
        if k in cnt2:
            if v > cnt2[k]:
                cnt[k] = cnt2[k]
        else:
            cnt[k]=0

cnt = sorted(cnt.items())
            
for i in range(len(cnt)):
    if cnt[i][1] > 0:
        ans += cnt[i][0] * cnt[i][1]
        
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    map<ll,ll> mp;
    ll a;
    ll total = 0;
    rep(i,n){
        cin >> a;
        mp[a]++;
        total += a;
    }

    int q;
    cin >> q;
    ll b,c;
    rep(i,q){
        cin >> b >> c;
        ll dif = (c-b) *mp[b];
        total += dif;
        mp[c] += mp[b];
        mp[b] = 0;
        cout << total << endl;
    }

    return 0;
}

Measured memory_bytes: 9364
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
	long long  N,M;
	cin>>N>>M;
	if(N>=M/2){
		cout<<M/2<<endl;
	}
	else{
		cout<<N+(M-2*N)/4<<endl;
	}
    return 0;
}

Measured memory_bytes: 3608
let m, n = Scanf.sscanf (read_line ()) "%d %d" @@ fun m n -> (m, n)

let () = Printf.printf "%d\n" @@
  match m, n with 
    | 1, 1 -> 1
    | 1, a | a, 1 -> a - 2
    | n, m -> (n - 2) * (m - 2)
  

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,L,N,M,K,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> A >> B >> C;
  Vec(P,string,N,"");
  rep(i,0,N)cin >> P[i];
  Vec(Q,string,0,"");
    rep(i,0,N){
      if(P[i]=="AB"){
        if(A>B){
          A--;B++;
          Q.pb("B");
        }
        else if(A==B&&i!=N-1){
          if(P[i+1]=="BC"){
            A--;B++;
            Q.pb("B");
          }
          else{
            A++;B--;
            Q.pb("A");
          }
        }
        else{
          A++;B--;
          Q.pb("A");
        }
      }
      else if(P[i]=="AC"){
        if(A>C){
          A--;C++;
          Q.pb("C");
        }
        else if(A==C&&i!=N-1){
          if(P[i+1]=="BC"){
            A--;C++;
            Q.pb("C");
          }
          else{
            A++;C--;
            Q.pb("A");
          }
        }
        else{
          A++;C--;
          Q.pb("A");
        }
      }
      else{
        if(C>B){
          C--;B++;
          Q.pb("B");
        }
        else if(C==B&&i!=N-1){
          if(P[i+1]=="AB"){
            C--;B++;
            Q.pb("B");
          }
          else{
            C++;B--;
            Q.pb("C");
          }
        }
        else{
          C++;B--;
          Q.pb("C");
        }
      }
      if(A<0||B<0||C<0)flag=1;
    }
    if(flag)Out("No");
    else{
      Out("Yes");
      for(auto v:Q)Out(v);
    }
}

Measured memory_bytes: 10564
#include <iostream>

using namespace std;

void printArr(int a[], int len) {


	for (int i = 0; i < len; i++)
	{
		if (i == 0) cout << a[0];
		else cout << " " << a[i];
	}
	cout << endl;
}

int selectionSort(int a[], int len) {

	int count = 0;
	for (int i = 0; i < len; i++)
	{
		int min = i;
		for (int j = i + 1; j < len; j++)
		{
			if (a[min] > a[j]) min = j;
		}
		if (min != i) {
			swap(a[i], a[min]);
			count++;
		}
	}
	return count;
}

int main() {

	int n;
	cin >> n;
	
	int* r = new int[n];

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

	int count = selectionSort(r, n);
	printArr(r, n);
	cout << count << endl;

	delete[] r;
	return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn=1e6+10;
int main(){
	fast;
	int sm=0; 
	string s; cin>>s;
	for(auto i=0;i<s.size();++i)sm+=s[i]-'0';
	(sm%9==0)?cout<<"Yes\n":cout<<"No\n";
	return 0;
}
//prime func
//subset production
//factorization
 
//Trees
//Graphs(dfs,bfs,shortes path etc.)
//DP-Recursion

Measured memory_bytes: 3724
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int temp=1;
	vector<int> list;

	//0になるまで読み込む
	while (true) {
		cin >> temp;
		if (temp == 0) {
			break;
		}
		list.push_back(temp);
	}

	//配列内の全ての要素をプリントする
	for (int i = 0; i < list.size(); i++) {
		cout << "Case " << i+1 << ": " 
			<< list[i] << endl;
	}
    return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;

typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
} 

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

using namespace std;

int a[4];

int main () {
    for (int i = 0; i < 4; ++i) scanf("%d", a + i);
    sort(a, a + 4);

    if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) printf("YES");
    else printf("NO");

    return 0;
}


Measured memory_bytes: 256
N = int(input())

if N % 2 == 1:
    print(0)
    exit()

num = 0
five = 0
N_5 = N // 2

while(True):
    if N_5 >= 5:
        N_5 = N_5 // 5
        five += 1
    else:
        break

N = N // 2

for i in range(1, five+1):
    f = 5 ** i
    num += N // f

print(num)


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
      return cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  deque<ll> d;
  ll n,a;
  string s;
  cin >> n;
  rep(i,n){
    cin >> s;
    if(s == "insert"){
      cin >> a;
      d.push_front(a);
    }
    else if(s == "delete"){
      cin >> a;
      FindErase(d,a);
    }
    else if(s == "deleteFirst") {
      d.pop_front();
    }
    else{
      d.pop_back();
    }
  }
  rep(i,d.size()){
    if(i) cout << ' ' ;
    cout << d[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 10912
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n;
	while (cin >> n&&n)
	{
		vector<pii> a;
		FOR(i, n)
		{
			INT(id);
			pii t(0, id);
			FOR(j, 4)
			{
				int m, s;
				cin >> m >> s;
				t.first += m * 60 + s;
			}
			a.push_back(t);
		}
		sort(ALL(a));
		a.pop_back();
		cout << a[0].second << endl << a[1].second << endl << a.back().second << endl;
	}
}

Measured memory_bytes: 3184
A,B,C,D,E,F=map(int,input().split())
w=set()
s=set()
sw=0
sws=0
sww=0
for i in range(F//(100)):
    for j in range(F//(100)):
        w.add(i*100*A+j*100*B)
for i in range(F//C):
    for j in range(F//D):
        s.add(i*C+j*D)
s=list(s)
w=list(w)
for i in range(len(w)):
    for j in range(len(s)):
        if w[i]+s[j]!=0:
            tmp=(s[j]*100)/(w[i]+s[j])
            if sw <= tmp <= (E*100)/(100+E) and F >= w[i]+s[j]:
                sw =tmp
                sww= w[i]+s[j]
                sws = s[j]
print(sww,sws)

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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;
}

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
        
    int N;
    cin >> N;
    vi hei(N);
    rep(i, N) cin >> hei[i];

    vli dp(N);
    dp[0] = 0;
    dp[1] = abs(hei[1] - hei[0]);
    for (int i = 2; i < N; i++) {
        dp[i] = min(dp[i - 1] + abs(hei[i] - hei[i - 1]), dp[i - 2] + abs(hei[i] - hei[i - 2]));
    }
    
    cou(dp[N - 1]);
}


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


//pair
#define ff              first
#define ss              second

#define int             long long
#define endl            '\n'
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            int t; cin>>t; while(t--)

const int M=1e9+7;
long long mod(long long x){
    return ((x%M + M)%M);
}
int add(int a, int b){
    return mod(mod(a)+mod(b));
}
int mul(int a, int b){
    return mod(mod(a)*mod(b));
}
int sub(int a, int b){
    return mod(mod(a)-mod(b));
}

int modPow(int a, int b){
    if(b==0)
        return 1LL;
    if(b==1)
        return a%M;
    int res=1;
    while(b){
        if(b%2==1)
            res=mul(res,a);
        a=mul(a,a);
        b=b/2;
    }
    return res;
}

int Pow(int a,int b){
    if(b==0)
        return 1;
    if(b==1)
        return a;
    int res=1;
    while(b){
        if(b%2==1)
            res=res*a;
        a=a*a;
        b=b/2;
    }
    return res;
}

int sumOfDigits(int n){
    int s = 0;
    while(n!=0){
        s=s+n%10;
        n=n/10;
    }
    return s;
}
int dp[2005];

int check(int s){

    if(s==1||s==2){
        return 0;
    }

    if(dp[s]!=-1){
        return dp[s];
    }
    int ans = 0;

    for(int i=3;i<=s;i++){
        if(s-i>=0){
            ans = add(ans,check(s-i));
        }

    }
    dp[s]=ans;
    return ans;
}

void solve(){
    int n;
    cin>>n;
    if(n<=2){
        cout<<0;
        return;
    }
    memset(dp,-1,sizeof(dp));
//    cout<<dp[n]<<endl;
    dp[0]=1;
    dp[3]=1;
    dp[4]=1;
    dp[5]=1;
    cout<<check(n);


}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}




Measured memory_bytes: 3656
#!/usr/bin/env python3

N = int(input().split()[0])
p_list = []

for _ in range(N):
    p = int(input().split()[0])
    p_list.append(p)

p_list = sorted(p_list, reverse=True)
ans = p_list[0] // 2 + sum(p_list[1:])

print(ans)


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

#include <atcoder/dsu>
using namespace atcoder;

int main() {
    int N, Q;
    cin >> N >> Q;
    dsu uf(N);
    rep(i,Q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            uf.merge(u, v);
        } else {
            if (uf.same(u, v)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 3924
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        sc.close();

        if (n % 2 != 0) {
            System.out.println("No");
            System.exit(0);
        }

        String ans = "Yes";
        for (int i = 0; i < n / 2; i++) {
            if (s.charAt(i) != s.charAt(i + n / 2)) {
                ans = "No";
                break;
            }
        }
        System.out.println(ans);

    }

}


Measured memory_bytes: 21844
#include <iostream>
#include <cmath>

using namespace std;

long long N,a,b,c,d,e;

int main(){
    cin >> N >> a >> b >> c >> d >> e;
    long long m = min(min(min(a,b),min(c,d)),e);
    long long t = N / m;
    if(N%m != 0) t++;
    cout << t + 4 << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,y,z = inpl()
x -= (y+z+z)
if x < 0:
    print(0)
else:
    print(x//(y+z) + 1)
    

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        //入力
        var arr = arrLong();
        var a = arr[0];
        var b = arr[1];
        var ans = Lcm(a, b);
        Console.WriteLine(ans);
    }

    // 最小公倍数
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }


    //入力受け取り用
    static string crS() { return Console.ReadLine(); }
    static int crI() { return int.Parse(Console.ReadLine()); }
    static int[] arrInt(){return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();}
    static long[] arrLong(){ return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr(){return Console.ReadLine().Split(' ').ToArray();}

}

Measured memory_bytes: 28140
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAXN = 105;
const int MAXM = 10005;

struct edge_color{
	int n, m;
	int deg[2][MAXN];
	pi has[2][MAXN][MAXN];
	int color[MAXM];
	int c[2];

	void dfs(int x, int p) {
		auto i = has[p][x][c[!p]];
		if (has[!p][i.first][c[p]].second) dfs(i.first,!p);
		else has[!p][i.first][c[!p]] = pi(0,0);
		has[p][x][c[p]] = i;
		has[!p][i.first][c[p]] = pi(x,i.second);
		color[i.second] = c[p];
	}

	int solve(vector<pi> v, vector<int> &cv){
		m = sz(v);
		int ans = 0;
		for (int i=1;i<=m;i++) {
			int x[2];
			x[0] = v[i-1].first;
			x[1] = v[i-1].second;
			for (int d=0;d<2;d++) {
				deg[d][x[d]]+=1;
				ans = max(ans,deg[d][x[d]]);
				for (c[d]=1;has[d][x[d]][c[d]].second;c[d]++);
			}
			if (c[0]!=c[1]) dfs(x[1],1);
			for (int d=0;d<2;d++) has[d][x[d]][c[0]] = pi(x[!d],i);
			color[i] = c[0];
		}
		cv.resize(m);
		for(int i=1; i<=m; i++) cv[i-1] = color[i];
		return ans;
	}
}EC;

int n, m, a[MAXN][MAXN], b[MAXN][MAXN], idx[MAXN*MAXN];

int main(){
	auto print_grid = [&](int v[MAXN][MAXN]){
		for(int i=0; i<n; i++){
			for(int j=0; j<m; j++){
				printf("%d ", v[i][j]);
			}
			puts("");
		}
	};
	scanf("%d %d",&n,&m);
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			scanf("%d",&a[i][j]);
		}
	}
	vector<pi> v;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			int col = (a[i][j] - 1) / m;
			idx[a[i][j]] = sz(v);
			v.emplace_back(i+1, col+1);
		}
	}
	vector<int> color;
	assert(EC.solve(v, color) == m);
	for(int i=1; i<=n*m; i++){
		int iv = idx[i];
		b[v[iv].first-1][color[iv] - 1] = i;
	}
	print_grid(b);
	for(int i=0; i<m; i++){
		vector<int> v;
		for(int j=0; j<n; j++) v.push_back(b[j][i]);
		sort(all(v));
		for(int j=0; j<n; j++) b[j][i] = v[j];
	}
	print_grid(b);
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x);
  vector<ll> b(y);
  vector<ll> c(z);
  vector<ll> ab;
  for(int i = 0;i < x;i++)cin >> a[i];
  for(int i = 0;i < y;i++)cin >> b[i];
  for(int i = 0;i < z;i++)cin >> c[i];
  for(int i = 0;i < x;i++){
    for(int j = 0;j < y;j++){
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(ab.rbegin(),ab.rend());
  //for(auto i:ab)cout << i << " ";
  //cout << endl;
  vector<ll> abc;
  ll size = ab.size();
  for(int i = 0;i < min(k,size);i++){
    for(int j = 0;j < z;j++){
      abc.push_back(ab[i] + c[j]);
    }
  }
  sort(abc.rbegin(),abc.rend());
  for(int i = 0;i < k;i++)cout << abc[i] << endl;
}

Measured memory_bytes: 43368
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define INF 1000000000000000000
#define all(x) (x).begin(), (x).end()

int main(){
  int N;
  cin >> N;
  vector<pll> v(N);
  rep(i, N){
    ll a, l;
    cin >> a >> l;
    v[i] = {a - l, a + l};
  }
  
  sort(all(v), [](pll a, pll b) { return a.second < b.second;});
  
  int res = 0;
  ll cur = - INF;
  rep(i, N){
    if (cur > v[i].first) continue;
    res++;
    cur = v[i].second;
  }
  cout  << res << endl;
}


Measured memory_bytes: 1792
count = 0
ans = []
xmax = []
num = []

loop do

 prexmax, prenum = gets.split.map &:to_i

 if !( prexmax == 0 && prenum == 0 )
  xmax << prexmax
  num << prenum
  count += 1

 else
  break
 end

end

for c in 0..count-1

 preans = 0

 imax = [num[c]/3-1, xmax[c]].min
 for i in 1..imax

  jmax = [((num[c]-i)/2.to_f).ceil-1, xmax[c]].min
  for j in i+1..jmax

   if num[c]-i-j <= xmax[c] then preans += 1 end

  end
 end

 ans << preans

end

puts ans



Measured memory_bytes: 8888
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
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; }

ll MOD = 1000000007;
ll INF =1<<29;

int main(){
    int x,n;
    cin >> x>>n;
    vector<int>p(n);
    rep(i,n) cin >> p[i];
    vector<bool>r(101,true);
    rep(i,n){
        r[p[i]]=false;
    }
    int ma = 1000;
    int ans;
    for(int i = 0;i<=101;++i){
        if(r[i]==true&&abs(x-i)<ma){
            ma = abs(x-i);
            ans = i;
        }
    }
    if(ans-x>=x+1){
        cout << -1 << endl;
        return 0;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3628
n, k = map(int, input().split())
d = list(set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) - set(map(int, input().split())))
for i in range(10-k):
    d[i] = str(d[i])

for i in range(n, 10 ** 10):
    f = 0
    for j in range(len(str(i))):
        if str(i)[j] in d:
            f += 1
        if f == len(str(i)):
            print(i)
            exit()

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N),B(N),plus(N);
    ll sum = 0;
    for (int i=0;i<N;i++) {
        cin >> A[i] >> B[i];
        plus[i] = A[i]+B[i];
        sum -= B[i];
    }
    sort(plus.rbegin(),plus.rend());
    for (int i=0;i<N;i+=2){
        sum += plus[i];
    }
    cout << sum << "\n";
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
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;
}*/

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

	int n, ma, mb;
	cin >> n >> ma >> mb;
	vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i] >> b[i] >> c[i];

	// 必要な予算の最小値
	// dp[i][j][k] := i番目の薬を見たときのAがjグラムでBがkグラムの予算の最小値
	vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(401, vector<int>(401,inf)));
	rep(i, n + 1) dp[i][0][0] = 0;

	rep(i, n) {
		rep(j, 401) {
			rep(k, 401) {
				if (j - a[i] >= 0 && k - b[i] >= 0) {
					if (dp[i][j - a[i]][k - b[i]] != inf) {
						dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
					}
					else {
						dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
					}
				}
				else {
					dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				}
			}
		}
	}

	int ans = inf;
	// ma:mb = j:kとなるものを探す
	for (int j = ma; j <= 400; j += ma) {
		int k = mb * (j / ma);
		if (k > 400) continue;
		if (dp[n][j][k] != inf) {
			ans = min(ans, dp[n][j][k]);
		}
	}
	if (ans == inf) cout << -1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 27264
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;


typedef long long ll;
const ll INF = 1e18;


int main() {
	ll N, K;
	cin >> N >> K;

	vector<ll> P(N + 1), C(N + 1);
	for (int i = 1; i <= N; ++i) cin >> P[i];
	for (int i = 1; i <= N; ++i) cin >> C[i];

	ll ans = -INF;
	for (int s = 1; s <= N; ++s) {
		// find loop
		ll tot = 0, len = 0;
		int x = s;
		vector<bool> visited(N + 1, false);
		while (!visited[x]) {
			visited[x] = true;
			tot += C[x];
			len++;
			x = P[x];
		}

		// search max
		ll now = 0;
		for (int i = 1; i <= len; ++i) {
			x = P[x]; now += C[x];
			if (i > K) break;
			ll sc = now;
			if (tot > 0) sc += ((K - i) / len) * tot;
			ans = max(ans, sc);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3228