akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N;
	long long ans=12345678901234567LL;
	cin >> N;
	vector<long long> A(N);
	for(auto &i:A)cin >> i;
	vector<long long> S(N+1,0);
	for(int i=0;i<N;i++)S[i+1]=S[i]+A[i];
	
	vector<int> Lmin(N+1,1);
	vector<int> Rmin(N+1,N-1);
	for(int i=3;i<N-1;i++){
		int minm;
		long long mind;
		for(int m=Lmin[i-1];m<i;m++){
			long long l=S[m],r=S[i]-S[m];
			if(m==Lmin[i-1]){
				minm=m;
				mind=abs(l-r);
			}
			else if(abs(l-r)<mind){
				minm=m;
				mind=abs(l-r);
			}
			else if(m!=Lmin[i-1])break;
		}
		Lmin[i]=minm;
	}
	
	for(int i=N-2;i>1;i--){
		int minm;
		long long mind;
		for(int m=Rmin[i+1];m>i;m--){
			long long l=S[m]-S[i],r=S[N]-S[m];
			if(m==Rmin[i+1]){
				minm=m;
				mind=abs(l-r);
			}
			else if(abs(l-r)<mind){
				minm=m;
				mind=abs(l-r);
			}
			else if(m!=Rmin[i+1])break;
		}
		Rmin[i]=minm;
	}
	
	for(int i=2;i<N-1;i++){
		vector<long long> PQRS(4);
		PQRS[0]=S[Lmin[i]];
		PQRS[1]=S[i]-S[Lmin[i]];
		PQRS[2]=S[Rmin[i]]-S[i];
		PQRS[3]=S[N]-S[Rmin[i]];
		//for(int j=0;j<4;j++)printf("%lld ",PQRS[j]);
		//cout << *max_element(PQRS.begin(),PQRS.end())-*min_element(PQRS.begin(),PQRS.end()) << endl;
		ans=min(ans,*max_element(PQRS.begin(),PQRS.end())-*min_element(PQRS.begin(),PQRS.end()));
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
#define pb push_back
#define db(x) cerr << #x << " = " << x << endl;
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define vi vector<int>
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define ll long long
#define ull unsigned long long
typedef long double ld;

#define MAXN 112
#define MAXV 1123

int n, w;
int V[MAXN];
ll W[MAXN];
int target;
int vis[MAXN][MAXV * MAXN];
ll dp[MAXN][MAXV * MAXN];

ll solve(int idx, int r)
{
    if (r <= 0)
        return 0;
    
    if (idx == n)
        return r <= 0 ? 0:INF;

    if (vis[idx][r])
        return dp[idx][r];
    vis[idx][r] = 1;

    ll res = min(solve(idx + 1, r), solve(idx + 1, r - V[idx]) + W[idx]);
    return dp[idx][r] = res;
}

int main()
{
    scanf("%d%d", &n, &w);

    for (int i = 0; i < n; i++)
    {
        scanf("%d%d", &W[i], &V[i]);
    }
    int up = 100000;
    int lo = 0;
    int best = -1;

    while (lo <= up)
    {
        int mid = lo + (up - lo)/2;
        if (solve(0, mid) <= w)    
        {
            best = mid;
            lo = mid + 1;
        }
        else
        {
            up = mid - 1;
        }
    }
    
    printf("%d\n", best);
}

Measured memory_bytes: 147840
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll x;
        cin>>x;
        vi v;
        ll a=0,b=0;
        rep(i,0,3300)
        {
            v.pb(i*i*i*i*i);
        }        
        rep(i,0,3300)
        {
            rep(j,i+1,3300)
            {
                if(v[i]+v[j]==x)
                {
                    a=i,b=-j;
                    break;
                }
                else if(v[j]-v[i]==x)
                {
                    a=j,b=i;
                    break;
                }
            }
        }
        cout<<a<<" "<<b<<endl;
    }
    return 0;
}

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (N >= S.length()) {
        cout << S << endl;
    } else {
        cout << S.substr(0, N) << "..." << endl;
    }
}


