akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {

int x,N;
cin>>x >>N;
vector<int>vec(300);//-100から始まる

rep(i,N){
  int a;cin >> a;
  vec[a+101]++;
}

P n{1e9,1e9};//first 絶対差 second その時の数字

rep(i,300)
{
  int num=i-101;
  if(vec[i]==0&&abs(num-x)<n.first){n.first=abs(num-x);n.second=num;}
}
cout<<n.second<<endl;
}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

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

int main(){
  int n,k,cnt;
  bool f;

  while(cin >> n,n){
    cnt = 0; f = false;
    for(int i=0;i<n;i++){
      cin >> k;
      if(k)cnt++;
      if(k>1)f = true;
    }
    if(!f)cout << "NA\n";
    else cout << cnt + 1 << endl;
  }
}

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

int main(){

    int num;
    cin >> num;

    vector<int> emp_num(num);
    int i;
    vector<int> relation(num);

    for (i=0; i<num-1; i++){
        cin >> emp_num.at(i);
//        relation.at(i) = 0;
    }

    for (i=0; i<num-1; i++){
        relation.at(emp_num.at(i)-1)++;
    }

    for (i=0; i<num; i++){
        cout << relation.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 4840
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

#include<math.h>
typedef long long ll;
using namespace std;

int main()
{
	ll n;
	vector<ll> a;
	cin >> n;
	for(ll i = 0; i < n-1; i++)
	{
		ll v;
		cin >> v;
		a.push_back(v);
	}

	vector<ll> num(n , 0);
	for(ll i = 0; i < n-1; i++)
	{
		num.at((a.at(i) - 1))++;
	}

	for(ll i = 0; i < n; i++)
	{
		cout << num.at(i) << endl;
	}
	return 0;
}

Measured memory_bytes: 6092
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
    int t=min(x, y);
    int ans=min((a+b)*t, 2*c*t);
    int s=x>y ? a : b;
    t=max(x, y)-t;
    ans+=min(t*s, 2*c*t);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> P;

struct node {
	int id;
	bool done;
	vi ed, dist;
	int from;
	ll d;
	bool operator<(const node & another) const {
		return !(d != another.d ? d < another.d : id < another.id);
	}
};


void dijkstra(vector<node> nodes, int n, int start) {
	priority_queue<node> pq;
	nodes[start].d = 0;
	pq.push(nodes[start]);
	while (pq.size()) {
		node focus = pq.top(); pq.pop();
		if (nodes[focus.id].done) continue;
		Loop(i, focus.ed.size()) {
			if (focus.d + focus.dist[i] < nodes[focus.ed[i]].d) {
				nodes[focus.ed[i]].d = focus.d + focus.dist[i];
			}
			pq.push(nodes[focus.ed[i]]);
			nodes[focus.id].done = true;
		}
	}
	Loop(i, n) {
		if (nodes[i].d == INFLL) cout << "INF" << endl;
		else cout << nodes[i].d << endl;
	}
	return;
}

int main() {
	int v, e, r; cin >> v >> e >> r;
	vector<node> nodes(v + 5);
	Loop(i, v) nodes[i] = { i, false, {}, {}, -1, INFLL };
	Loop(i, e) {
		int s, t, d; cin >> s >> t >> d;
		nodes[s].ed.push_back(t);
		nodes[s].dist.push_back(d);
	}
	dijkstra(nodes, v, r);
}

Measured memory_bytes: 45952
#include <iostream>

using namespace std;

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int d = s - i - j;
      if (d >= 0 && d <= k) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3144
#include <iostream>
using namespace std;
int main(){
  int x;
  cin>>x;
  for(int i = 1; i<10003; i++){
      if(x == 0){
          return 0;
      }
      cout<<"Case"<<" "<<i<<":"<<" "<<x<<endl;
      cin>>x;
  }
  return 0;
}


Measured memory_bytes: 3056
n = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for _ in range(n):
    i = input()
    if i == 'AC':
        AC += 1
    elif i == 'WA':
        WA += 1
    elif i == 'TLE':
        TLE += 1
    else:
        RE += 1
print('AC x ' + str(AC))
print('WA x ' + str(WA))
print('TLE x ' + str(TLE))
print('RE x ' + str(RE))

Measured memory_bytes: 9200
h, w = gets.split.map(&:to_i)
ss = h.times.map { gets.chomp!.chars }

dy = [-1, 0, 1, -1, 1, -1, 0, 1]
dx = [1, 1, 1, 0, 0, -1, -1, -1]

0.upto(h-1) do |i|
  0.upto(w-1) do |j|
    next if ss[i][j] == '#'

    ans = 0
    0.upto(7) do |k|
      ci = i + dy[k]
      cj = j + dx[k]

      next if ci < 0 || ci >= h || cj < 0 || cj >= w
      ans += 1 if ss[ci][cj] == '#'
    end
    ss[i][j] = ans.to_s
  end
end

ss.each do |s|
  puts s.join
end


Measured memory_bytes: 14664
inf = 10**6
N, M = map(int, input().split())

edge = [[inf] * N for _ in range(N)]
for _ in range(M):
    s, t, c = map(int, input().split())
    edge[s][t] = c
for i in range(N):
    edge[i][i] = 0


# 0からスタートするよ
dp = [[inf] * (1 << N) for _ in range(N)]
dp[0][0] = 0

for bit in range(1 << N):
    for t in range(N):
        if bit & (1 << t):
            continue
        bit_next = bit | (1 << t)
        for s in range(N):
            dp[t][bit_next] = min(dp[t][bit_next], dp[s][bit] + edge[s][t])


if dp[0][(1 << N)-1] >= inf:
    print(-1)
else:
    print(dp[0][(1 << N) - 1])


Measured memory_bytes: 17176
N=int(input())
a=list(map(int, input().split()))
a.sort()
nums=[0]*(10**5+1)
for i in range(N):
  nums[a[i]]+=1
maxsum=0
for x in range(1, 10**5-1):
  tmp=nums[x-1]+nums[x]+nums[x+1]
  if maxsum<tmp:
    maxsum=tmp
print(maxsum)

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

int main(){
    int n;
    cin >> n;
    int a[110000];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int k;
        cin >> k;
        cout << binary_search(a, a+n, k) << endl;
    }
    return 0;
}


Measured memory_bytes: 3496
#include <bits/stdc++.h>
#define pll pair<ll,ll>
const int mod = 1e9 + 7;
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int n,H[100101][3],dp[101010][3],k;
int main(){
    ios::sync_with_stdio(0);
    cin >> n ;
    for(int i=1;i<=n;i++){
            for(int j=0;j<3;j++)cin>>H[i][j];
    }
    for(int i = n;i>=1;i--){
        for(int j=0;j<3;j++){
            dp[i][j] = -1e9-7;
            for(int k=0;k<3;k++)if(k!=j)dp[i][j]=max(dp[i][j],dp[i+1][k]+H[i][k]);
        }
    }
    cout << max({dp[1][0],dp[1][1],dp[1][2]}) << endl;
    return 0;
}


Measured memory_bytes: 2560
n=int(input())
s=list(input())

point = 0
rList = []
gList = []
bList = []
for value in s:
    point += 1
    if value == "R":
        rList.append(point)
    elif value == "G":
        gList.append(point)
    elif value == "B":
        bList.append(point)

if len(rList) < 1 or len(gList) < 1 or len(bList) < 1:
    print(0)
else:
    count = len(rList) * len(gList) * len(bList)
    for i in range(n-1):
        for j in range(i+1,n):
            k = 2*j-i
            if k < n and s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                count -= 1
    print(count)

Measured memory_bytes: 9344
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	vector <int> check, dp(n), h(n);
	for (int i = 0; i < n; i++)cin >> h[i];
	for (int i = 0; i < n; i++) {
		if (i == 0)dp[i] = 0;
		else if (i < k) {
			for (int j = 0; j < i; j++) {
				check.push_back(dp[i - j - 1] + abs(h[i - j - 1] - h[i]));
			}
			dp[i] = *min_element(check.begin(), check.end());
			check.clear();
		}
		else
		{
			for (int j = 0; j < k; j++)check.push_back(dp[i - j - 1] + abs(h[i - j - 1] - h[i]));
			dp[i] = *min_element(check.begin(), check.end());
			check.clear();
		}
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 1024
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

struct BIT2D { //1-indexed
private:
    ll h,w;
    vector< vector<ll> > dat;

public:
    BIT2D(ll H, ll W){
        h = H; w = W;
        dat.assign(h+10, vector<ll>(w+10, 0));
    }

    void update(ll x, ll y, ll v){
        for(ll i = x; i <= h; i += i & -i) for( ll j = y; j <= w; j += j & -j) dat[i][j] += v;
    }

    ll qsum(ll x, ll y){
        ll res = 0;
        for(ll i = x; i > 0; i -= i & -i) for(ll j = y; j > 0; j -= j & -j) res += dat[ i ][ j ];
        return res;
    }

    ll qsum(ll x0,  ll y0,  ll x1,  ll y1){
        return qsum(x1, y1) - qsum(x0-1, y1) - qsum(x1, y0-1) + qsum(x0-1, y0-1);
    }

    ll get(ll x, ll y){
        return qsum(x, y, x, y);
    }
};

typedef struct {
    ll h;
    ll w;
    ll t;
} P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W,T,Q;
    cin >> H >> W >> T >> Q;
    BIT2D bit_fin(H,W), bit_mada(H,W);
    queue<P> que;
    while(Q--){
        ll t,c,h1,w1,h2,w2;
        cin >> t >> c >> h1 >> w1;
        if(c == 2) cin >> h2 >> w2;
        while(not que.empty()){
            P p = que.front();
            if(t - p.t >= T){
                que.pop();
                bit_fin.update(p.h, p.w, 1);
                bit_mada.update(p.h, p.w, -1);
            }else{
                break;
            }
        }
        if(c == 0){
            bit_mada.update(h1, w1, 1);
            que.push((P){h1,w1,t});
        }else if(c == 1){
            if(bit_fin.get(h1,w1) >= 1){
                bit_fin.update(h1,w1,-1);
            }

        }else{
            ll v1 = bit_fin.qsum(h1,w1,h2,w2);
            ll v2 = bit_mada.qsum(h1,w1,h2,w2);
            cout << v1 << " " << v2 << endl;
        }

    }
    

}



Measured memory_bytes: 68592
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535;
#define MOD 1000000007;
vint t;
queue<ll> q;

int main(void) {
	ll k;
	cin >> k;
	t.resize(k, (ll)1e6);
	q.push(1);
	t[1] = 1;

	while (!q.empty()) {
		ll x = q.front(); q.pop();
		if (t[(x + 1)%k] > t[x] + 1) {
			q.push((x + 1)%k);
			t[(x + 1)%k] = t[x] + 1;
		}
		if (t[(x * 10) % k] > t[x]) {
			q.push((x * 10) % k);
			t[(x * 10) % k] = t[x];

		}

	}
	cout << t[0] << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005][4];
int dp[100005][3]={0};
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+a[i][2];
	}
	int ans=-1;
	for(int i=0;i<=2;i++)
		ans=max(dp[n][i],ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2944
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll mod = (ll)1e9 + 7;
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
map<int,int>mp;
set<int> s;
int ans[111];
int main()
{
    fast;
    int n, k;
    cin>>n>>k;
    if(k>=n)
        cout<<"unsafe\n";
    else
        cout<<"safe\n";
}






Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<tuple>
#include<cassert>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const int mod = pow(10, 9) + 7;

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(s == u) a--;
    else b--;

    cout << a <<' ' << b << endl;
}

