akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>

 static int N=100;

int main(){
  int i,l,j,k,n,p[N+1],m[N+1][N+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
  }

  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=1<<21;
      for(k=i;k<=j-1;k++){
	m[i][j]=fmin(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
 
  printf("%d",m[1][n]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2048
from itertools import groupby

n, k = map(int, input().split())

D = {
    'L': 0,
    'R': 0
}

for val, it in groupby(input()):
    D[val] += 1

u = max([1, D['L'] + D['R'] - 2 * k])

print(n - u)


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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int total_red = 0,total_white = 0;
	vector<int> cumm_red(n+1);
	vector<int> cumm_white(n+1);
	for(int i = 1;i <= n ;i++) {
		if(s[i-1] == 'W')
			cumm_white[i] = cumm_white[i-1]+1;
		else
			cumm_white[i] = cumm_white[i-1];
		if(s[i-1] == 'R')
			cumm_red[i] = cumm_red[i-1]+1;
		else
			cumm_red[i] = cumm_red[i-1];
	}
	total_red = cumm_red[n];
	total_white = cumm_white[n];
	int result = cumm_white[n];
	for(int i = 0;i< n;i++)
		result = min(result,max(total_red-cumm_red[i],cumm_white[i]));
	cout << result << endl;

	return 0;
}

Measured memory_bytes: 5244
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0;i<n;i++){
        cin >> arr[i];
    }
    vector<int> dp(n,INT_MAX);
    dp[0] = 0;
    for(int i = 0;i<n;i++){
        for(int j=1;j<=k && i+j<n;j++){
            dp[i+j] = min(dp[i+j],dp[i] + abs(arr[i] - arr[i+j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
ll a,b,c,d;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

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

    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d)<<newl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;
double ab,ac,bc;
double ak,bk,ck,as,bs,cs;
bool heron(){
    double sta;
    double wa = 0.0;
    double S,s;
    bool f1=false,f2=false; 
    /*sta*/
    s = (ab+ac+bc)*0.5;
    S = sqrt(s * (s-ab) * (s-ac) * (s-bc));
    sta = S;

    /*wa*/
    s = (ab+ak+bk)*0.5;
    S = sqrt(s*(s-ab)*(s-ak)*(s-bk));
    wa += S;
    s = (ac+ak+ck)*0.5;
    S = sqrt(s*(s-ac)*(s-ak)*(s-ck));
    wa += S;
    s = (bc+bk+ck)*0.5;
    S = sqrt(s*(s-bc)*(s-bk)*(s-ck));
    wa += S;
    if(fabs(sta-wa) <= 0.01)f1 = true;
    wa = 0.0;

    s = (ab+as+bs)*0.5;
    S = sqrt(s*(s-ab)*(s-as)*(s-bs));
    wa += S;
    s = (ac+as+cs)*0.5;
    S = sqrt(s*(s-ac)*(s-as)*(s-cs));
    wa += S;
    s = (bc+bs+cs)*0.5;
    S = sqrt(s*(s-bc)*(s-bs)*(s-cs));
    wa += S;
    if(fabs(sta-wa) <= 0.01)f2 = true;

    if((f1 && f2) || (!f1 && !f2))return false;
    else return true;
}
int main(){
    int hoge;
    scanf("%d",&hoge);
    while( hoge-- ){
        double xa,ya,xb,yb,xc,yc,xk,yk,xs,ys;
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&xa,&ya,&xb,&yb,&xc,&yc,&xk,&yk,&xs,&ys);
        ab = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
        ac = sqrt((xa-xc)*(xa-xc) + (ya-yc)*(ya-yc));
        bc = sqrt((xb-xc)*(xb-xc) + (yb-yc)*(yb-yc));
        ak = sqrt((xa-xk)*(xa-xk) + (ya-yk)*(ya-yk));
        bk = sqrt((xb-xk)*(xb-xk) + (yb-yk)*(yb-yk));
        ck = sqrt((xc-xk)*(xc-xk) + (yc-yk)*(yc-yk));
        as = sqrt((xa-xs)*(xa-xs) + (ya-ys)*(ya-ys));
        bs = sqrt((xb-xs)*(xb-xs) + (yb-ys)*(yb-ys));
        cs = sqrt((xc-xs)*(xc-xs) + (yc-ys)*(yc-ys));
        bool f = heron();
        (f) ? puts("OK") : puts("NG");
    }
    return 0;
}

Measured memory_bytes: 1208
def solve():
  N, K = map(int, input().split())
  R, S, P = map(int, input().split())
  dic = {'r':P,'s':R,'p':S}
  T = input()
  point = [0]*N
  for i in range(N):
    if i<K:
      point[i] = dic[T[i]]
    else:
      if T[i]!=T[i-K] or point[i-K]==0:
        point[i]=dic[T[i]]
  ans = sum(point)
  return ans
print(solve())

Measured memory_bytes: 9972
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n;
	string s1,s2,s3;
	cin>>n>>s1;
	s2=s1.substr(0,s1.length()/2);
	s3=s1.substr(s1.length()/2,s1.length());

	if(s2==s3){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}



Measured memory_bytes: 256
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

const MOD: usize = 1000000007;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut ans = 1;
    let mut dp = [0; 3];

    for &e in &a {
        let mut flag = false;
        let mut cnt = 0;
        for i in 0..3 {
            if dp[i] == e {
                cnt += 1;
                if !flag {
                    flag = true;
                    dp[i] += 1;
                }
            }
        }

        ans *= cnt;
        ans %= MOD;
    }

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


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

using namespace std;

vector<string> v;
char buf[5002];
int main(){
    scanf("%s",buf);
    string s=buf;
    for(int i=0;i<s.size();i++){
        for(int j=i;j<s.size()&&j<i+7;j++){
            v.push_back(s.substr(i,j-i+1));
        }
    }
    sort(v.begin(),v.end());
    int k;
    cin>>k;
    k--;
    v.erase(unique(v.begin(),v.end()),v.end());
    printf("%s\n",v[k].c_str());
    return 0;
}

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



int main()
{
  ll n;
  cin>>n;
  ll ans=0;
  map<ll,ll> mp;
  for (ll i = 2; i*i <= n; i++)
  {
    if (n%i != 0) continue;
    while(n%i==0)
    {
      mp[i]++;
      n/=i;
    }      
  }
  if(n!=1) mp[n]++;

  for(const auto& e: mp) 
  {
    int i=1;
    while(i*(i+1)<=2*e.second)
    {
      i++;
    }
    i--;
    ans+=i;
  }
  cout<<ans;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 5e3 + 5;
const int inf = 1e9;
int f[2][maxn];
int ans[maxn];
int n , w[maxn];
vector<int> adj[maxn];

void DFS(int u){
    for(int c : adj[u])DFS(c);
    fill_n(&f[0][0],maxn*2,inf);
    int bit = 1;
    f[0][0] = 0;
    for(int c : adj[u]){
        for(int i = 0 ; i <= w[u] ; ++i){
            f[bit][i] = inf;
            if(i >= w[c])f[bit][i] = min(f[bit][i] , f[bit ^ 1][i - w[c]] + ans[c]);
            if(i >= ans[c])f[bit][i] = min(f[bit][i] , f[bit ^ 1][i - ans[c]] + w[c]);
        }
        bit ^= 1;
    }
    ans[u] = inf;
    for(int i = 0 ; i <= w[u] ; ++i)ans[u] = min(ans[u],f[bit^1][i]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 2 ; i <= n ; ++i){
        int p;cin >> p;adj[p].pb(i);
    }
    for(int i = 1 ; i <= n ; ++i)cin >> w[i];
    DFS(1);
    if(ans[1] == inf)cout << "IM";
    cout << "POSSIBLE";
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 0<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };


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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}

int main(void){
	int a, b; cin >> a >> b;
	int count = 1;
	int i = 0;
	while(1){
		if(count >= b){
			cout << i << endl;
			break;
		}
		count += a;
		count--;
		i++;
	}


	return 0;
}

Measured memory_bytes: 256
/*Author : Krishna*/
#include<iostream>
#include<unordered_map>
#include<map>
#include<string>
#include<sstream>
#include<vector>
#include <cmath>
#include <stack>
#include<queue>
#include <unordered_set>
#include <algorithm>
#define ll long long
using namespace std;

vector<int>adj[100005];
vector<bool>vis(100005,false);
void dfs(int i)
{
    if(!vis[i])
    {
        vis[i]=true;
        for(auto v : adj[i])
            dfs(v);
    }
}


void solve()
{

    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
         int x ,y;
         cin>>x>>y;
         --x;
         --y;
         adj[x].push_back(y);
         adj[y].push_back(x);
    }
    int comp=0;
    for(int i=0;i<n;i++)
    {
        if(!vis[i])
        {
            comp++;
            dfs(i);
        }
    }
    cout<<comp-1;


}


int main()
{
    int t;
//    cin>>t;
    t =1;
    while(t--)
    {
        solve();
    }
}

/*
 *Check for the edge cases(n=1)?
 *Is there any another approach?
 *check for data types
 *Keep on thinking
 */



Measured memory_bytes: 9484
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		String d1="";
		String d2="";
		String d3="";
		String d4="";
		for(int i=A;i<W;i++) {
			d1+="0";
		}
		for(int i=A;i<W;i++) {
			d2+="1";
		}
		for(int i=0;i<A;i++) {
			d3+="0";
		}
		for(int i=0;i<A;i++) {
			d4+="1";
		}
			int i=0;
			for(;i<B;i++) {
				int j=0;
				System.out.print(d4);
				System.out.print(d1);
				System.out.println();
			}
			for(;i<H;i++) {
				int j=0;
				System.out.print(d3);
				System.out.print(d2);
				System.out.println();
			}
			return;
	}

}

Measured memory_bytes: 32688
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef pair<int,int> P;
struct edge{int to,cap,cost,rev;};

const int inf = 1e9;
vector<edge> G[3010];
int h[3010];
int dist[3010];
int prevv[3010],preve[3010];

void add_edge(int from,int to,int cap,int cost){
    G[from].push_back((edge){to,cap,cost,(int) G[to].size()});
    G[to].push_back((edge){from,0,-cost,(int) G[from].size()-1});
}

int min_cost_flow(int s,int t,int f,int n){
    int res = 0;
    fill(h,h+n,0);
    while(f>0){
        priority_queue<P,vector<P>,greater<P>> Q;
        fill(dist,dist+n,inf);
        dist[s] = 0;
        Q.push(P(s,0));
        while(!Q.empty()){
            P p = Q.top(); Q.pop();
            int v = p.second;
            if(dist[v]<p.first) continue;
            for(int i=0;i<G[v].size();i++){
                edge &e = G[v][i];
                if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
                    dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    Q.push(P(dist[e.to],e.to));
                }
            }
        }
        if(dist[t]==inf) return -1;
        for(int v=0;v<n;v++) h[v] += dist[v];
        int d = f;
        for(int v=t;v!=s; v=prevv[v]){
            d = min(d,G[prevv[v]][preve[v]].cap);
        }
        f -= d;
        res += d*h[t];
        for(int v=t;v!=s;v=prevv[v]){
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

int N,M,F;
int A[1010],B[1010];

int main(){
    cin >> N;
    int id = N+1;
    map<int,int> m;
    for(int i=1;i<=N;i++){
        cin >> A[i] >> B[i];
        if(!m.count(A[i])){
            m[A[i]] = id;
            add_edge(0,id,1,0);
            id++;
        }
        if(!m.count(B[i])){
            m[B[i]] = id;
            add_edge(0,id,1,0);
            id++;
        }
        add_edge(m[A[i]],i,1,-B[i]);
        add_edge(m[B[i]],i,1,-A[i]);
        
    }
    for(int i=1;i<=N;i++) add_edge(i,id,1,0);
    add_edge(0,id,inf,0);
    cout << -min_cost_flow(0,id,N,id+1) << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int sumd(int n)
{
    int c=0;
    while(n)
    {
        c+=n%10;
        n=n/10;
    }
    return c;
}

int main()
{
    fsscan();
    int n;
    cin>>n;
    if(n%sumd(n)==0)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<queue>
#include <iostream>
#include <string>
#include<map>
using namespace std;
int main()
{
   int ans=0,n,h1,h,cnt=0;
   cin>>n;
   n--;
   cin>>h1;
   while(n--)
   {
       cin>>h;
       if(h<=h1)
      {
      cnt++;
      ans=max(ans,cnt);
      }
       else
       {
        cnt=0;}
       h1=h;
   }
   cout<<ans;
   return 0;
}


Measured memory_bytes: 256
answer = []


def prime(n):
    prime_flag = [0 for i in range(n + 1)]
    prime_list = []
    for i in range(2, n + 1):
        if prime_flag[i] == 0:
            prime_list.append(i)

            temp = 1
            while temp * i <= n:
                prime_flag[temp * i] = 1
                temp += 1
    return prime_list


prime_list = prime(100000)

while True:

    m, a, b = map(int, input().split())
    if m == a == b == 0:
        break
    rate = a / b
    ans = [0, 0]
    for i in prime_list:
        if i > m:
            break
        for j in prime_list:
            if i * j <= m:
                if i / j >= rate and i / j <= 1:
                    if ans[0] * ans[1] < i * j:
                        ans = [i, j]
            else:
                break

    answer.append(ans)

for i in answer:
    print(*i)


Measured memory_bytes: 6668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=203,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<pair<int,int>> cnt(N+1);
    for(int i=0;i<cnt.size();i++) cnt[i].second=i;
    
    for(int i=0;i<M;i++){
        string S;cin>>S;
        vector<int> ecnt(N+1),wcnt(N+1);
        for(int j=0;j<N;j++){
            if(S[j]=='E') ecnt[j+1]++;
            else wcnt[j+1]++;
        }
        for(int j=1;j<N+1;j++){
            ecnt[j]+=ecnt[j-1];
            wcnt[j]+=wcnt[j-1];
        }
        
        for(int i=0;i<N+1;i++){
            cnt[i].first+=ecnt[i]-ecnt[0];
            cnt[i].first+=wcnt[N]-wcnt[i];
        }
    }
    
    sort(all(cnt));
    
    cout<<cnt[0].second<<" "<<cnt[0].second+1<<endl;
}





Measured memory_bytes: 3360
#include<stdio.h>
#include<stdlib.h>
int f(int*a,int*b){return *a<*b?-1:*a==*b?0:1;}
int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  int p[n];
  for(int i=0;i<n;i++)scanf("%d",&p[i]);
  qsort(p,n,sizeof(int),f);
  int sum=0;
  for(int i=0;i<k;i++)sum+=p[i];
  printf("%d\n",sum);
}

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

int main() {
    int n;
    cin >> n;
    int t, x, y, d;
    for (int i = 0; i < n; i++)
    {
        cin >> t >> x >> y;

        d = abs(x) + abs(y);
        if (d > t) {
            cout << "No" << endl;
            return 0;
        } 
        if ((t - d) % 2 > 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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



int main() {
	
	int k, s;
	cin >> k >> s;
	int count = 0;

	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			int a = s - i - j;
			if (a >= 0 && a <= k) {
				count++;
			}
		}
	}

	cout << count << endl;
	return 0;

}




Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static final int H = 0;
	public static final int A = 1;
	public static final int D = 2;
	public static final int S = 3;
	//1回攻撃したダメージ量
	public static final int ACK = 4;
	//1回攻撃を受けたダメージ量
	public static final int DEF = 5;
	//倒すまでのターン数
	public static final int TURN = 6;
	//1ターンの勇者に与えるダメージ
	//public static final int DAM = 5;
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		doIt();
		//test();
	}

	public static void test(){
		PriorityQueue<E> queue = new PriorityQueue<E>();
		queue.add(new E(1,3.5));
		queue.add(new E(2,7));
		queue.add(new E(3,1.4));
		while(queue.isEmpty() == false){
			E e = queue.poll();
			System.out.println("i = " + e.i + ", r = " + e.r);
		}

	}

	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] yusya = new long[4];
		yusya[H] = sc.nextInt();
		yusya[A] = sc.nextInt();
		yusya[D] = sc.nextInt();
		yusya[S] = sc.nextInt();
		long[][] enemy = new long[n][7];
		PriorityQueue<E> queue = new PriorityQueue<E>(n);
		//勇者の受けた総ダメージ
		long dam = 0;
		//敵の総力攻撃
		long sum = 0;
		//情報のセット
		for(int i = 0; i < n; i++){
			enemy[i][H] = sc.nextInt();
			enemy[i][A] = sc.nextInt();
			enemy[i][D] = sc.nextInt();
			enemy[i][S] = sc.nextInt();
			//iを倒すまでのターン数を計算
			//1会のダメージ
			enemy[i][ACK] = Math.max(enemy[i][A] - yusya[D],0);
			enemy[i][DEF] = Math.max(yusya[A] - enemy[i][D],0);
			//倒せない場合
			if(enemy[i][DEF] == 0 && enemy[i][ACK] > 0){
				System.out.println(-1);
				return;
			}
			//向こうからの攻撃が通らない敵は無視する
			if(enemy[i][ACK] > 0){
				//倒せるまでのターン数の計算
				long h = enemy[i][H];
				enemy[i][TURN] = h / enemy[i][DEF];
				if(h % enemy[i][DEF] > 0){
					enemy[i][TURN]++;
				}
				double r = (double)enemy[i][ACK] / (double)enemy[i][TURN];
				//System.out.println("ack = " + enemy[i][ACK] + "turn = " + enemy[i][TURN] +  ", r = " + r);
				queue.add(new E(i,r));
				sum += enemy[i][ACK];
			}
			//まず勇者よりスピードの速い敵の攻撃
			//勇者の受けたダメージ
			if(enemy[i][S] > yusya[S]){
				dam += enemy[i][ACK];
			}
		}
		//戦闘開始
		//勇者の最適戦略はqueueの戦闘から倒していくこと

		if(yusya[H] <= dam){
			System.out.println(-1);
			return;
		}
		int num = queue.size();
		//敵がいなかったら
		if(num == 0){
			System.out.println(0);
			return;
		}
		while(queue.isEmpty() == false){
			int target = queue.poll().i;
			//勇者の行動
			//targetを倒す
			dam += sum*(enemy[target][TURN] - 1);
			if(yusya[H] <= dam){
				dam = -1;
				break;
			}
			sum -= enemy[target][ACK];
			dam += sum;
		}
//		while(true){
//			//勇者の行動
//			enemy[target][H] -= enemy[target][DEF];
//			if(enemy[target][H] <= 0){
//				num--;
//				if(num == 0){
//					ret = dam;
//					break;
//				}
//				sum -= enemy[target][ACK];
//				target = queue.poll().i;
//			}
//			//敵の行動
//			dam += sum;
//			if(yusya[H] <= dam){
//				ret = -1;
//				break;
//			}
//		}
		System.out.println(dam);
	}

}

class E implements Comparable<E>{
	public int i;
	public double r;
	E(int index, double rate){
		i = index;
		r = rate;
	}

	public int compareTo(E o) {
		// TODO 自動生成されたメソッド・スタブ
		return r < o.r ? 1 : -1;
	}
}

Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <tuple>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

ll inf = 1e9+7;
 
ll pw(ll x, ll y) {
    if (y == 0) return 1;
    else if (y == 1) return x % inf;
    else if (y % 2 == 0) {
        ll p = pw(x, y / 2);
        return p * p % inf;
    }
    else {
        ll p = pw(x, y / 2);
        return p * p % inf * x % inf;
    }
}

ll dv(ll x, ll y) {
    return x * pw(y, inf - 2) % inf;
}
 
ll comb(ll cn, ll cr) {
    ll v = 1;
    if (cn < cr || cn < 0 || cr < 0) return 0;
    for (int i = 1; i <= cr; i++) {
        v = v * (cn - i + 1) % inf;
        v = v * dv(1, i) % inf;
    }
    return v;
}

int main() {
    ll a, b, n, ans;
    cin >> n >> a >> b;
    ans = pw(2, n) - 1 + inf;
    if (a <= n) ans = (ans + inf * inf - comb(n, a)) % inf;
    if (b <= n) ans = (ans + inf * inf - comb(n, b)) % inf;
    cout << ans << endl;


}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

struct DSU {
    vi p; void init(int n) {p = vi (n, -1);}
    int findSet(int x) { return p[x] < 0 ? x : findSet(p[x]);}
    bool sameSet(int a, int b) { return findSet(a) == findSet(b); }
	int size(int x) { return -p[findSet(x)]; }
	bool joinSet(int x, int y) { // union-by-rank
		x = findSet(x), y = findSet(y); if (x == y) return 0;
		if (p[x] > p[y]) swap(x,y);
		p[x] += p[y]; p[y] = x; return 1;
	}
};

using city = pair<int, pii>;

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

	int N; cin >> N;
	
	vi xs (N);
	vi ys (N);
	vector<city> cxs (N);
	vector<city> cys (N);

	F0R(i, N) {
		cin >> xs[i] >> ys[i];
		cxs[i] = {i, pii {xs[i], ys[i]}};
		cys[i] = {i, pii {xs[i], ys[i]}};
	}

	sort(cxs.begin(), cxs.end(), [] (const city& lhs, const city& rhs) {
		return lhs.second.first < rhs.second.first;
	});

	sort(cys.begin(), cys.end(), [] (const city& lhs, const city& rhs) {
		return lhs.second.second < rhs.second.second;
	});

	priority_queue<city, vector<city>, greater<city>> q;

	FOR(i, 1, N) {
		city c1, c2;

		c1 = cxs[i-1];
		c2 = cxs[i];

		q.push({c2.second.first - c1.second.first, {c1.first, c2.first}});

		c1 = cys[i-1];
		c2 = cys[i];

		q.push({c2.second.second - c1.second.second, {c1.first, c2.first}});
	}

	ll ans = 0;

	DSU dsu; dsu.init(N);
	while (!q.empty()) {
		city res = q.top(); q.pop();
		if (dsu.sameSet(res.second.first, res.second.second)) continue;

		ans += res.first;
		dsu.joinSet(res.second.first, res.second.second);
	}
	print(ans);
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

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

    vector<vector<char>> image_a(n, vector<char>(n)), image_b(m, vector<char>(m));
    rep(i, n) rep(j, n) cin >> image_a[i][j];
    rep(i, m) rep(j, m) cin >> image_b[i][j];

    bool flag = false;
    rep(sy, n-m+1){
        rep(sx, n-m+1){
            bool same = true;
            rep(i, m){
                rep(j, m){
                    same &= image_a[sy + i][sx + j] == image_b[i][j];
                }
            }
            flag |= same;
        }
    }

    outYes(flag);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int A,B;

int main(int argc, char const *argv[])
{
    cin>>A>>B;
    if(A%3==0||B%3==0||(A+B)%3==0){
        cout<<"Possible"<<endl;
    }else{
        cout<<"Impossible"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string s, t;
vector<string> dic;

int main(void){
    
    cin >> s >> t;
    
    for(int i = s.size() - t.size(); i >= 0; --i){
        int cnt = 0;
        for(int j = 0; j < t.size(); ++j){
            if(s[i + j] == t[j] || s[i + j] == '?') ++cnt;
        }
        if(cnt == t.size()){
            string temp;
            for(int j = 0; j < i; ++j){
                if(s[j] == '?') temp.push_back('a');
                else temp.push_back(s[j]);
            }
            temp = temp + t;
            for(int j = temp.size(); j < s.size(); ++j){
                if(s[j] == '?') temp.push_back('a');
                else temp.push_back(s[j]);
            }
            dic.push_back(temp);
        }
    }
    sort(dic.begin(), dic.end());
    
    if(dic.size()) cout << dic.front() << endl;
    else cout << "UNRESTORABLE" << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int C = (B/K)*K;
		
		if(A <= C) {
			System.out.println("OK");
		}else {
			System.out.println("NG");
		}
	}

}

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

void call(int n){
	int i;
 for (i = 1; i <= n; i++){
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    continue;
  }
 for(; x; x /= 10) {
  if ( x % 10 == 3 ){
    cout << " " << i;
    break;
  }
 }
 }
  cout << endl;
}

int main(){
	int n;
	cin >> n;
	call(n);
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[8];
signed main(){
	ic(n)
	sc(s)
	if(n%2!=0){
		c("No")
		return 0;
	}	
	rep(0,i,n/2){
		if(s[i]!=s[i+n/2]){
			c("No")
			return 0;
		}
	}
	c("Yes")	
}	
	


Measured memory_bytes: 256
import sys
count = 0
for line in sys.stdin:
    if count % 2 == 0:
        a = list(map(int, line.split()))
    else:
        b = list(map(int, line.split()))
        hit, brow = 0, 0
        for i in range(4):
            if a[i] == b[i]:
                hit += 1
            elif a[i] in b:
                brow += 1
        print(hit, brow)
    count += 1



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

int main(void){
	string a;
	cin >> a;
	for(int i=0; i<=5; i++){
		if(a[i] == 'A' && a[i+1]=='C'){
			cout << "Yes" << endl;
			return 0;
		}
		
	}

			cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    cout << (n <= 999 ? "ABC" : "ABD") << '\n';
}


Measured memory_bytes: 256
def check(table, n)
  if n == 2
    table.find {|x| x == 2}
  else
    (1..7).each do |i|
      if table[i] > 0 and table[i + 1] > 0 and table[i + 2] > 0
        table[i] -= 1
        table[i + 1] -= 1
        table[i + 2] -= 1
        return true if check(table, n - 3)
        table[i] += 1
        table[i + 1] += 1
        table[i + 2] += 1
      end
    end
    (1..9).each do |i|
      if table[i] >= 3
        table[i] -= 3
        return true if check(table, n - 3)
        table[i] += 3
      end
    end
    false
  end
end

$<.readlines.map(&:chomp).map {|n| n.chars.map(&:to_i)}.each do |data|
  table = Array.new(10, 0)
  data.each {|i| table[i] += 1}
  result = (1..9).map do |i|
    added = table.dup
    added[i] += 1
    next if added[i] > 4
    check(added, 14) ? i : nil
  end.compact
  puts result.empty? ? 0 : result.join(" ")
end


Measured memory_bytes: 6868
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  string A, B, C;
  cin >> A >> B >> C;
  char a = A[0];
  char b = B[0];
  char c = C[0];
  a += 'A' - 'a';
  b += 'A' - 'a';
  c += 'A' - 'a';
  cout << a << b << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

map<int, int> make_map(vector<int> const& vec) {
  auto s = vec.size();
  map<int, int> mp;
  for (int i = 0; i < s; ++i) {
    int sum = 0;
    for (int j = i; j < s; ++j) {
      sum += vec[j];
      mp[sum] += 1;
    }
  }

  return mp;
}

int main() {
  while (true) {
    int h,w;
    cin >> h >> w;
    if (h == 0 && w == 0) break;
    vector<int> hvec(h), wvec(w);
    rep(i, h) cin >> hvec[i];
    rep(i, w) cin >> wvec[i];
    auto hmap = make_map(hvec);
    auto wmap = make_map(wvec);

    int ans = 0;
    for (auto it : hmap) {
      ans += it.second * wmap[it.first];
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 34276
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here

        Scanner scan = new Scanner(System.in);
   long N=scan.nextLong();
long p=0;
long n=0;
 for(long i=1;i<=N;i++){
     n=N/i;
     p=p+i*n*(n+1)/2;
 }
System.out.println(p);
    }
}


Measured memory_bytes: 27060
N,M=map(int,input().split())
A=map(int,input().split())
B=map(int,input().split())
Y=[0]*N*M
X=[0]*N*M
for a in A:
	if Y[a-1]:
		print(0)
		exit()
	Y[a-1]=1
for b in B:
	if X[b-1]:
		print(0)
		exit()
	X[b-1]=1
z=1
h=w=0
MD=10**9+7
for i in range(N*M)[::-1]:
	if Y[i]:
		if X[i]:
			z*=1
			h+=1
			w+=1
		else:
			z*=w
			h+=1
	else:
		if X[i]:
			z*=h
			w+=1
		else:
			z*=h*w-(N*M-1-i)
	z%=MD
print(z)


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    double L;
    cin >> L;
    double res = pow(L/3, 3);
    printf("%.8f\n", res);
    return 0;
}


Measured memory_bytes: 512
/*
   Created by Rahul Goel.
*/
/*******************************************************************************/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/*******************************************************************************/
using namespace std;
using ll = long long;
using ld = long double;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
/*
.-.. . -. -.- .- / .. ... / .-.. --- ...- . -.-.--
 */
/* For PBDS */
/*Two new methods X.order_of_key() and X.find_by_order()*/
/*
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*******************************************************************************/
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%mod; }
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/

/*
    Code begins after this.
*/


ll solve(){
    ll n;
    cin >> n;
    vi vec(n);
    ll xxx = 0;
    for(ll &x : vec)
        cin >> x, xxx = xxx xor x;
    for(ll &x : vec)
        cout << (xxx xor x) << " ";
    cout << endl;
    return 0;
}


signed main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}

