akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    ll A, B, N;
    cin >> A >> B >> N;
    ll x = min(B - 1, N);
    cout << A * x / B - A * (x / B) << endl;
    return 0;
}



Measured memory_bytes: 3632
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main(){

  int N; cin >> N;

  vector<ll> a(N), b(N);
  REP(i, N){ ll _a; cin >> _a; a[i]=_a; }
  REP(i, N){ ll _b; cin >> _b; b[i]=_b; }

  ll result = 0;
  REP(k, 30){
    ll t = 1 << k;

    vll a_mod_t = a; REP(i, N) a_mod_t[i]%=2*t;
    vll b_mod_t = b; REP(i, N) b_mod_t[i]%=2*t;
    sort(b_mod_t.begin(), b_mod_t.end());

    int d = 0;
    REP(i, N){

      auto i1 = lower_bound(b_mod_t.begin(), b_mod_t.end(), t-a_mod_t[i]);
      auto i2 = lower_bound(b_mod_t.begin(), b_mod_t.end(), 2*t-a_mod_t[i]);
      auto i3 = lower_bound(b_mod_t.begin(), b_mod_t.end(), 3*t-a_mod_t[i]);
      auto i4 = lower_bound(b_mod_t.begin(), b_mod_t.end(), 4*t-a_mod_t[i]);

      d += i2-i1 + i4-i3;
    }

    if( d%2 != 0 ){
      result += t;
    }

  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 6552
S=input()

def No():
    print("No")
    exit()
def Yes():
    print("Yes")
    exit()
if len(S)%2!=0:
    No()
if len(S)==0:
    No()
    
if all([S[2*i:2*i+2]=="hi" for i in range(int(len(S)/2))]):
    Yes()
else:
    No()

Measured memory_bytes: 3060
require 'prime'

n,pr=gets.chomp.split(" ").map { |e| e.to_i }

a=pr.prime_division


def search(a,n)
  ans = 1
  for x in a do
    i = x[1]/n
    ans *= (x[0]**i)
  end
  return ans
end

puts search(a,n)



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

int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if(a <= b){
    if((a+w)>=b){
      cout << 0 << endl;
    }
    else{
      cout << b-(a+w) << endl;
    }
  }
  else{
    if((b+w)>=a){
      cout << 0 << endl;
    }
    else{
      cout << a-(b+w) << endl;
    }
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)
H, W = map(int, input().split())
S = []
white = 0
for i in range(H):
  s = str(input())
  S.append(s)
  white += s.count('.')
  
def main(h, w):
  global H
  global W
  global S
  global l
  tmp = []
  if h < H-1:
    if (S[h+1][w]=='.') and ([h+1, w] not in l):
      tmp.append([h+1, w])
  if w < W-1:
    if (S[h][w+1]=='.') and ([h, w+1] not in l):
      tmp.append([h, w+1])
  if 0 < h:
    if (S[h-1][w]=='.') and ([h-1, w] not in l):
      tmp.append([h-1, w])
  if 0 < w:
    if (S[h][w-1]=='.') and ([h, w-1] not in l):
      tmp.append([h, w-1])
  return tmp
    
cnt = 0
l = [[0, 0]]
tmp = [[0, 0]]
for i in range(10000):
  t = []
  for n in tmp:
    u = main(n[0], n[1])
    l += u
    t += u
  if t == []:
    ans = white+1
  elif [H-1, W-1] in t:
    ans = i+2
    break
  else:
    tmp = t
print(white-ans)

Measured memory_bytes: 9252
N = int(input())
v = [int(i) for i in input().split(" ")]
c = [int(i) for i in input().split(" ")]
#a,b,t = map(int,input().split(' '))
tt = 0
for i in range(N):
    k = int(v[i])-int(c[i])
    if k>0:
        tt +=k
print(tt)

Measured memory_bytes: 3060
if __name__ == "__main__":
    n = int(raw_input())

    nums = map( int, raw_input().split())
    nlen = len( nums )
    nlast = n - 1
    i = nlast
    while i >= 0:
        if i == 0:
            print nums[i]
        else:
            print nums[i],
        i = i - 1

Measured memory_bytes: 4204
#include <cstdio>
#include <iostream>
#include <stack>
#include <cstring>

using namespace std;

stack<int> s;

int main()
{
    int n, lim;
    char str[15];

    cin >> str;
    n = strlen(str);

    for(int i=0; i<n; i++)
    {
        if(str[i] == '0' || str[i] == '1')
            s.push(str[i]);
        if(str[i] == 'B' && s.empty() == false)
            s.pop();
    }

    lim = s.size();
    for(int i=1; i<=lim; i++)
    {
        str[i] = s.top();
        s.pop();
    }

    for(int i=lim; i>=1; i--)
        printf("%c", str[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i, n, m, ans;

  scanf("%d%d", &n, &m);
  while(!(n == 0 && m == 0)){
    ans = 1;
    for(i = 2; i <= n; i++){
      ans = (ans+m)%i;
      if(ans == 0)
	ans = i;
    }
    printf("%d\n", ans);
    scanf("%d%d", &n, &m);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    int m=-1;
    FOR(i,1,n+1){
        if(i*(i+1)/2==n){
            m=i;
            break;
        }
    }
    if(m==-1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    cout << m+1 << endl;
    vector<vector<int>> a(m+1,vector<int>(m));
    int s=0,t=0;
    FOR(i,1,n+1){
        a[s][t]=i;
        a[t+1][s]=i;
        if(t==m-1){
            t=s+1;
            s++;
        }
        else{
            t++;
        }
    }
    REP(i,m+1){
        cout << m << " ";
        REP(j,m){
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 3872
import sys
n, m, k = map(int, input().split())

if k==0:
    print("Yes")
    sys.exit()

for i in range(n+1):
    black=i*m
    c=n-(2*i)
    for j in range(m+1):
        if black+(j*c)==k:
            print("Yes")
            sys.exit()

print("No")

Measured memory_bytes: 8904
#include <bits/stdc++.h>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
  int x,n;
  cin >> x >> n;
  if(n==0){
    cout << x;
    return 0;
  }
  vector<int> p(n);
  vector<int> flag(100,0);
  for(int i=0;i<n;i++){
    cin >> p[i];
    continue;
    //cout << i;
  }
  int tmp;
  for(int i=0;i<n;i++){
    tmp = i;
    tmp = p[i]-1;
    flag[tmp] = 1;
  }
  
  for(int i=0;i<=100;i++){
    if(x-i <= 0){
      cout << x-i;
      return 0;
    }
    if(flag[x-i-1]==0){
      cout << x-i;
      return 0;
    }
    if(x+i >= 101){
      cout << x+i;
      return 0;
    }
    if(flag[x+i-1]==0){
      cout << x+i;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3628
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    ll N, T;
    ll ans_cost, ans_time = 0;
    cin >> N >> T;
    vector<ll> c(N, 0);
    vector<ll> t(N, 0);
    rep(i, N) cin >> c[i] >> t[i];
    ans_cost = c[0];
    rep(j, N) {
        if (ans_cost >= c[j]&& t[j]<=T) {
            ans_cost = c[j];
            ans_time = t[j];
        }
    }
    sort(t.begin(), t.end());
    if (t[0] > T) {
        cout << "TLE" << endl;
        return 0;
    }
     cout << ans_cost << endl;
    

  

    return 0;
}


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

using namespace std;

int main() {

	int n;
	string s;
	int max = 0;
	int cnt = 0;
	cin >> n;
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		
		if (s[i] == 'I') {
			cnt++;
		}
		else {
			cnt--;
		}
		
		if (cnt > max) {
			max = cnt;
		}
	}
	cout << max<< endl;


	return 0;
}

Measured memory_bytes: 256
/*
[soundhound2018-summer-qual] E - + Graph
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;
const ll INF = 1e18;

struct edge {
    int to;
    ll cost;
};

int N, M;
vector<edge> g[MAX_N];
bool visited[MAX_N];
ll cands[2][MAX_N];
ll t_min, t_max;

bool dfs(int v) {
    if (visited[v]) {
        return true;
    }
    visited[v] = true;

    bool ret = true;
    for (edge& e : g[v]) {
        for (int i = 0; i < 2; i++) {
            if (cands[i ^ 1][v] == -INF) {
                continue;
            }
            if (cands[i][e.to] != -INF &&
                cands[i][e.to] != e.cost - cands[i ^ 1][v]) {
                return false;
            }
            cands[i][e.to] = e.cost - cands[i ^ 1][v];
        }
        ret = ret && dfs(e.to);
    }

    return ret;
}

ll solve() {
    fill(cands[0], cands[0] + N, -INF);
    fill(cands[1], cands[1] + N, -INF);
    cands[1][0] = 0;
    if (!dfs(0)) {
        return 0;
    }

    t_min = 0;
    t_max = INF;
    for (int i = 0; i < N; i++) {
        if (cands[0][i] != -INF && cands[1][i] != -INF) {
            if ((cands[0][i] + cands[1][i]) % 2 != 0) {
                return 0;
            }
            int t_new = (cands[0][i] - cands[1][i]) / 2;
            if (t_new < t_min || t_new > t_max) {
                return 0;
            }
            t_min = t_max = t_new;
        } else if (cands[0][i] != -INF) {
            t_max = min(t_max, cands[0][i] - 1);
        } else if (cands[1][i] != -INF) {
            t_min = max(t_min, -cands[1][i] + 1);
        }
    }

    return max(0LL, t_max - t_min + 1);
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int u, v;
        ll s;
        cin >> u >> v >> s;
        u--;
        v--;
        g[u].push_back((edge){v, s});
        g[v].push_back((edge){u, s});
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 14208
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N;
    cin >> N;

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

    vector<int> I(N);
    REP(i, N) I[P[i] - 1] = i;

    ll ans = 0;

    reverse(ALL(I));
    set<int> s;
    s.insert(I[0]);
    s.insert(-1);
    s.insert(-2);
    s.insert(N);
    s.insert(N+1);
    FOR(i, 1, N) {
        s.insert(I[i]);

        auto it = s.find(I[i]);

        auto c1 = it;
        int p1 = *(--c1), p2 = *(--c1);

        auto c2 = it;
        int n1 = *(++c2), n2 = *(++c2);

        ll cnt = 0;

        if (p1 > -1) cnt += (p1 - p2) * (n1 - *it); // self + left
        if (n1 < N) cnt += (*it - p1) * (n2 - n1); // self + right

        ans += cnt * (N - i);
    }

    print(ans);

}


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

int main() {
    long long N,h,v,p;
    int a=1,ans=0,b=0;
    cin >> h >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        ans+=A.at(i);
    } 
    
    if(ans>=h) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define Maxn 300007
#define modp 998244353
int n,a[Maxn],b[Maxn],c[Maxn];
int tag[Maxn],g[Maxn];
char s[Maxn];
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    int cnt1=0,cnt2=0,cnt3=0;
    for (int i=1;i<=3*n;i++)
        if (s[i]=='R') a[++cnt1]=i;
        else if (s[i]=='G') b[++cnt2]=i;
        else c[++cnt3]=i;
    memset(tag,0,sizeof(tag));
    for (int i=1;i<=n;i++)
    {
        int tmp;
        if (a[i]<b[i]&&a[i]<c[i]) tag[a[i]]=1,g[a[i]]=1,tmp=1;
        if (b[i]<a[i]&&b[i]<c[i]) tag[b[i]]=1,g[b[i]]=2,tmp=2;
        if (c[i]<a[i]&&c[i]<b[i]) tag[c[i]]=1,g[c[i]]=3,tmp=3;
        if (a[i]>b[i]&&a[i]>c[i]) tag[a[i]]=-1,g[a[i]]=tmp;
        if (b[i]>a[i]&&b[i]>c[i]) tag[b[i]]=-1,g[b[i]]=tmp;
        if (c[i]>a[i]&&c[i]>b[i]) tag[c[i]]=-1,g[c[i]]=tmp;
        if (tag[a[i]]==0) g[a[i]]=tmp;
        if (tag[b[i]]==0) g[b[i]]=tmp;
        if (tag[c[i]]==0) g[c[i]]=tmp;
    }
    int ans=1;
    cnt1=0,cnt2=0,cnt3=0;
    int tot1=0,tot2=0,tot3=0;
    for (int i=1;i<=3*n;i++)
        if (tag[i]==1) 
        {
            if (g[i]==1) ++tot1;
            else if (g[i]==2) ++tot2;
            else ++tot3;
        }
        else if (tag[i]==-1)
        {
            if (s[i]=='R') ans=(1LL*ans*cnt1)%modp,--cnt1;
            else if (s[i]=='G') ans=(1LL*ans*cnt2)%modp,--cnt2;
            else ans=(1LL*ans*cnt3)%modp,--cnt3;
        }
        else
        {
            if (g[i]==1) ans=(1LL*ans*tot1)%modp,--tot1;
            else if (g[i]==2) ans=(1LL*ans*tot2)%modp,--tot2;
            else ans=(1LL*ans*tot3)%modp,--tot3;
            int tmp=g[i];
            if (s[i]=='R') tmp+=1;
            else if (s[i]=='G') tmp+=2;
            else tmp+=3;
            tmp=6-tmp;
            if (tmp==1) ++cnt1;
            else if (tmp==2) ++cnt2;
            else ++cnt3;
        }
    for (int i=1;i<=n;i++)
        ans=(1LL*ans*i)%modp;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 7640
#include<bits/stdc++.h>
using namespace std;
 
 
struct edge{
  int to,cost;
  bool operator < ( const edge &p)const{
    return (cost == p.cost? to < p.to :cost < p.cost);
  }
};
struct state{
  int pos,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};
 
typedef long long ll;
 
#define MAX 100005
int pa[MAX],ra[MAX];
int t[MAX],h[MAX],d[MAX];
 
vector<edge> G[MAX];
vector<edge> g[MAX];
int n,m;
 
void init();
int find(int x);
void unite(int x,int y);
ll solve();
 
int main(){
  while( scanf("%d",&n)!=EOF){
    init();
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    scanf("%d",&m);
    int a,b;
    for(int i=1;i<=m;i++){
      scanf("%d %d",&a,&b);
      g[a].push_back((edge){b,h[b]});
      g[b].push_back((edge){a,h[a]});
      if(h[a]<h[b]){        
        G[a].push_back((edge){b,h[b]});
      }else if(h[a]>h[b]){
        G[b].push_back((edge){a,h[a]});
      }else{        
        unite(a,b);
      }
    }
 
 
    for(int i=1;i<=n;i++){
      sort(g[i].begin(),g[i].end());
      for(int j=1;j<(int)g[i].size();j++){
        if(g[i][j-1].cost==g[i][j].cost){
          unite(g[i][j-1].to,g[i][j].to);
        }else if(g[i][j-1].cost<g[i][j].cost){
          G[ g[i][j-1].to ].push_back( g[i][j] );
        }
      }
    }
 
  
    for(int i=1;i<=n;i++){
      int id=find(i);
      t[id]++;
      if(i==id)continue;
      for(int j=0;j<(int)G[i].size();j++){
        edge e=G[i][j];
        G[id].push_back(e);
      }
    }
  
    cout<<solve()<<endl;
 
    break;
  }
  return 0;
}
 
ll solve(){
  priority_queue< state > Q;
 
  for(int i=1;i<=n;i++){
    if(i==find(i))Q.push((state){i,h[i]});
  }
  
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    int pos=s.pos;
    int cost=d[s.pos];
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      e.to=find(e.to);
      d[e.to]=max(d[e.to],cost+1);      
    }
  }
  ll ans=0;
  for(int i=1;i<=n;i++)ans+= (ll)d[i] * (ll)t[i];  
  return ans;
}
 
void init(){
  for(int i=0;i<MAX;i++){
    pa[i]=i;
    ra[i]=0;
    t[i]=0;
    d[i]=1;
    G[i].clear();
    g[i].clear();
  }  
}
 
 
 
int find(int x){
  if(pa[x]==x)return x;
  else return pa[x]=find(pa[x]);
}
 
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(ra[x]<ra[y])pa[x]=y;
  else {
    pa[y]=x;
    if(ra[x]==ra[y])ra[x]++;
  }  
}

Measured memory_bytes: 21264
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e6;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
char readChar()
{
    char result = getchar();
    while (isspace(result)) {
        result = getchar();
    }
    return result;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r)
{
    return uniform_int_distribution<int>(l, r)(rng);
}
struct pt {
    int x, id;
};
pt a[N];
bool comp(pt a, pt b) {
    return a.x < b.x;
}
main() {
    int n = readInt();
    for (int i = 1; i <= n; i++) {
        a[i].x = readInt();
        a[i].id = i;
    }
    sort(a + 1, a + n + 1, comp);
    for (int i = 1; i <= n; i++) {
        cout << a[i].id << " ";
    }
}


Measured memory_bytes: 2432
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

int union_tree[1000];
int union_find(int a) {
	if (union_tree[a] == a) return a;
	return union_tree[a] = union_find(union_tree[a]);
}
int union_merge(int a, int b) {
	a = union_find(a);
	b = union_find(b);
	if (a == b) return 0;
	union_tree[a] = b;
	return 1;
}

void solve() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return;
		REP(i, n) {
			union_tree[i] = i;
		}
		vector<tuple<long double, long double, long double, long double>> inputs;
		REP(i, n) {
			long double a, b, c, d;
			cin >> a >> b >> c >> d;
			inputs.push_back(make_tuple(a, b, c, d));
		}
		vector<tuple<long double, int, int>> next;
		REP(i, n) {
			for (int q = i + 1; q < n; ++q) {
				long double cost = 0;
				cost += pow(get<0>(inputs[i]) - get<0>(inputs[q]),2.0);
				cost += pow(get<1>(inputs[i]) - get<1>(inputs[q]), 2.0);
				cost += pow(get<2>(inputs[i]) - get<2>(inputs[q]), 2.0);
				cost = (long double)sqrt(cost);
				cost -= get<3>(inputs[i]) + get<3>(inputs[q]);
				cost = max(cost, 0.0L);
				next.push_back(make_tuple(cost, i, q));
			}
		}
		sort(ALL(next));
		long double ans = 0.0;
		REP(i, next.size()) {
			ans += get<0>(next[i]) * (long double)union_merge(get<1>(next[i]), get<2>(next[i]));
		}
		cout << fixed << setprecision(3);
		cout << ans << endl;
	}
}

int main() {
	init();
	solve();
}


Measured memory_bytes: 3536
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;
int A[500][500] = {};

int main()
{
    int X,Y;
    cin >> X >> Y;
    cout << X+Y/2;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int n; string c; 
    cin >> n >> c;

    vector<int> cnt_W(n+1), cnt_R(n+1);
    cnt_W[0] = 0;
    cnt_R[0] = 0;
    for(int i = 1; i <= n; i++){
        if(c[i-1] == 'W'){
            cnt_W[i] = cnt_W[i-1] + 1;
            cnt_R[i] = cnt_R[i-1];
        }
        else{
            cnt_W[i] = cnt_W[i-1];
            cnt_R[i] = cnt_R[i-1] + 1;
        }
    }

    // 答えは max(左側のW, 右側のR)
    int ans = 300000;
    for(int i = 0; i < n+1; i++){
        int left_R = cnt_R[n] - cnt_R[i];
        int right_W = cnt_W[i];
        ans = min(ans, max(left_R, right_W));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* struct for mod Calculation*/
struct mint {
        ll x;
        mint(ll x = 0):x((x % mod + mod) % mod) {}
        mint operator-() const { return mint(-x); }
        mint& operator+=(const mint a) {
            if ((x += a.x) >= mod) x -= mod;
            return *this;
        }
        mint& operator-=(const mint a) {
            if ((x += mod - a.x) >= mod) x -= mod;
            return *this;
        }
        mint& operator*=(const mint a) {
            (x *= a.x) %= mod;
            return *this;
        }
        mint operator+(const mint a) const {
            mint res(*this);
            return res += a;
        }
        mint operator-(const mint a) const {
            mint res(*this);
            return res -= a;
        }
        mint operator*(const mint a) const {
            mint res(*this);
            return res *= a;
        }
        mint pow(ll t) const {
            if (!t) return 1;
            mint a = pow(t >> 1);
            a *= a;
            if (t & 1) a *= *this;
            return a;
        }
        // for prime mod
        mint inv() const {
            return pow(mod - 2);
        }
        mint& operator/=(const mint a) {
            return (*this) *= a.inv();
        }
        mint operator/(const mint a) const {
            mint res(*this);
            return res /= a;
        }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    vector<ll> s, t;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] >= 0) s.push_back(A[i]);
        else t.push_back(A[i]);
    }

    int S = s.size(), T = t.size();
    bool ok = false;
    if (S > 0) {
        if (N == K) ok = (T%2 == 0);
        else ok = true;
    } else {
        ok = (K%2 == 0);
    }

    mint ans = 1;
    if (!ok) {
        sort(A.begin(), A.end(), [](int x, int y) {
            return abs(x) < abs(y);
        });
        for (int i = 0; i < K; i++) ans *= A[i];
    } else {
        sort(s.begin(), s.end());
        sort(t.rbegin(), t.rend());
        if (K%2 == 1) {
            ans *= s.back();
            s.pop_back();
        }
        vector<ll> p;
        while (s.size() >= 2) {
            ll x = s.back(); s.pop_back();
            x *= s.back(); s.pop_back();
            p.push_back(x);
        }
        while  (t.size() >= 2) {
            ll x = t.back(); t.pop_back();
            x *= t.back(); t.pop_back();
            p.push_back(x);
        }
        sort(p.rbegin(), p.rend());
        for (int i = 0; i < K/2; i++) ans *= p[i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 8152
from sys import stdin,stdout
from collections import defaultdict,deque

n, q = map(int,stdin.readline().split())
queries = stdin.readlines()
A = defaultdict(deque)
ans = []
#count = 0
for query in queries:
    #print(count)
    #count += 1
    query = query.split()
    if query[0] == '0':
        A[int(query[1])].append(query[2])
    elif query[0] == '1':
        ans.append(' '.join(A[int(query[1])]) + '\n')
    else:
        s = int(query[1])
        t = int(query[2])
        if (A[t]):
            if len(A[s]) == 1:
                A[t].append(A[s][0])
            elif len(A[t]) == 1:
                A[s].appendleft(A[t][0])
                A[t] = A[s]
            else:
                A[t].extend(A[s])
        else:
            A[t] = A[s]
        A[s] = deque()

stdout.writelines(ans)



Measured memory_bytes: 84032
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void chmin(int &x, int v) { if (x > v) x = v; }

int N;
vector<int> G[100000];
int dp[100000][2];
void dfs(int x, int p) {
  int deg = 0, sum = 0;
  for (int t : G[x]) if (t != p) {
    dfs(t, x);
    sum += dp[t][1];
    dp[x][0] = min(dp[x][0]+dp[t][0], N);
    deg++;
  }
  if (deg > 1) dp[x][0] = N;
  if (deg == 0) dp[x][1] = 1;
  else dp[x][1] = sum;
  for (int t : G[x]) if (t != p) {
    chmin(dp[x][1], sum - dp[t][1] + dp[t][0] + (deg == 1));
  }
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N-1) {
    int u, v;
    cin >> u >> v;
    G[u].pb(v);
    G[v].pb(u);
  }
  int root = -1;
  rep(i, N) if (G[i].size() >= 3) root = i;
  if (root == -1) {
    cout << 1 << "\n";
    return 0;
  }
  dfs(root, -1);
  cout << min(dp[root][0], dp[root][1]) << "\n";
  return 0;
}


Measured memory_bytes: 11776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    i64 x;
    cin >> x;
    i64 y = x % 500;
    i64 ans = x / 500 * 1000 + y / 5 * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def inputInline():
    N=int(input())
    numbers=list(map(int,input().split(" ")))
    return numbers
def bubbleSort(list):
    N=len(list)
    count=0
    flag=True
    while flag:
        flag=False
        for i in range(N-1):
            if list[i]>list[i+1]:
                temp=list[i]
                list[i]=list[i+1]
                list[i+1]=temp
                flag=True
                count+=1
    return (list,count)
result=bubbleSort(inputInline())
print(" ".join(list(map(str,result[0]))))
print(result[1])

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

ll solve() {
    ll N, l, r;
    cin >> N;
    vector<ll> L(N), R(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> L[i] >> R[i];
    }
    vector<int> il(N), ir(N);
    for ( int i = 0; i < N; i++ ) {
        il[i] = i;
        ir[i] = i;
    }
    sort(il.begin(), il.end(), [&](int i1, int i2) { return L[i1] > L[i2];});   //desc
    sort(ir.begin(), ir.end(), [&](int i1, int i2) { return R[i1] < R[i2];});   //asc

    auto calc = [&](int f) {
        ll d = 0;
        vector<bool> used(N);
        int jl = 0, jr = 0;
        ll c = 0;
        for( int cnt = 0; cnt < N; cnt++ ) {
            int i;
            if ( f == 0 ) {
                while ( used[il[jl]] ) jl++;
                i = il[jl];
            } else {
                while ( used[ir[jr]] ) jr++;
                i = ir[jr];
            }
            if ( c < L[i] ) {
                d += L[i] - c;
                c = L[i];
            } else if ( R[i] < c ) {
                d += c - R[i];
                c = R[i];
            }
            f = 1 - f;
            used[i] = true;
        }
        d += abs(c);
        return d;
    };

    ll ans = max(calc(0), calc(1));
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2560
#import numpy

#for loop
#a = [1,2,3,4,5,6,7,8,9,10]
#s = [0]*len(a)
#s[0] = a[0]
#for i in range(len(a)-1):
#  s[i+1] = s[i] + a[i+1]
#print(s)

#numpy.cumsum()
#print(numpy.cumsum(a))

q = int(input())
n = 10**5+1
limit = int(n**0.5)
a = [i for i in range(3, n, 2)]
prime = [2]
while True:
  p = a[0]
  if limit <= p:
    prime += a
    break
  prime.append(p)
  a = [j for j in a if j%p!=0]
  
pi = [0]*n
for i in range(len(prime)):
  ai = (prime[i]+1)//2
  if ai in prime:
    pi[prime[i]-1] = 1
    
s = [0]*n
s[0] = pi[0]
for i in range(len(pi)-1):
  s[i+1] = s[i] + pi[i+1]
s = [0,0] + s
for i in range(q):
  l, r = map(int, input().split())
  print(s[r+1]-s[l])


Measured memory_bytes: 14424
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if (a >= k){
        cout << k << endl;
        return 0;
    }else if (a + b >= k){
        cout << a << endl;
        return 0;
    }else{
        cout << a - (k-a-b) << endl;
        return 0;
    }
}

Measured memory_bytes: 3624
'use strict';
function main(input) {
  const arr = input.trim().split('\n');
  const a = arr[0].split(' ').map(x => Number(x));
  const b = arr[1].split(' ').map(x => Number(x)).sort(function (a, b) {
    return b - a;
  });
  let sum = 0;

  for (let i = 0; i < b.length; i ++) {
    sum += b[i];
  }

  if (b[(a[1] - 1)] < sum / 4 / a[1]) {
    console.log('No');
  } else {
    console.log('Yes');
  }
  
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
M = [19, 20]
Y = sum(M) * 5

for i in range(int(input())):
    res = 0
    y,m,d = list(map(int,input().split()))
    for y_2 in range(1000-1, y, -1):
        res += Y if y_2 % 3 != 0 else 200

    for m_2 in range(10, m, -1):
        res += M[m_2 % 2] if y % 3 != 0 else 20

    res += (M[m%2] if y % 3 != 0 else 20) - d +1

    print(res)

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a[6];
	int b=0,c=0,d=0,e=0;
	for(int i=0;i<6;i++){
		cin>>a[i];
		if(a[i]==1){
			b++;
		}
		else if(a[i]==2){
			c++;
		}
		else if(a[i]==3){
			d++;
		}
		else if(a[i]==4){
			e++;
		}
	}
	if(b==1&&c==1&&d==2&&e==2){
		cout<<"YES"<<endl;
	}
	else if(b==1&&c==2&&d==1&&e==2){
		cout<<"YES"<<endl;
	}
	else if(b==1&&c==2&&d==2&&e==1){
		cout<<"YES"<<endl;
	}
	else if(b==2&&c==1&&d==1&&e==2){
		cout<<"YES"<<endl;
	}
	else if(b==2&&c==1&&d==2&&e==1){
		cout<<"YES"<<endl;
	}
	else if(b==2&&c==2&&d==1&&e==1){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 256
local a,b,c=io.read("n","n","n")
if b>c then
  b,c=c,b
end
if a>b then
  a,b=b,a
end
if b>c then
  b,c=c,b
end
if a==b and a==5 and c==7 then
  print("YES")
else
  print("NO")
end


Measured memory_bytes: 508
import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val n = readint()
    val m = HashSet<Int>()
    for(i in 0 until n){
        val a = readint()
        if(m.contains(a)) m.remove(a)
        else m.add(a)
    }
    println(m.size)
}

fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}

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

void Change(int x, int y){
	int z = y;
	y = x;
	x = z;
}

vector<int> Subvec(vector<int> X, int p, int l){
	vector<int> Y;
	for(int i = p; i < p+l; i++) Y.push_back(X[i]);
	return Y;
}

vector<int> SelectionSort(vector<int> A, int i){
	int N = A.size() - 1;
	int j_0 = i;
	for(int j = i; j < N; j++){
		if(A[j] < A[j_0]) j_0 = j;
	}
	if(j_0 != i){
		A[N]++;
		int a = A[j_0];
		A[j_0] = A[i];
		A[i] = a;
	}
	return A;
}

void Output(vector<int> A){
	int n = A.size() - 1;
	for(int i = 0; i < n; i++) cout << A[i] << ' ';
	cout << A[n] << endl;
}

int main(){
	int N;
	cin >> N;
	vector<int> A;
	for(int i = 0; i < N; i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
	A.push_back(0); //A[N]?????\??????????????°?????¨???
	for(int i = 0; i < N; i++) A = SelectionSort(A, i);
	Output(Subvec(A, 0, N));
	cout << A[N] << endl;
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int N, K;
int p[1005];

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", p+i);
  }
  sort(p, p+N);
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += p[i];
  }
  printf("%d\n", ans);
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 a, b, c;
  cin >> a >> b >> c;
  if (a < b && b < c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	long long N, A, B; cin >> N >> A >> B;
	if ((B - A) % 2 == 0) return !printf("%lld", (B - A) / 2);
	cout << ((B - A) / 2 + min(A, N - B + 1));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, K, Q; cin >> N >> K >> Q;
VI A(Q), correct(N, 0); rep(i, 0, Q) cin >> A[i];

rep(i, 0, Q){
    ++correct[A[i]-1]; //正解数のカウント
}

// 不正解数は Q - correct[i]
rep(i, 0, N){
    if (K <= (Q - correct[i])) cout << "No" << endl;
    else cout << "Yes" << endl;
}

}

// 境界，出力文字列 チェック



Measured memory_bytes: 1408
A = int(input())
B = int(input())
 
if A == 1 and B ==2:
  print(3)
elif A == 1 and B ==3:
  print(2)
elif A == 2 and B ==1:
  print(3)
elif A == 2 and B ==3:
  print(1)
elif A == 3 and B ==1:
  print(2)
else:
  print(1)

Measured memory_bytes: 3060
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    string S, T;
    cin >> S >> T;

    string TT = T + T;
    if (TT.find(S) != string::npos) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
    int H, W;


    while(1){
        cin >> H >> W;
        if(0 == H && 0 == W){
            break;
        }

        // cout << H << " " << W << endl;

        for(int j = 0; j < H; j++){
            for(int i = 0; i < W; i++){
                if(0 != j && (H - 1) != j && 0 != i && (W - 1) != i){
                    cout << ".";
                } else {
                    cout << "#";
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3036
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
typedef long long int lli;
using namespace std;

int dx[7][4]={{0,0,1,1},{0,0,0,0},{0,1,2,3},{0,0,-1,-1},{0,1,1,2},{0,0,1,1},{0,-1,0,1}};
int dy[7][4]={{0,1,1,0},{0,1,2,3},{0,0,0,0},{0,1,1,2},{0,0,1,1},{0,1,1,2},{0,1,1,0}};
string MAP[8];
string ans="ABCDEFG";

int main(){
	while(1){
	for(int i=0; i<8; ++i){
		cin >> MAP[i];
		if(cin.eof()){
			return 0;
		}
	}
	for(int i=0; i<8; ++i){
		for(int j=0; j<8; ++j){
			if(MAP[i][j]=='1'){
				for(int k=0; k<7; ++k){
					bool ok=true;
					for(int l=0; l<4; ++l){
						int nx=j+dx[k][l];
						int ny=i+dy[k][l];
						if((0<=nx&&nx<8&&0<=ny&&ny<8&&MAP[ny][nx]!='1')||(nx<0||8<=nx||ny<0||8<=ny)){
							ok=false;
							break;
						}
					}
					if(ok){
						cout << ans[k] << "\n";
						break;
					}
				}
			}
		}
	}
	}
	return 0;
}

Measured memory_bytes: 1168
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashSet;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long  a=sc.nextLong();
    long  b=sc.nextLong();
    long  c=sc.nextLong();
    long  d=sc.nextLong();


/*
  if (a>=0&&c>=0) {
    System.out.println(b*d);
 }
 if(d<0&&a>=0){
   System.out.println(a*d);
 }
 if (b<0&&c>=0) {
   System.out.println(b*c);
 }
 */
 long a1=a*c;
 long a2=a*d;
 long a3=b*c;
 long a4=b*d;
 long ans=0;
 if(a1>a2){
   ans=a1;
 }else{
   ans=a2;
 }
if(a3>ans){
  ans=a3;
}
if (a4>ans) {
  ans=a4;
}
System.out.println(ans);

}
}


Measured memory_bytes: 35688
#include <bits/stdc++.h>
using namespace std;
int MAIN(){
  int n;
  if(!(cin >> n)) return 0;
  vector<vector<int> > arr(2, vector<int>(n, 0));
  for(int e = 0; e < 2; e++) for(int f = 0; f < n; f++) cin >> arr[e][f];
  int ans = 0;
  // for(int e = 0; e < 2; e++){
    for(int f = 0; f < n; f++){
      int col = 0;
      for(int g = 0; g <= f; g++) col += arr[0][g];
      for(int g = f; g < n; g++) col += arr[1][g];
      ans = max(ans, col);
    }
  // }
  cout << ans << endl;
  return 1;
}
int main(){
  while(MAIN());
  return 0;
}


Measured memory_bytes: 256
function Main(input) {
    input = input.trim();    
    input = input.split("\n")

    var a = input[0]
    var b = input[1]

    b = b.slice(0,b.length-1)

    if(a == b){
        console.log("Yes");
    }else{
        console.log("No")
    }    

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29628
#!/usr/bin/perl -w

@line = split(//,<>);
$b=1000;
for($i=0;$i<@line-3;$i++){
    
    $a=abs(753-($line[$i]*100+$line[$i+1]*10+$line[$i+2]));
    if($b>$a){
        $b=$a;
        
    }
}
print $b;

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define MOD 1000000007

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> p(N, 0);
    vector<int> d(K);
    for (int i = 0; i < K; i++) {
        cin >> d.at(i);
        for (int j = 0; j < d.at(i); j++) {
            int tmp;
            cin >> tmp;
            tmp--;
            p.at(tmp)++;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (p.at(i) == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

void dfs(const vector<vector<int>>& graph, vector<ll>& ans, int node, int parent) {
    for (auto& next_node : graph[node]) {
        if (next_node == parent) {
            continue;
        }
        ans[next_node] += ans[node];
        dfs(graph, ans, next_node, node);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    vector<vector<int>> graph(N);
    int u, v;
    rep(i, 0, N - 1) {
        cin >> u >> v;
        --u, --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    ll p, x;
    vector<ll> ans(N, 0);
    rep(i, 0, Q) {
        cin >> p >> x;
        ans[--p] += x;
    }
    dfs(graph, ans, 0, -1);
    rep(i, 0, N) {
        cout << ans[i] << " \n"[i + 1 == N];
    }
    return 0;
}

Measured memory_bytes: 30592
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val vs = readLine()!!.split(' ').map { it.toInt() }

    var ans = Int.MIN_VALUE

    for (i in 0..Math.min(n, k)) {
        for (j in 0..Math.min(n, k) - i) {
            val xs = vs.take(i).plus(vs.takeLast(j))
            val v = xs.sum() - xs.filter { it < 0 }.sorted().take(k - i - j).sum()
            ans = Math.max(ans, v)
        }
    }

    println(ans)
}


Measured memory_bytes: 40392
using System;

namespace ABC173D
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine().Trim());
            long[] a = new long[N];
            var t = Console.ReadLine().Trim().Split(' ');
            for(int i=0;i<N;i++) a[i] = long.Parse(t[i]);
            Array.Sort(a); Array.Reverse(a);
            long ans = a[0];
            int k = 1;
            for(int i=1;i<N-1;i++) {
                ans += a[k];
                if(i % 2 == 0) k++;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 47060
program hi;
var 
    n, i, ans: longint;
    s: string;

begin
    readln(n);
    readln(s);
    ans := 0;
    for i := 1 to n - 2 do 
        if s[i] + s[i + 1] + s[i + 2] = 'ABC' then
            inc(ans);
    writeln(ans);
end.

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

int main()
{
  int A, B;
  cin >> A >> B;

  string S;
  cin >> S;

  int flag = 0;
  for(int i = 0; i < A; i++){
    if(S[i] == '-'){
      flag++;
      break;
    }
  }

  if(S[A] != '-') flag++;

  for(int i = A + 1; i < A + B + 1; i++){
    if(S[i] == '-'){
      flag++;
      break;
    }
  }

  if(flag == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}

Measured memory_bytes: 256
fn main() {
    use std::collections::HashSet;

    let s: String = read_line_as_value();
    let mut odd_chars = HashSet::new();
    odd_chars.insert('R');
    odd_chars.insert('U');
    odd_chars.insert('D');
    let mut even_chars = HashSet::new();
    even_chars.insert('L');
    even_chars.insert('U');
    even_chars.insert('D');

    let mut ans = true;
    for (i, c) in s.chars().enumerate() {
        if (i+1) % 2 == 0 && even_chars.contains(&c) {
            continue
        } else if (i+1) % 2 == 1 && odd_chars.contains(&c) {
            continue
        } else {
            ans = false;
            break
        }
    }
    match ans {
        true => println!("Yes"),
        false => println!("No"),
    }
}

fn read_line_as_value<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().parse() {
        Ok(val) => val,
        _ => panic!("error while parsing input: {}", input)
    }
}

Measured memory_bytes: 2184
#include<iostream>
#include<vector>
#include<list>
#include<algorithm>
using namespace std;

int main () {
  long H,W;
  cin >> H >> W;
  if (H==1 || W ==1 ) {
    cout << 1;
    return 0;
  }
  long ans=0;
  ans += ((H+1)/2) * ((W+1)/2); // 奇数行目
  ans += (H/2) * (W/2); //偶数行目

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 1000000000
#define MOD 1000000007;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;


int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << max(0, min(b, d) - max(a, c)) << endl;

	
	return 0;
}





Measured memory_bytes: 256