Measured memory_bytes: 256
import math
def num_divisors(n):
    ans = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            if i > 2 and i-1 > n // i: ans.append(i-1)
            if n != i**2 and n//i-1 > n // (n//i):
                ans.append(n//i-1)
    
    return ans

N = int(input())
lst = num_divisors(N)

print(sum(lst))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];

  cout << (a[2] != *min_element(a.begin(), a.end()) && a[2] != *max_element(a.begin(), a.end()) ? "Yes" : "No") << endl;


  
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
n, m = map(int, input().split())
food_arr = []
total = 0
for i in range(n):
   food_arr += list(map(int, input().split()[1:]))
    
counter = Counter(food_arr)
for key, value in counter.items():
  if value == n:
    total += 1
print(total)     

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  double x;
  cin >> x;
  int y = floor(sqrt(x));
  cout << y*y << endl;
  return 0;
}

Measured memory_bytes: 256
// Problem : A - Range Flip Find Route
// Contest : AtCoder - AtCoder Grand Contest 043
// URL : https://atcoder.jp/contests/agc043/tasks/agc043_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 5;

void min_self(int& a, int b) {
	a = min(a, b);
}

int main() {
	int H;
	int W;
	cin >> H >> W;
	vector<string> grid(H);
	for (int row = 0; row < H; row++) {
		cin >> grid[row];
	}
	vector<vector<int>> dp(H, vector<int>(W, INF));
	
	dp[0][0] = grid[0][0] == '#';
	for (int row = 0; row < H; row++) {
		for (int col = 0; col < W; col++) {
			if (row == 0 && col == 0) {
				continue;
			}
			if (row != 0) {
				min_self(dp[row][col], dp[row - 1][col] + (grid[row][col] == '#' && grid[row - 1][col] == '.'));
			}
			if (col != 0) {
				min_self(dp[row][col], dp[row][col - 1] + (grid[row][col] == '#' && grid[row][col - 1] == '.'));
			}
		}
	}
	cout << dp[H - 1][W - 1] << "\n";
}
















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