/*******************************************************************************/
// Remeber - In a custom comparator cmp(a, b) a==b must always return to false.


Measured memory_bytes: 4764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define gt first
#define gc second.first
#define gr second.second
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,a[55],b[55],i,j,k,x;
	ll d[55][55],ans=0ll;
	bool use[55];
	fill(use,use+55,false);
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(i=0; i<n; ++i){
		cin >> b[i];
	}
	for(x=51; x>0; --x){
		fill(d[0],d[55],INFLL);
		for(i=0; i<=50; ++i){
			d[i][i] = 0ll;
		}
		for(i=0; i<=50; ++i){
			for(j=1; j<=51; ++j){
				if(use[j] || j<x){
					d[i][i%j] = min(d[i][i%j],(1ll<<j));
				}
			}
		}
		for(k=0; k<=50; ++k){
			for(i=0; i<=50; ++i){
				for(j=0; j<=50; ++j){
					d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
				}
			}
		}
		for(i=0; i<n; ++i){
			if(d[a[i]][b[i]] == INFLL){
				use[x] = true;
				break;
			}
		}
	}
	if(use[51]){
		ans = -1;
	}else{
		for(i=1; i<=50; ++i){
			if(use[i]){
				ans += (1ll<<i);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

x,a,b=MI()
if b<=a:
    print("delicious")
elif b-a<=x:
    print("safe")
else:
    print("dangerous")

Measured memory_bytes: 3316
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <cstdio>
#include <stack>
#include <set>
#include <deque>
using namespace std;
int n,m,x,a[105],b[105];
int ans,cnt;
int main()
{
	cin>>n>>m>>x;
	for (int i=0;i<m;i++)
	{
		cin>>a[i];
		b[a[i]]=1;
	}
	for (int i=1;i<=x-1;i++)
		if (b[i]==1)
			ans++;
	for (int i=x+1;i<=n;i++)
		if (b[i]==1)
			cnt++;
	cout<<min(ans,cnt)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();
		int q = sc.nextInt();
		int ns[] = new int[300001];
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			ns[a] = a;
		}
		int ans = 0;
		for (int i = 0; i < q; i++) {

			int mod = sc.nextInt();
			for (int j = 1; (j * mod - 1) <= 300000; j++) {
				ans = Math.max(ans, ns[j * mod - 1] % mod);
			}
			System.out.println(ans);
		}

	}

	public static void main(String[] args) {

		new Main().run();
	}
}

Measured memory_bytes: 144260
import sys
sys.setrecursionlimit(10**9)
N = int(input())

class Edge:
    def __init__(self,to,cost):
        self.to = to
        self.cost = cost
#隣接グラフ
graph = [[] for i in range(N)]
for i in range(N-1):
    a,b,c = map(int,input().split())
    graph[a-1].append(Edge(b-1,c))
    graph[b-1].append(Edge(a-1,c))
dp = [0 for i in range(N)]

def dfs(s,pare):
    for i in graph[s]:
        if i.to != pare :
            dp[i.to] = dp[s] + i.cost
            dfs(i.to,s)
        else:
            continue 


Q,K = map(int,input().split())
dfs(K-1,-1)
for i in range(Q):
    x,y = map(int,input().split())
    print("{}".format(dp[x-1]+dp[y-1]))


Measured memory_bytes: 152208
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int q,n,i,j;
  cin >> n;
  int a[n],b[n];
  for(i=0;i<n;i++){
    cin >> a[i];
    q=a[i]-1;
    b[q]=i+1;
  }

  for(i=0;i<n;i++){
    cout << b[i] << " ";
  }
}