Measured memory_bytes: 3596
import java.util.*;

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

		int ans = -1000000000;
		int min = stdIn.nextInt();

		for (int i=1; i<n; i++) {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 94152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define pi 3.14159265359
#define INF 1000000000

int main() {
    int N; cin >> N;
    int ans[N+1];
    rep(i, N) {
        int num;
        cin >> num;
        ans[num-1] = i+1;
    }
    rep(i, N) {
        cout << ans[i];
        if (i != N-1) cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll inf = LONG_LONG_MAX / 2 - 1;
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n);
    rep(i, m) {
        ll u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
    }
    ll s, t;
    cin >> s >> t;
    s--; t--;
    vector<vector<ll>> dp(n, vector<ll>(3, inf));
    queue<pair<ll, ll>> q;
    q.push(make_pair(s, 0));
    dp[s][0] = 0;
    while(!q.empty()) {
        pair<ll, ll> p = q.front(); q.pop();
        ll u = p.first;
        ll step = p.second;
        for(auto v : g[u]) {
            ll ns = (step + 1) % 3;
            ll nv = dp[u][step] + ((step == 0) ? 1 : 0);
            if (dp[v][ns] <= nv) continue;
            dp[v][ns] = nv;
            q.push(make_pair(v, ns));
        }
    }
    if (dp[t][0] == inf) {
        cout << -1 << endl;
    }
    else {
        cout << dp[t][0] << endl;
    }
    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    int N = inputValue();
    set<int> s;
    string ans = "YES";
    REP(i, N){
        int v = inputValue();
        if(s.find(v) != s.end()){
            ans = "NO";
            break;
        };
        s.insert(v);
    }
    cout << ans << endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n, m; 
int ax[100], ay[100],bx[100], by[100];
int calDist(int x1, int y1, int x2, int y2){
	return (abs(x1-x2) + abs(y1-y2));
}
int main(){
	cin>>n>>m;
	for(int i = 0; i < n; ++i)
		cin>>ax[i]>>ay[i];
	for(int i = 0; i < m; ++i)
		cin>>bx[i]>>by[i];
	for(int i = 0; i < n; ++i){
		int best = INF;
        int ans = INF;
		for(int j = 0; j<m; ++j){
			int cur = calDist(ax[i], ay[i], bx[j], by[j]);
			if(cur < best){
				best = cur;
				ans = j;
			}
		}
		cout<<ans + 1 <<endl;
	}
	return 0;
}

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

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	int temp[n+m];
	int ctr=0;
	int odd=1;
	int even=2;
	int ctr1=0;
	for(int i=0; i<n; i++){
		temp[ctr++]=even;
		even+=2;
	}
	for(int i=0; i<m; i++){
		temp[ctr++]=odd;
		odd+=2;
	}
	for(int i=0; i<n+m; i++){
		for(int j=i+1; j<m+n; j++){
		int tott=temp[i]+temp[j];
		if(tott%2==0){
			ctr1++;
		}		
		}
	}
	
	printf("%d\n", ctr1);
	return 0;
}



Measured memory_bytes: 1732
N=int(input())
from math import sqrt
L=[]
for i in range(1,int(sqrt(N))+1):
    if N%i==0:
        L.append((i,N//i))
ans=float("INF")
for t in L:
    a,b=t
    now=max(len(str(a)), len(str(b)))
    ans=min(ans, now)

print(ans)
#print(L)

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-


def gcd(m, n):
    return m if n == 0 else gcd(n, m % n)


def lcm(m, n):
    return m * n // gcd(m,n)


def main():
    n = int(input())
    t = []
    for i in range(n):
        tmp = int(input())
        t.append(tmp)
    ans = t[0]
    for i in t:
        ans = lcm(ans, i)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

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

	int max = n - d;

	if (d == 0)
	{
		cout << OF64 << (double)(m - 1) / (double)(n) << endl;
		return 0;
	}
	cout << OF64 << (double)(2 * (m - 1)*(n - d)) / (double)(n*n) << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
from itertools import accumulate
import sys
sys.setrecursionlimit(10**6)
mo=10**9+7

#n=int(input())  
n,l=map(int,input().split())
#a=[int(i) for i in input().split()]
a=[l+i-1 for i in range(1,n+1)]
if 0 in a:
    ans=sum(a)
elif l>0:
    ans=sum(a)-l
else:
    ans=sum(a)-(l+n-1)
    
print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>

#define N_MAX 100000

using namespace std;

int main(){
    int p[N_MAX];
    int like2017[N_MAX];
    bool isPrime[N_MAX];
    int num_p = 0;
    int num_like = 0;
    int Q;
    cin >> Q;
    fill(isPrime, isPrime+N_MAX, true);
    //エラトステネスのふるい
    for(int i = 2; i*i < N_MAX;i++){
        if(isPrime[i]){
            for(int j = 2; i*j < N_MAX; j++){
                isPrime[i*j] = false;
            }
        }
    }
    for(int i = 3; i< N_MAX;i+=2){
        if(isPrime[i] && isPrime[(i+1)/2]){
            like2017[num_like] = i;
            num_like++;
        }
    }
    for(int i = 0; i < Q; i++){
        int l, r;
        cin >> l >> r;
        int* l_index = lower_bound(like2017, like2017+num_like, l);
        int* r_index = lower_bound(like2017, like2017+num_like, r);
        
        if(*r_index == r){
            cout << r_index - l_index + 1 << endl;
        }else{
            cout << r_index - l_index << endl;
        }
    }
}

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

int main(){
    int r, c;
    cin >> r >> c;
    int a[101][101] = {};
    for(int i = 0 ; i < r ; i++){
        for(int j = 0 ; j < c ; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0 ; i < r ; i++){
        for(int j = 0 ; j < c ; j++){
            a[r][c] = a[r][c] + a[i][j];
        }
    }
    for(int i = 0 ; i < r ; i++){
        int s = 0;
        for(int j = 0 ; j < c ; j++){
            s = s + a[i][j];
            a[i][c] = s;
        }
    }
    for(int j = 0 ; j < c ; j++){
        int s = 0;
        for(int i = 0 ; i < r ; i++){
            s = s + a[i][j];
            a[r][j] = s;
        }
    }
    for(int i = 0 ; i <= r ; i++){
        for(int j = 0 ; j <= c ; j++){
            if(j) cout << " ";
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0;
}



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

int main() {
  int N;
  long long ans=0;
  cin >> N;
  
  for (int i=0; i<N; i++) {
    for (int j=0; j<N/(i+1); j++) {
      if ((i+1)*(j+1) < N) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;

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

    string res = "YES";

    //2で割れれば良い
    vector <ll> a(N);

    ll gcnt = 0;
    ll kcnt = 0;
    ll tmp;

    REP(i,N)
    {
        cin >> a[i];
        if(a[i] % 2 == 0)gcnt++;
        else kcnt++;
    }

    //kcnt2個でgcnt1個
    if(kcnt % 2 != 0)res = "NO";

    cout << res << endl;

}

Measured memory_bytes: 1024
Size = 3

A = [list(map(int, input().split())) for _ in range(Size)]
n = int(input())

for _ in range(n):
    b = int(input())
    for i in range(Size):
        for j in range(Size):
            if A[i][j] == b:
                A[i][j] = 0

bingo = False
for row in A:
    if sum(row) == 0:
        bingo = True
for col in zip(*A):
    if sum(col) == 0:
        bingo = True
if sum(A[i][i] for i in range(Size)) == 0:
    bingo = True
if sum(A[i][Size - 1 - i] for i in range(Size)) == 0:
    bingo = True

print("Yes" if bingo else "No")


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

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

  string ans = "";
  while(n != 0){
    int r = n % 2;
    if(r < 0) r += 2;
    n = (n-r)/(-2);

    ans += (char)('0' + r);
  }

  reverse(all(ans));
  if(ans == "") ans = "0";

  cout << ans << endl;

}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        Console.WriteLine(a == b && b == c ? "Yes" : "No");
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>a(n),b(n),c(n);
    int sum=0;
    rep(i,n)cin>>a[i];
    rep(i,n){
        cin>>b[i];
        sum+=b[i];
    }    
    rep(i,n-1)cin>>c[i];
    rep(i,n-1){
        if(a[i]+1==a[i+1]){
            sum+=c[a[i]-1];
        }
    }
    cout<<sum<<endl;
    return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;

int main(){
    int n; cin >> n;
    int mini = 1e9, maxi = -1e9;

    REP(i, n){
        int x; cin >> x;
        mini = min(mini, x);
        maxi = max(maxi, x);
    }
    cout << maxi - mini;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    vector<int> a(5);
    for(int i = 0; i < 5; i++) cin >> a[i];
    int k;
    cin >> k;
    for(int i = 0; i < 4; i++){
        for(int  j = 0; j < 5; j++){
            if(i == j) continue;
            if(abs(a[i]-a[j]) > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 256
inp = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
l = inp.shift().split(' ')
K = l[0] * 1
S = l[1] * 1 
cnt = 0
for (i=0; i<=K; i++) {
  for (j=0; j<=K; j++) {
      t = S - (i + j)
      if (t >= 0 && t <= K) {
          cnt++
      } 
  }
}
console.log(cnt)


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

string IntToString(int number)
{
	stringstream ss;
	ss << number;
	return ss.str();
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int n;

int main()
{
    ci >> n;

    llint sum = 0;
    for(int i = 1; i <  n; i++) sum += i;


    co << sum - n / 2 << en;

    if(n % 2 == 0) {
	for(int i = 1; i < n; i++) {
	    for(int j = i + 1; j <= n; j++) {
		if(i + j == n + 1) continue;
		co << i << ' ' << j << en;
	    }
	}
    } else {
	for(int i = 1; i < n; i++) {
	    for(int j = i + 1; j <= n; j++) {
		if(i + j == n) continue;
		co << i << ' ' << j << en;
	    }
	}
    }
    
    return 0;
}



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

int main()
{
    int A, B, C, max, lac;
    cin >> A >> B >> C;

    max = A;
    if (max < B)
        max = B;
    if (max < C)
        max = C;
        
    lac = max * 3 - A - B - C;
    if (lac % 2 == 1)
        lac += 3;

    cout << lac / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int dp[260000]={0};

int main(){
	for(int i=2; i<260000; i++){
		bool flag = true;
		for(int j=2; j<i; j++){
			if(i%j==0){
				flag = false;
				break;
			}
		}
		if(flag) dp[i]=1;
	}
	dp[2]=1;

	while(1){
		int n; cin >> n;
		if(!n) break;
		int count=0;
		for(int i=n+1; i<=2*n; i++){
			count+=dp[i];
		}
		cout << count << endl;
	}
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef long long llint;
typedef vector<long long int> vint;
typedef vector< vector<int> > vvint;
typedef vector<string> vstr;


int main(void) {
	int A, P,n;
	cin >> A >> P;
	n = 3 * A + P;
	cout << n / 2 << endl;
}


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

int main(){
  int a,b;
  cin >> a;
  cin >> b;
  if(a!=1&&b!=1)
    cout<<"1"<<endl;
  else if(a!=2&&b!=2)
    cout<<"2"<<endl;
  else
    cout<<"3"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll P = 1e9+7;
const ll N = 1e6+7;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll t=1;
	// cin>>t;

	while(t--){
		ll n;
		cin>>n;
		vector<ll> a(n),b(n);
		for (ll i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (ll i = 0; i < n; i++) {
			cin >> b[i];
		}
		
		reverse(b.begin(),b.end());
		
		ll lpt = 0, rpt = n - 1;
		
		for (ll i = 0; i < n; i++) {
			if (a[i] == b[i]) {
				if (b[lpt] != b[i] && a[lpt] != b[i]) {
					swap(b[i], b[lpt]);
					++lpt;
				} else if (b[rpt] != b[i] && a[rpt] != b[i]) {
					swap(b[i], b[rpt]);
					--rpt;
				} else {
					cout << "No\n";
					return 0;
				}
			}
		}
		
		for (ll i = 0; i < n; i++) {
			if (a[i] == b[i]) {
				cout << "No\n";
				return 0;
			}
		}
		
		cout << "Yes\n";
		for (ll i = 0; i < n; i++) {
			cout << b[i] << " ";
		}
		cout << '\n';
		
	}

	return 0;
}	


Measured memory_bytes: 6284
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

#define STR_MAX    (100000)

int main(void)
{
    char s[STR_MAX];
    const char exp[2] = { '0', '1' };

    scanf("%s", s);

    uint64_t ptr = 0;
    char c;

    uint64_t cnt = 0;

    while ( (c = s[ptr]) != '\0' ) {
        cnt += (( c == exp[(ptr & 0x1)] ) ? 1 : 0);
        ptr++;
    }

    uint64_t ans = ( cnt >= (ptr - cnt) ) ? ptr - cnt : cnt;

    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Deg fprintf(stderr,"Passing [%s] line %d\n",__FUNCTION__,__LINE__)
typedef long long LL;
const int maxn=110000;
const int inf=1e9+7;
int n,k;
int a[maxn];
int Abs(int x)
{
	if(x<0) return -x;
	return x;
}
int main()
{
	scanf("%d%d",&n,&k);
	a[0]=-inf;
	a[n+1]=inf;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int pos=-1;
	for(int i=1;i<=n+1;i++)
	{
		if(a[i-1]<=0&&0<=a[i]) pos=i;
	}
	if(a[pos-1]==0)
	{
		k--;
		for(int i=pos;i<=n;i++) a[i-1]=a[i];
		n--;
		pos--;
	}
	for(int i=0;i<=n+1;i++) a[i]=Abs(a[i]);
	int ma=pos-1;
	int mb=n-pos+1;
	int ans=inf;
	if(ma>=k) ans=min(ans,a[pos-k]);
	if(mb>=k) ans=min(ans,a[pos+k-1]);
	for(int i=1;i<=ma;i++)
	{
		if(k-i>mb||k-i<1) continue;
		int A=a[pos-i];
		int B=a[pos+k-i-1];
		if(A>B) swap(A,B);
		ans=min(ans,A*2+B);
	}
	printf("%d\n",ans);
	return 0;
	return 0;
}


Measured memory_bytes: 640
def validate(A, B, K):
    for n in range(A, B + 1):
        if n % K == 0:
            return True
    return False


def main():
    K = int(input())
    A, B = list(map(int, input().split(' ')))
    if validate(A, B, K):
        print('OK')
    else:
        print('NG')


if __name__ == '__main__':
    main()


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

int main() {
        long long w, a, b;
        cin >> w >> a >> b;

        if ((a<=b && b<=a+w) || (b<=a && a<=b+w)) {
                cout << 0 << endl;
        } else {
                if (b>a) {
                        cout << b-a-w << endl;
                } else {
                        cout << a-b-w << endl;
                }
        }
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y;
    cin>>x>>y;
    int res=0;
    res+=max((4-x)*100000,0LL)+max((4-y)*100000,0LL);
    if(x==1&&y==1){
        res+=400000;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int tmp = 1;
  
  for(int i; i<N; i++){
    int a, b;
    a = tmp * 2;
    b = tmp + K;
   	if (a<b){
      tmp = a;
    }
    else{
      tmp = b;
    }
  }
  cout << tmp << endl;
}

Measured memory_bytes: 256
import copy
from collections import deque
H,W=map(int, input().split())
A=[[-1]*W for _ in range(H)]
d=deque()
for h in range(H):
  s=input()
  for w in range(W):
    if s[w]=='.':
      pass
    else:
      A[h][w]=0
      d.append((h,w))

DIF=[(1,0),(0,1),(-1,0),(0,-1)]
while d:
  point=d.popleft()
  for dif in DIF:
    x=point[0]+dif[0]
    y=point[1]+dif[1]
    if 0<=x<H and 0<=y<W and A[x][y]==-1:
      d.append((x,y))
      A[x][y]=A[point[0]][point[1]]+1
ans=0    
for h in range(H):
  Amax=max(A[h])
  ans=max(ans,Amax)
#print(A)
print(ans)

Measured memory_bytes: 84060
import numpy as np
n,k=map(int,input().split())

d=[]
a=[]
sunuke=np.zeros(n)

for _ in range(k):
    d=int(input())
    a=list(map(int,input().split()))
    for j in range(d):
        e=a[j]
        sunuke[e-1]=1
ans=0
for i in range(n):
    if sunuke[i]!=1:
        ans+=1
print(ans)


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

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

  int wcnt[N];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'W') {
      sum++;
    }
    wcnt[i] = sum;
  }
  cout << endl;

  int minv = 1e9;
  for (int i = 0; i < N; i++) {
    int l = (i == 0 ? 0 : wcnt[i - 1]);
    int r = (N - i - 1) - (wcnt[N -1] - wcnt[i]);
    minv = min(minv, r + l);
  }
  cout << minv << endl;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int s[n];
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    
    int q;
    cin >> q;
    int t[q];
    for (int i = 0; i < q; i++)
    {
        cin >> t[i];
    }

    int cnt = 0;    
    for (int i = 0; i < q; i++)
    {
       
        int check = lower_bound(s, s + n, t[i]) - s;
        if(check != n && s[check] == t[i]) cnt ++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3660
import bisect

n,m = map(int,input().split())
pos = list(map(int,input().split()))
q = int(input())
l = list(map(int,input().split()))

pos.append(n+1)
d = [pos[i+1]-pos[i]-1 for i in range(m)]
d.sort()
s = [0]*(m+1)
for i in range(len(d)):
    s[i+1] = s[i]+d[i]

for lim in l:
    ok = n+1
    ng = 0
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        idx = bisect.bisect_left(d,mid)
        cost = (s[-1]-s[idx]) - (m-idx)*(mid-1) + (pos[0]-1)
        if cost <= lim:
            ok = mid
        else:
            ng = mid
    if ok <= n:
        print(ok)
    else:
        print(-1)



Measured memory_bytes: 19988
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            double t = in.nextDouble();
            double x = in.nextDouble();

            out.print(t / x);
        }

    }
}



Measured memory_bytes: 23252
ABC = input().split()

A = ABC[0]
B = ABC[1]
C = ABC[2]

if A==B:
	if B==C:
		print("No")
	else:
		print("Yes")
	exit()

if B==C:
	if A==C:
		print("No")
	else:
		print("Yes")
	exit()

if A==C:
	if B==C:
		print("No")
	else:
		print("Yes")
	exit()

print("No")	


Measured memory_bytes: 3060
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
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))

n = inp()
a = inpl()
for j in a:
    if j % 2:
        continue
    if j % 3 == 0 or j % 5 == 0:
        continue
    print('DENIED')
    break
else:
    print('APPROVED')

Measured memory_bytes: 64748
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer k = sc.nextInt();
		String s = sc.next();
		
		if(s.length() <= k) {
			System.out.println(s);
		} else {
			System.out.println(s.substring(0, k) + "...");
		}
	}
}

Measured memory_bytes: 38584
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    int a,b,c;cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b << '\n';
    return 0;
}
/*
 *!!CHECK!! 
 * 制約をよく読め：まず最も愚直な解法を考えろ
 * intの掛け算をしてる場合：overflowは大丈夫？
 * 制約の下限・上限は大丈夫？
 * 木構造は一直線にした時TLEしない？
 * */


Measured memory_bytes: 256
#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() {
  string latter;
  cin >> latter;
  int q;
  cin >> q;
  string prev;

  rep(i, q){
    int t;
    cin >> t;
    if(t == 1){
      swap(prev, latter);
    } else {
      int f; char c;
      cin >> f >> c;
      if(f == 1) {
        prev += c;
      }else {
        latter += c;
      }
    }
  }
  reverse(prev.begin(), prev.end());
  prev += latter;
  cout << prev  << endl;
  return 0;
}

Measured memory_bytes: 1128
#include<stdio.h>
#define N 1000000
struct{int a[6];}data[N];

int main(){
    int i,j,L;
    double a,b,c,d,e,f;
    double x,y;
    for(i=0; i<N; i++){
        for(j=0;j<6;j++)
            if(scanf("%d",&data[i].a[j])==EOF)break;
        if(j==0)break;
    }
    L=i;
    for(i=0;i<L;i++){       
        a=data[i].a[0]; b=data[i].a[1]; c=data[i].a[2]; d=data[i].a[3]; e=data[i].a[4]; f=data[i].a[5];
        x=(1/(a*e-b*d))*(e*c-b*f);
        y=(1/(a*e-b*d))*(a*f-d*c);
        if(x==-0)x=0;
        if(y==-0)y=0;
        printf("%4.3f %4.3f\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 2644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,K;
ll a[5001];

bool dp[5002][5002];

bool DP[5002][5002];

bool check(bool a[5002],bool b[5002],ll left,ll right){
  int l=K;
  for(int i=0;i<=K;i++){
    if(!a[i])continue;
    while(!b[l]||i+l>=right){
      l--;
      if(l<0)return false;
    }
    if(left<=i+l)return true;
  }
  return false;
}

void solve(){
  dp[0][0]=true;
  for(int i=1;i<=N;i++){
    for(int j=0;j<=K;j++){
      dp[i][j]=dp[i-1][j];
      if(j-a[i]>=0)dp[i][j]|=dp[i-1][j-a[i]];
    }
  }

  DP[N+1][0]=true;
  for(int i=N;i>=1;i--){
    for(int j=0;j<=K;j++){
      DP[i][j]=DP[i+1][j];
      if(j-a[i]>=0)DP[i][j]|=DP[i+1][j-a[i]];
    }
  }

  int ans=0;
  for(int i=1;i<=N;i++){
    if(check(dp[i-1],DP[i+1],K-a[i],K)){
      
    }    else {
      ans++;
    }
  }
  cout<<ans<<endl;
}

int main(){
  cin>>N>>K;
  for(int i=1;i<=N;i++){
    cin>>a[i];
  }
  sort(a+1,a+N+1);
  solve();
  return 0;
}


Measured memory_bytes: 49152
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#include<cstdio>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include<set>
#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)
#define INF9                1000000010
#define INF18               1000000000000000010
#define dist(ax,ay,bx,by)   sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
#define gcd(a,b)            __gcd(a,b)
#define lcm(a,b)            (a*b)/__gcd(a,b)
#define m_p(a,b)            make_pair(a,b)
#define sqr(a)              ((a)*(a))
#define pb                  push_back
#define bpll(a)             __builtin_popcountll(a)
#define MX                  1000000
#define PI                  acos(-1)
#define mod                  1000000007
#define cnt_bin(n)          __builtin_clzll(0ll) - __builtin_clzll(n)

typedef long long lli;
using namespace std;

deque<lli>v;

int main()
{
    lli n, k;
    scanf("%lld %lld", &n, &k);

    for(lli i=0; i<n; i++)
    {
        lli a;
        scanf("%lld", &a);
        v.push_back(a);
    }

    lli cur=1;
    lli prev=1;

    for(lli i=0; i<k; i++)
    {
        cur*=v[i];
    }


    while(v.size()>=k+1)
    {
        if(v.front()<v[k]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        v.pop_front();
    }

    return 0;
}


Measured memory_bytes: 5336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int A,B,C;
cin>>A>>B>>C;
if(A>=B && A>=C){
  cout<<B+C<<"\n";
}
else if(B>=A && B>=C){
  cout<<A+C<<"\n";
}
else{
  cout<<A+B<<"\n";
}
return 0;
}


Measured memory_bytes: 256
S = input()
S = [e for e in S]
T = input()
T = [e for e in T]
restorable = False
for i in range(len(S)-len(T)+1)[::-1]:
    sub_S = S[i:i+len(T)]
    flag = True
    for s,t in zip(sub_S,T):
        if s != '?':
            if s != t:
                flag = False
                break
    if flag:
        restorable= True
        for j in range(i,i+len(T)):
            S[j] = T[j-i]
        break
if not restorable:
    print('UNRESTORABLE')
    exit()
for i in range(len(S)):
    if S[i] == '?':
        S[i] = 'a'
print("".join(S))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
long gcd(long a, long b) {return b % a ? gcd(b % a, a) : a;}
long lcm(long a, long b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    long a, b, c, k;
    cin >> a >> b >> c >> k;
    long s = k % 2 ? 1 : -1;
    cout << (b - a) * s << endl;
}


Measured memory_bytes: 764
#include <stdio.h>
#define max 100000
#define nil -1

typedef struct{
  int parent;
  int leaf;
  int right;
}node;

node t[max];
int n;

int dep(int id, int c){
  int i, depth = 0;
  if(t[id].parent != nil){
    depth = dep(t[id].parent, c);
    return depth+1;
  }
  else return 0;
}

int main(void){
  int i, j, id, k, c, sibling;
  scanf("%d", &n);

  //init
  for(i = 0; i < n; i++)
    t[i].parent = t[i].leaf = t[i].right = nil;

  //maketree
  for(i = 0; i < n; i++){
    scanf("%d%d", &id, &k);
    for(j = 0; j < k; j++){
      //for first time
      scanf("%d", &c); //1つの子ノードのid
      if(j == 0){
        t[c].parent = id; //親ノードのidを設定
        t[id].leaf = c; //自分の子を設定
        sibling = c; //次に作る子の兄弟はc
      } else {
        t[sibling].right = c; //前の子の次はc

        t[c].parent = id;
        sibling = c;
      }
    }
  }

  //printtree
  for(i = 0; i < n; i++){
    printf("node %d: ", i);
    printf("parent = %d, ", t[i].parent);
    printf("depth = %d, ", dep(i, 0));

    if(t[i].parent == nil)
      printf("root, [");

    else if(t[i].leaf != nil)
      printf("internal node, [");
    else{
      printf("leaf, []\n");
      continue;
    }
    if(t[i].leaf != nil){
      printf("%d", t[i].leaf);
      c = t[i].leaf;
    }
    else c = i;
    while(t[c].right != nil){
        printf(", %d", t[c].right);
        c = t[c].right;
    }
    printf("]\n");
  }

  return 0;
}

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

int main() {
	int n,k;
	int snukes[100]={0};
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int d;
		cin>>d;
		for(int i=0;i<d;i++) {	
			int a;
			cin>>a;
			snukes[a-1]+=1;
		}
	}
	int counts=0;
	for(int i=0;i<n;i++) if(snukes[i] == 0) counts++;
	cout<<counts;
	return 0;
}

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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<int> a(n),b(m);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	for(int i=0;i<101;i++){
		if(a[n-1]<i && i<=b[0] && i>x && i<y){
			cout<<"No War";
			return 0;
		}
	}
	cout<<"War";
}

Measured memory_bytes: 3596
l, r = list(map(int, input().split()))
ls = []
for i in range(l, (min((r + 1), (l + 2019)) - 1)):
    for j in range(i + 1, min((r + 1), (l + 2019))):
        ls.append(((i * j) % 2019))
print(min(ls))


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

int main(){
  int N;
  cin >> N;
  vector<pair<int, int>> edges;
  vector<vector<int>> G(N);
  for (int i=0; i<N-1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G.at(a).emplace_back(b);
    G.at(b).emplace_back(a);
    edges.emplace_back(a, b);
  }
  int K = 0;
  for (int i=0; i<N; i++) {
    if (G.at(i).size() > K) K = G.at(i).size();
  }
  map<pair<int, int>, int> I;
  queue<int> checklist;
  vector<int> used(N, 0);
  vector<int> rootcol(N);
  checklist.push(0);
  used.at(0) = 1;
  rootcol.at(0) = 0;
  while (!checklist.empty()) {
    int v = checklist.front();
    checklist.pop();
    int col = 0;
    for (int p : G.at(v)) {
      if (used.at(p)) continue;
      col++;
      if (col == rootcol.at(v)) col++;
      I[make_pair(v, p)] = col;
      I[make_pair(p, v)] = col;
      rootcol.at(p) = col;
      used.at(p) = 1;
      checklist.push(p);
    }
  }
  cout << K << endl;
  for (auto e : edges) {
    cout << I[e] << endl;
  }
}

Measured memory_bytes: 23284
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(){
    fastcin();

    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    vector<int> ans;
    int prv = -INF;
    rep(i, n){
        if(s[i] == 'o' && i > prv+c){
            ans.push_back(i);
            prv = i;
        }
    }
    if(ans.size() > k) return 0;

    int m = ans.size();
    int rem = c, nxt = 0;
    vector<int> res;
    for(int i=m-1; i>=0; i--){
        // cout << ans[i] << "!" << rem << endl;
        rep1(j, rem){
            if(ans[i]+j < n && s[ans[i]+j] == 'o'){
                nxt = j;
            }
        }
        if(nxt == 0) res.push_back(ans[i]);
        if(i > 0) rem = max(0, ans[i]-ans[i-1]+nxt-c);
        nxt = 0;
    }
    sort(all(res));
    repe(i, res) cout << i+1 << endl;
}

Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
 
//long long
using ll = long long;
 
// pair<int, int>
using PII = pair<int, int>;
 
//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
 
//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()
 
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
 
//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}
 
// a = max(a, b), a = min(a, b)
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; }
 
// 階乗(MODをとる)
ll pow_mod(ll num, ll pow, ll mod) {
    ll prod = 1;
    num %= mod;
    while (pow > 0) {
        if (pow & 1) prod = prod * num % mod;
        num = num * num % mod;
        pow >>= 1;
    }
    return prod;
}
 
 
 
// 二項係数(MODとる、1 ≦ k ≦ n ≦ 10^7 程度)
// COMinit()
// COM(x, y)
// とコンビで使う
 
// テーブルを作る前処理
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N;
    cin >> N;
    bool flag = true;
 REP(i, N){
     int x;
     cin >> x;
     if(x & 1) flag = false;
 }

 flag ? print("second") : print("first");

}

Measured memory_bytes: 256
/*
author : @timepasser00
date   :
										*/

#include<bits/stdc++.h>
#define ll long long
#define nl '\n'
#define sp " "
#define mod 1000000009
#define pb push_back
#define mk make_pair
#define speedup ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

// void solve()
// {

// }

int main()
{
	// freopen("i1.txt", "r", stdin); //redirects standard input
	// freopen("o1.txt", "w", stdout); //redirects standard output

	speedup

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

	int ans = (n * (n - 1)) / 2 + (m * (m - 1)) / 2;
	cout << ans  << endl;

}







Measured memory_bytes: 256
// (c) 2020, redotter

// Roses are red
// The Tardis is blue
// The Doctor once said
// Rose Tyler...

#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#pragma comment(linker, "/stack:500000000")
#endif

#define pb push_back
#define the(a) (a).begin(), (a).end()
#define ft first
#define sd second
#define endl "\n"
#define forn(i, n) for (int i = 0; i < (n); i++)
#define forr(i, s, n) for (int i = (s); i < (n); i++)

using i64 = long long;
using i32 = int;
using f64 = long double;

template <class T> using vec = vector<T>;
using str = string; using p64 = pair<i64, i64>;
using v64 = vec<i64>; using vv64 = vec<v64>;
using s64 = set<i64>; using m64 = map<i64, i64>;
template <size_t Size1> using a64 = array<i64, Size1>;
template <size_t Size1, size_t Size2> using aa64 = array<a64<Size2>, Size1>;
template <class T> using hash_set = unordered_set<T>;
template <class T, class U> using hash_map = unordered_map<T, U>;

mt19937 gen(998244353);
const i64 inf = numeric_limits<i64>::max() / 2;

template <class T> inline i64 len(const T& a) { return (i64)(a.size()); }
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <class T, class S>
inline bool check_min(T& a, S b) { if (a > b) return a = b, 1; return 0; }
template <class T, class S>
inline bool check_max(T& a, S b) { if (a < b) return a = b, 1; return 0; }

void read() {}
template<class T, class ...U>
void read(T& a, U& ...b) { cin >> a; read(b...); }
void print() {}
template<class T, class ...U>
void print(const T& a, const U& ...b) { cout << a << " "; print(b...); }
void println() { cout << "\n"; }
template<class T, class ...U>
void println(const T& a, const U& ...b) { cout << a << " "; println(b...); }

struct Problem {
	void files(str in, str out) {
#ifdef ONLINE_JUDGE
		freopen(in.c_str(), "r", stdin), freopen(out.c_str(), "w", stdout);
#endif
	}
	void solve(), input();
	void many() { i32 t; cin >> t; while (t--) input(), solve(); }
	void make(bool mt = 0) { if (mt) many(); else input(), solve(); }
} problem;

signed main() {
	fast();
	problem.make();
#ifdef _DEBUG
	println(); println("[finished]"); system("pause > nul");
#endif
	return 0;
}

i64 n, k;
v64 a;

void Problem::solve() {
	v64 dp(n, inf);
	dp[0] = 0;
	forr(i, 1, n) {
		forr(j, max(i - k, 0ll), i) {
			check_min(dp[i], dp[j] + abs(a[j] - a[i]));
		}
	}
	println(dp[n - 1]);
}

void Problem::input() {
	read(n, k);
	a.resize(n);
	forn(i, n) read(a[i]);
}


Measured memory_bytes: 4788
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll H, W;
    cin >> H >> W;

    ll D;
    cin >> D;

    vector<ll> A(H * W);
    rep(i, H * W) cin >> A[i];
    
    ll Q;
    cin >> Q;
    vector<ll> L(Q), R(Q);
    rep(i, Q) cin >> L[i] >> R[i];
    

    vector<ll> a2p(H * W + 1);
    rep(i, A.size()) {
        a2p[A[i]] = i;
    }

    // 一番小さい値から iに行くまでのコストc[i];
    vector<ll> c(H * W + 1);
    repi(v, c.size()) {
        if (c[v] > 0) {
            continue;
        }

        for (ll j = 1; v + j * D < c.size(); j++) {
            ll v1 = v + (j-1) * D;
            ll v2 = v + j * D;
            ll ind1 = a2p[v1];
            ll ind2 = a2p[v2];
            ll x1 = ind1 % W;
            ll y1 = ind1 / W;
            ll x2 = ind2 % W;
            ll y2 = ind2 / W;
            c[v2] = c[v1] + abs(x1-x2)+abs(y1-y2);
        }
    }

    rep(i, Q) {
        ll res = c[R[i]] - c[L[i]];
        put(res);
    }
}
signed main(){ Main();return 0;}

Measured memory_bytes: 6916
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int findDigitSum(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
    return sum;
}

int main(void){
    int n;cin>>n;
    int min = 100000;
    for(int i=1;i<n;i++){
        int j=n-i;
        int sum=findDigitSum(i)+findDigitSum(j);
        if(min>sum)min=sum;
    }
    cout<<min<<endl;
}



Measured memory_bytes: 764