int main(){
    int a,b;
    cin>>a>>b;
    if(a>b) swap(a,b);
    
    rep(i,b) cout<<a;
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

set<int>s;

vi help(int x){
	auto it = s.find(x);
	vi v;
	v.emplace_back(*it);
	for (int i = 0; i < 2; ++i)
	{
		if(it == s.begin()) break;
		it--;
		v.emplace_back(*it);
	}
	it = s.find(x);
	for (int i = 0; i < 2; ++i)
	{
		it++;
		if(it == s.end()) break;
		v.emplace_back(*it);
	}
	sort(v.begin(), v.end());
	return v;
}

int32_t main(){
    fast_io;
    int n;
    cin>>n;
    int f[n+1],a[n+1];
    fo(i,1,n){
    	cin>>a[i];
    	f[a[i]] = i;
    	s.insert(i);
    }
    int ans = 0;
    fo(i,1,n){
    	vi v = help(f[i]);
    	int id = 0;
    	for (int j = 0; j < v.size(); ++j)
    	{
    		if(v[j] == f[i]) {
    			id = j;
    			break;
    		}
    	}
    	if(id){
    		int val = 1;
    		int l = 0;
    		if(id-1 > 0) l = v[id-2];
    		val *= (v[id-1] - l);
    		int r = n+1;
    		if(id+1 < v.size()) r = v[id+1];
    		val *= (r - v[id]);
    		ans += val*i;
    	}
    	if(id+1 < v.size()){
    		int val = 1;
    		int l = 0;
    		if(id-1 >= 0) l = v[id-1];
    		val *= (v[id]-l);
    		int r = n+1;
    		if(id+2 < v.size()) r = v[id+2];
    		val *= (r - v[id+1]);
    		ans += val*i;
    	}
    	s.erase(f[i]);
    }
    show(ans);
    return 0;
}

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

public class UnionFind
{
    private int[] data;
    public UnionFind(int size)
    {
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);
        if (x != y)
        {
            if (data[y] < data[x])
            {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    public bool IsSameGroup(int x, int y) => Root(x) == Root(y);
    public int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]);
    public int getMem(int x) => -data[Root(x)];
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var uf = new UnionFind(n);
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]) - 1;
            var y = int.Parse(line[1]) - 1;
            uf.Unite(x, y);
        }
        var hs = new HashSet<int>();
        for (int i = 0; i < n; i++)            hs.Add(uf.Root(i));
        Console.WriteLine(hs.Count());
    }
}

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