Measured memory_bytes: 1664
N, K = gets.chomp.split.map(&:to_i)

trees = []

N.times do
  trees << gets.chomp.to_i
end

trees.sort!

min_diff = 1000000000
trees.each_with_index do |tree, i|
  break if i + K > N
  diff = trees[i + K - 1] - tree
  min_diff = diff if diff < min_diff
end

puts min_diff

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define _boost ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fi first
#define se second
#define clz __builtin_clz
#define clzll __builtin_clzll
#define bp __builtin_popcount
#define _unique(x) sort((x).begin(),(x).end()),(x).erase(unique((x).begin(), (x).end()),(x.end()))
#define all(x) (x).begin(),(x).end()
#define _rand(i,j) uniform_int_distribution<int>(i, j)(rng___)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;
template < typename _T, typename _T2> string to_string(pair<_T,_T2> x) {return "<"+to_string(x.fi)+", "+to_string(x.se)+">";}
template < typename _T> string to_string(vector<_T> vec) {string s="[ "; for(auto el:vec)s+=to_string(el)+", "; s[s.size()-1]=']';s[s.size()-2]=' '; return s;}
string to_string(string s) {return s;}
template < typename _T> string to_string(set<_T> vec) {string s="{ "; for(auto el:vec)s+=to_string(el)+", "; s[s.size()-1]='}';s[s.size()-2]=' '; return s;}
template < typename _T, typename _T2> string to_string(map<_T,_T2> vec) {string s="{ "; for(auto el:vec)s+="mp["+to_string(el.fi)+"]= "+to_string(el.se)+", "; s[s.size()-1]='}';s[s.size()-2]=' '; return s;}
template < typename _T > inline void _DBG(const char *s, _T x){cerr << s << " = " << to_string(x) << "\n";}
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a){while(*s != ',') cerr << *s++;cerr << " = " << to_string(x) << "\n";_DBG(s + 1, a...);}
#ifdef LOCAL
#define _print(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define _print(...) ;//cout<<2;//(__VA_ARGS__)
#endif
mt19937 rng___(chrono::steady_clock::now().time_since_epoch().count());


const LL MOD = 1e9+7;//998244353;
const LL LLINF = 1e18+7;
const int N=1e5+8;


int main()
{
    _boost;
    int n;
    cin>>n;
    vector<LL> vec(n+1);
    vector<LL> pref(n+1);
    for(int i=1;i<=n;i++)cin>>vec[i],pref[i]=pref[i-1]+vec[i];
    vector<vector<LL>> dp(n+1,vector<LL>(n+1,0));
    for(int d=1;d<n;d++)
    {
        for(int i=1;i+d<=n;i++)
        {
            LL minn=LLINF;
            for(int p=0;p<d;p++)
            {
                minn=min(minn,dp[i][i+p]+dp[i+p+1][i+d]);
            }
            dp[i][i+d]=minn+pref[i+d]-pref[i-1];
        }
    }
    cout<<dp[1][n];
}




Measured memory_bytes: 1536