int main() {
  int a,b,c;
  cin >> a >>b;
  
  c=a*b;
  
  if((c%2)==0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
        ll n;
        cin>>n;
        ll a[n];
        ll count=0;
        for(int i=0;i<n;i++)
        cin>>a[i];
        ll f=1;
        for(int i=0;i<n;i++)
        {
            if(a[i]==f)
            {
                count++;
                f++;
            }
        }
        if(count==0) cout<<"-1";
        else
        cout<<n-count<<endl;
         

      }
      






}












Measured memory_bytes: 1792
n,m = map(int,input().split())
li = [list(map(int,input().split()))for i in range(n)]

li.sort()

ans = 0
for i in range(n):
    a = min(m,li[i][1])
    m -= a
    ans += li[i][0]*a
    if a == 0:
        break
print(ans)


Measured memory_bytes: 27756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main(){
    ll N ,M,ac = 0, p = 0;
    cin >> N >> M;
    vector<ll> score(N,0);
    for(int i = 0; i < M; i++){
        ll num;
        string tmp;
        cin >> num >> tmp;
        if(score[num - 1] == 1) continue;
        if(tmp == "AC"){
            p += -(score[num - 1]);
            score[num - 1] = 1;
        }
        if(tmp == "WA") {
            score[num - 1]--;
        }
    }
    for(int i = 0; i < N; i++){
        if(score[i] == 1){
            ac += score[i];
        }
    }

    cout << ac << " " << p << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;
using P = pair<int,int>;

int main(){

  int N;
  cin >> N;
  int M;

  if(N % 1000 == 0){
    cout << 0 << endl;
  } else {
    M = N / 1000 + 1;
    int ans = M % 1000 * 1000 - N;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long ld;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  ld l;cin>>l;
cout.precision(17);

  cout<<l/3.0*l/3.0*l/3.0<<endl;
  
  return 0;
}


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

using namespace std;

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

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

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

#define MAX 1e5

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

	// チャンネルごとに分ける
	// もっとも重複してる時間帯を探す
	// チャンネル移動で時間を必要とするので、
	// 各チャンネルの時間を1秒先頭にプラスする?

	int n, C;
	cin >> n >> C;
	vector<int> s(n), t(n), c(n);
	rep(i, n) {
		cin >> s[i] >> t[i] >> c[i];
		s[i]--, t[i]--, c[i]--;
	}

	vector<vector<int>> cSum(C, vector<int>(MAX, 0));

	// このアルゴリズム思いついたの天才
	rep(i, n) {
		cSum[c[i]][t[i]]++;
		if(s[i] != 0)
			cSum[c[i]][s[i] - 1]--;
	}

	rep(ch, C) {
		int cnt = 0;
		for (int i = MAX - 1; i >= 0; i--) {
			cnt += cSum[ch][i];
			cSum[ch][i] += cnt - cSum[ch][i];
			if (cSum[ch][i] >= 2) {
				cSum[ch][i] = 1;
			}
		}
	}

	vector<int> exNum(MAX, 0);

	rep(ch, C) {
		rep(i, MAX - 1) {
			if (cSum[ch][i] == 0 && cSum[ch][i + 1] == 1) {
				exNum[i]++;
			}
		}
	}

	int ans = 0;

	rep(i, MAX) {
		int tmp = 0;
		rep(ch, C) {
			tmp += cSum[ch][i];
		}
		if (exNum[i] + tmp == C) tmp += exNum[i];
		ans = max(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13568
#include <iostream>

 

using namespace std;

 

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


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define int long long
#define register rg
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
typedef long long ll;
int sum[100011],n,k,maxx,net[100010];
char a[100001];
bool check(int x) {
	for(int i=1; i<=n-x+1; i++)
		if(sum[i+x-1]-sum[net[i]]<=k)
			return 1;
	return 0;
}
main() {
	//file("a");
	cin>>n>>k;
	scanf("%s",a+1);
	for(int i=1; i<=n; i++) {
		if(a[i]=='1')
			sum[i]=sum[i-1],net[i]=i-1;
		else if(a[i]==a[i-1])
			sum[i]=sum[i-1],net[i]=net[i-1];
		else if(a[i]=='0')
			sum[i]=sum[i-1]+1,net[i]=i-1;
	}
	int l=0,r=n;
	while(l<=r) {
		int mid=(l+r)/2;
		if(check(mid)) {
			l=mid+1;
			if(maxx<=mid)
				maxx=mid;
		} else
			r=mid-1;
	}
	printf("%lld",maxx);
	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>

int main(void){
    //input 
    int N;
    scanf("%d",&N);
    int A[N];
    for(int i = 0; i < N; i++)
    scanf("%d",&A[i]);

    //calcu
    int Ans[N];
    for(int i = 0; i < N; i++){
        Ans[A[i]-1] = i + 1;
    }


    //output
    for(int i = 0; i < N; i++)
    printf("%d ",Ans[i]);
//    printf("\n");
}

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

using vs = vector<string>;

using vi = vector<int>;
using vvi = vector<vi>;

vvi d =
{
    {-1, -1},
    {-1, 0},
    {-1, 1},
    {0, -1},
    {0, 1},
    {1, -1},
    {1, 0},
    {1, 1}
};

int main()
{
    int h, w; cin >> h >> w;

    vs v(h);

    for(int i = 0; i < h; i++) cin >> v[i];

    for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++) if(v[i][j] == '.')
    {
        int cnt = 0;

        for(auto& e : d)
        {
            int y = i + e[0];
            int x = j + e[1];

            if(y < 0 || y >= h) continue;
            if(x < 0 || x >= w) continue;

            if(v[y][x] != '#') continue;

            cnt++;
        }

        v[i][j] = '0' + cnt;
    }

    for(auto& e : v) cout << e << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
2
2 2
5 3

output:
......Q.
Q.......
..Q.....
.......Q
.....Q..
...Q....
.Q......
....Q...
"""

import sys

N = 8
FREE, NOT_FREE = -1, 1


def generate_board(_q_list):
    for queen in _q_list:
        x, y = map(int, queen)
        init_q_check[x][y] = True

    return init_q_check


def print_board():
    for i in range(N):
        for j in range(N):
            if q_check[i][j]:
                if row[i] != j:
                    return None
    for i in range(N):
        line = []
        for j in range(N):
            if row[i] == j:
                line.append('Q')
            else:
                line.append('.')
        print(*line, sep='')

    return None


def recursive(i):
    if i == N:
        print_board()
        return None

    for j in range(N):
        if ((col[j] is NOT_FREE) or
                (dpos[i + j] is NOT_FREE) or
                (dneg[i - j + N - 1] is NOT_FREE)):
            continue

        row[i] = j
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE

        recursive(i + 1)

        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE

    return q_check


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    q_num = int(_input[0])
    q_list = map(lambda x: x.split(), _input[1:])

    # initialize
    row, col = ([FREE] * N for _ in range(2))
    dpos, dneg = ([FREE] * (2 * N - 1) for _ in range(2))

    init_q_check = [[False] * N for _ in range(N)]
    q_check = generate_board(q_list)

    ans = recursive(0)

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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

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

	string w;
	cin >> w;
	
	int a[26];
	fill(a, a + 26, 0);
	
	for(char c : w) a[c - 'a']++;
	
	for(int i = 0; i < 26; i++) if(a[i] % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    void run() {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        if (n % 2 == 0)
            System.out.println(n);
        else
            System.out.println(n * 2);
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21716
import java.util.*;
public class Main {
    public static void main(String[] args){
        Main start=new Main();
        start.start();

    }
    public Main(){
    }
    public void start(){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        long N = sc.nextLong();
        long result=0;
        for(int i=1;i<Math.sqrt(N);i++){
            if(N%i==0&&i*(i+1)<N){
             result=result+(N/i-1);
            }
        }
        System.out.println(result);

    }
    int gcd (int a, int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
}

Measured memory_bytes: 23124
from collections import deque

n = int(input())
q = deque([str(i) for i in reversed(range(1,10,1))])

count = 0

while True:
    item = q.pop()
    last_int = int(item[-1])

    if last_int != 0:
        q.appendleft(item+str(last_int-1))
    q.appendleft(item+str(last_int))

    if last_int != 9:
        q.appendleft(item+str(last_int+1))

    count += 1
    if count == n:
        break

print(item)


Measured memory_bytes: 17012
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define pb(x) push_back(x)
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef unsigned long long ull;
const int mod=1e9+7;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int N=1e4+5;
int main()
{
    int n,m,k;
    while(~scanf("%d",&n))
    {
        int sum=0,tmp=n;
        while(tmp)
        {
            sum+=tmp%10;
            tmp/=10;
        }
        printf("%s\n",n%sum==0?"Yes":"No");
    }
    return 0;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] O = new int[N/2];
        int[] E = new int[N/2];
        for(int i = 0; i < N; i++){
            if(i % 2 == 0){
                O[i/2] = sc.nextInt();
            }else{
                E[i/2] = sc.nextInt();
            }
        }
        sc.close();
        Arrays.sort(O);
        Arrays.sort(E);
        int[][] oMax = new int[N/2][2];
        int t = 0;
        int tCount = 0;
        int idx = 0;
        for(int j = 0; j < N/2; j++){
            if(t == 0){
                t = O[j];
                tCount = 1;
            }else if(O[j] != t){
                oMax[idx][0] = tCount;
                oMax[idx][1] = t;
                idx++;
                t = O[j];
                tCount = 1;
            }else{
                tCount++;
            }
        }
        oMax[idx][0] = tCount;
        oMax[idx][1] = t;

        int[][] eMax = new int[N/2][2];
        t = 0;
        tCount = 0;
        idx = 0;
        for(int j = 0; j < N/2; j++){
            if(t == 0){
                t = E[j];
                tCount = 1;
            }else if(E[j] != t){
                eMax[idx][0] = tCount;
                eMax[idx][1] = t;
                idx++;
                t = E[j];
                tCount = 1;
            }else{
                tCount++;
            }
        }
        eMax[idx][0] = tCount;
        eMax[idx][1] = t;
        Arrays.sort(oMax, (x, y) -> y[0]-x[0]);
        Arrays.sort(eMax, (x, y) -> y[0]-x[0]);

        if(oMax[0][1] != eMax[0][1]){ System.out.println(N - oMax[0][0] - eMax[0][0]);}
        else if(oMax[0][0] + eMax[1][0] >= oMax[1][0] + eMax[0][0]){ System.out.println(N - oMax[0][0] - eMax[1][0]);}
        else{ System.out.println(N - oMax[1][0] - eMax[0][0]);}

    }

}


Measured memory_bytes: 51724
#include <iostream>
#include <queue>
#include <utility>
//#include "../cxx-prettyprint/prettyprint.hpp"

int main() {
    int n, q;
    std::cin >> n >> q;

    std::queue<std::pair<std::string, int>> queue;
    for (int i = 0; i < n; i ++) {
        std::string name;
        int time;
        std::cin >> name >> time;
        queue.push({name, time});
    }

    int clock = 0;
    while (!queue.empty()) {
        auto process = queue.front();
        queue.pop();
        int &time_left = process.second;

        if (time_left > q) {
            time_left -= q;
            queue.push(process);
            clock += q;
        } else {
            std::cout << process.first << " " << clock + time_left << std::endl;
            clock += time_left;
        }
    }
}



Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long W,H,x,y;
  cin >> W >> H >> x >> y;
  int a = 0;
  
  if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) a = 1;
  
  cout << double(W) * double(H) / 2 << " " << a << endl; 
}

Measured memory_bytes: 256
# include <cstdio>
# include <iostream>
# include <algorithm>
# define R register int

using namespace std;

const int maxn=100005;
int r,C,n,cnt,sta[maxn<<1],tp,a,b,c,d;
struct po { int x,y,d,id; }g[maxn<<1];

bool cmp (po a,po b)
{
    if(a.d!=b.d) return a.d<b.d;
    if(a.d==1) return a.y<b.y;
    else if(a.d==2) return a.x<b.x;
    else if(a.d==3) return a.y>b.y;
	return a.x>b.x;
}

int main()
{
    scanf("%d%d%d",&r,&C,&n);
    for (R i=1;i<=n;++i)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if(a!=0&&a!=r&&b!=0&&b!=C) continue;
        if(c!=0&&c!=r&&d!=0&&d!=C) continue;
        ++cnt;
        g[cnt].x=a; g[cnt].y=b; g[cnt].id=i;
        ++cnt;
        g[cnt].x=c; g[cnt].y=d; g[cnt].id=i;
    }
    for (R i=1;i<=cnt;++i)
    {
        if(g[i].x==0) g[i].d=1;
        else if(g[i].y==C) g[i].d=2;
        else if(g[i].x==r) g[i].d=3;
        else if(g[i].y==0) g[i].d=4;
    }
    sort(g+1,g+1+cnt,cmp);
    for (R i=1;i<=cnt;++i)
    {
        if(sta[tp]==g[i].id) { tp--; continue; }
        sta[++tp]=g[i].id;
    }
    if(tp) puts("NO");
    else puts("YES");
    return 0;
}

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

int main(void) {
    int A;
    int N[6]; 
    for(int i=0;i<6;i++){
        N[i]=0;
    }
    for(int i=0;i<6;i++){
        cin>>A;
        N[A]=N[A]+1;
        
    
    }

    for(int j=1;j<5;j++){
        if(N[j]==3){
            cout<<"NO"<<endl;
            return 0;
        }
        
    
    }

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

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

const int DIM = 2e5 + 5;

int bit[DIM], ans[DIM];
vector<int> lst1[DIM], lst2[DIM];

void update( int p, int x ) {
    for( int i = p; i < DIM; i += (i & (-i)) )
        bit[i] += x;
    return;
}

int query( int p ) { int x = 0;
    for( int i = p; i >= 1; i -= (i & (-i)) )
        x += bit[i];
    return x;
}

int main( void ) {
    
    int n, m;
    cin >> n >> m;
    
    for( int i = 1; i <= n; i ++ ) {
        int x, y;
        cin >> x >> y;
        
        lst1[y].push_back( x );
    }
    
    for( int i = 1; i <= m; i ++ )
        for( int j = i; j <= (m << 1); j += i )
            lst2[j].push_back( i );
    
    for( int i = 1; i <= (m << 1); i ++ ) {
        for( int x : lst2[i] )
            ans[x] += query( i ) - query( i - x );
        for( int x : lst1[i] )
            update( x, 1 );
    }
    
    for( int i = 1; i <= m; i ++ )
        cout << n - ans[i] << "\n";
    
    return 0;
}

Measured memory_bytes: 31360
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int A[114514],B[114514];
    cin >> N;
    REP(i,N){
        cin >> A[i];
        B[A[i]]=i+1;
    }
    REP(i,N){
        cout << B[i+1] << " ";
    }
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 2432
r=lambda x:x if u[x]<0else r(u[x])
n,m,*e=map(int,open(0).read().split())
u=[-1]*-~n
t=n*~-n//2
a=[t]
for x,y in zip(e[-2:1:-2],e[:1:-2]):
 x,y=sorted((r(x),r(y)))
 if x!=y:t-=u[x]*u[y];u[x]+=u[y];u[y]=x
 a+=[t]
print(*a[::-1],sep='\n')

Measured memory_bytes: 25308
#include <iostream>

using namespace std;

int main( void )
{
	const char *key[] = { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	const int size[] = { 5, 3, 3, 3, 3, 3, 4, 3, 4 };
	int n;
	cin >> n;
	while(n--) {
		char buff[1025];
		scanf("%s", buff);
		char msg[77]; msg[0] = 0;
		int index = -1, no, pnt = 0;
		for(int i=0; buff[i]; ++i) {
			if('0' == buff[i]) {
				if(index != -1) {
					msg[pnt++] = key[no][index];
					msg[pnt] = 0;
				}
				index = -1;
			}
			else { // 1~9
				no = buff[i]-'1';
				index = (index+1) % size[no];
			}
		}
		cout << msg << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define pb push_back
#define ff first
#define ss second
#define all(s) (s).begin(), (s).end()
const ll mod = 1e9 + 7;

ll binpow(ll x, ll y)
{
    ll res = 1;
    while (y)
    {
        if (y & 1)
            res = (res * x) % mod;
        y >>= 1;
        x = (x * x) % mod;
    }
    return res;
}

int main()
{
    int n, t;
    cin >> n >> t;
    ll ans = 0, mn = 0, mx = 0;
    for (int i = 0; i <= n; i++){
        mn += i, mx += n - i;
        if (i >= t - 1)
            ans += mx - mn + 1, ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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


Measured memory_bytes: 256
from collections import deque

n,u,v = map(int, input().split())
neighbors = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    neighbors[a].append(b)
    neighbors[b].append(a)

vds = [-1]*n

qp = deque([])

qp.append(v-1)

vds[v-1] = 0

while qp:
    now = qp.pop()
    for nxt in neighbors[now]:
        if vds[nxt] == -1:
            qp.appendleft(nxt)
            vds[nxt] = vds[now] + 1

uds = [-1]*n
ucost = [-1]*n

qp.append(u-1)

uds[u-1] = 1
ucost[u-1] = 0

while qp:
    now = qp.pop()
    for nxt in neighbors[now]:
        if uds[nxt] == -1 and nxt != v-1:
            qp.appendleft(nxt)
            uds[nxt] = 1
            ucost[nxt] = ucost[now] + 1

ans = 0

for i in range(n):
    if uds[i] != -1 and ucost[i] <= vds[i] and ans < vds[i]:
        ans = vds[i]

            
print(ans-1)


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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += (n - i + 1) * 1LL * i;
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    if (a > b) {
      swap(a, b);
    }
    ans -= a * 1LL * (n - b + 1);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long 
#define endl "\n"
using namespace std;

void solve()
{
	//Enter code here Tanmay::
	int n;
	cin>>n;
	
	int arr[n];
	int max=INT_MIN;
	int c=0;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	if(n==1)
	{
		cout<<"0";
		exit(0);
	}
	for(int i=0;i<n-1;i++)
	{
		if(arr[i+1]<=arr[i])
		c++;
		else
		c=0;
		if(c>max)
		{
			max=c;
		}
	}
	cout<<max;
	
}

	


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
void fastscan(int &number) 
{ 
    //variable to indicate sign of input number 
    bool negative = false; 
    register int c; 
  
    number = 0; 
  
    // extract current character from buffer 
    c = getchar(); 
    if (c=='-') 
    { 
        // number is negative 
        negative = true; 
  
        // extract the next character from the buffer 
        c = getchar(); 
    } 
  
    // Keep on extracting characters if they are integers 
    // i.e ASCII Value lies from '0'(48) to '9' (57) 
    for (; (c>47 && c<58); c=getchar()) 
        number = number *10 + c - 48; 
  
    // if scanned input has a negative sign, negate the 
    // value of the input number 
    if (negative) 
        number *= -1; 
} 

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
//#define double long double
const int maxn=2e5+10;
const int mod=998244353;
double dis[1005];
vector<pair<int,double>>E[1005];

struct ac
{
    double x,y,r;
};
ac a[1005];




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    double sx,sy,ex,ey;
    cin>>sx>>sy>>ex>>ey;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
       cin>>a[i].x>>a[i].y>>a[i].r;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            double temp=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
            temp-=a[i].r+a[j].r;
            temp=max(temp,0.0);
            E[i].pb({j,temp});
            E[j].pb({i,temp});
        }
    }
    double t=sqrt((sx-ex)*(sx-ex)+(sy-ey)*(sy-ey));
    /*E[0].pb({n+1,t});
    E[n+1].pb({0,t});*/
    dis[n+1]=t;
    for(int i=1;i<=n;i++)
    {
        double temp=sqrt((sx-a[i].x)*(sx-a[i].x)+(sy-a[i].y)*(sy-a[i].y));
        double temp2=sqrt((ex-a[i].x)*(ex-a[i].x)+(ey-a[i].y)*(ey-a[i].y));
        temp-=a[i].r;
        temp2-=a[i].r;
        temp=max(0.0,temp);
        temp2=max(0.0,temp2);
        E[i].pb({0,temp});
        E[0].pb({i,temp});
        E[n+1].pb({i,temp2});
        E[i].pb({n+1,temp2});

    }
    priority_queue<pair<double,int>>q;
    for(int i=1;i<=n;i++)
    {
        dis[i]=1e10;
    }
    dis[0]=0;
    q.push({0,0});
    while(!q.empty())
    {
        int u=q.top().second;
        q.pop();
        for(auto &v:E[u])
        {
            if(dis[v.first]>dis[u]+v.second)
            {
                dis[v.first]=dis[u]+v.second;
                q.push({-dis[v.first],v.first});
            }
        }
    }
    cout<<fixed<<setprecision(10)<<dis[n+1]<<'\n';



}


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

int main() {
    int n, l, r;

    while (cin >> n >> l >> r, n || l || r) {
	vector<int> a(n);
	for (auto& i : a) cin >> i;

	int count = 0;
	for (int x = l; x <= r; x++) {
	    int i;
	    for (i = 0; i < n; i++) {
		if (x % a[i] == 0)
		    break;
	    }

	    if ((i < n && i % 2 == 0) || (i >= n && n % 2 == 0))
		count++;
	}

	cout << count << endl;
    }

    return 0;
}



Measured memory_bytes: 3096
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		out.println((int)ceil((double)(a+b)/2));
	}
}


Measured memory_bytes: 23764
#include<stdio.h>
int main(){
int a,b,c,s=3;
scanf("%d %d %d",&a,&b,&c);
if(a==b)s--;
if(a==c)s--;
if(b==c)s--;
if(s==0)s=1;
printf("%d",s);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int r;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> r;
	cout << r * r << endl;	
	return 0; 
}
//do smt instead of nothing! never give up!

Measured memory_bytes: 256