akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

int a[3],b[3];

signed main(){
	int counter[4] = {0};
	FOR(i,0,3){
		int a,b;
		cin >> a >> b;
      a--;
      b--;
		counter[a]++;
		counter[b]++;
	}
	FOR(i,0,4){
		if(counter[i] > 2){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
PY=[]
for i in range(M):
    PY.append(list(map(int,input().split())))
    PY[i].append(i)
PY=sorted(PY,key=lambda x: x[1])
PY=sorted(PY,key=lambda x: x[0])

X=[1]
for i in range(1,M):
    if PY[i][0] == PY[i-1][0]:
        X.append(X[-1]+1)
    else:
        X.append(1)

for i in range(M):
    PY[i].append(str(PY[i][0]).rjust(6,'0')+\
              str(X[i]).rjust(6,'0'))

PY=sorted(PY,key=lambda x: x[2])

for i in range(M):
    print(PY[i][3])

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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D) {
		cout << "Left" << endl;
	}
	else if (A + B < C + D) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

ll que1sum[300000];
ll que2sum[300000];

int main(){
  int N; cin >> N;
  vector<ll> v(3*N);
  rep(i,3*N){
    cin >> v[i];
  }
  priority_queue<ll, vector<ll>, greater<ll>> que1;
  rep(i,N){
    que1.push(v[i]);
    que1sum[N-1]+=v[i];
  }
  for(int i=N;i<2*N;i++){
    que1.push(v[i]);
    que1sum[i]=que1sum[i-1]+v[i]-que1.top();
    que1.pop();
  }
  priority_queue<ll> que2;
  for(int i=2*N;i<3*N;i++){
    que2.push(v[i]);
    que2sum[2*N]+=v[i];
  }
  for(int i=2*N-1;i>=N;i--){
    que2.push(v[i]);
    que2sum[i]=que2sum[i+1]+v[i]-que2.top();
    que2.pop();
  }
  ll ans=que1sum[N-1]-que2sum[N];
  for(int i=N-1;i<2*N;i++){
    ll quesum=que1sum[i]-que2sum[i+1];
    if(quesum>ans) ans=quesum;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7156
n,a,b,c = map(int,input().split())
state = [a,b,c]

def stoi(s):
    if s == "AB":
        return [0,1]
    if s == "AC":
        return [0,2]
    return [1,2]
itos = ["A","B","C"]
s = [stoi(input()) for _ in range(n)]

arr = [""]*n

def sim():
    for idx,select in enumerate(s):
        if state[select[0]] == 0 and state[select[1]] == 0:
            print("No")
            exit()
        if state[select[0]] == 0:
            arr[idx] = itos[select[0]]
            state[select[0]] += 1
            state[select[1]] -= 1
        elif state[select[1]] == 0:
            arr[idx] = itos[select[1]]
            state[select[1]] += 1
            state[select[0]] -= 1
        elif state[select[0]] == 1 and state[select[1]] > 1:
            arr[idx] = itos[select[0]]
            state[select[0]] += 1
            state[select[1]] -= 1
        elif state[select[1]] == 1 and state[select[0]] > 1:
            arr[idx] = itos[select[1]]
            state[select[1]] += 1
            state[select[0]] -= 1
        else:
            if idx == n-1:
                arr[idx] = itos[select[0]]
            else:
                if select[0] in s[idx+1]:
                    arr[idx] = itos[select[0]]
                    state[select[0]] += 1
                    state[select[1]] -= 1
                else:
                    arr[idx] = itos[select[1]]
                    state[select[1]] += 1
                    state[select[0]] -= 1
sim()

print("Yes")
for choice in arr:
    print(choice)

Measured memory_bytes: 85844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second



void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define MAXN  100
#define MOD   1000000007
#define int long long
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef cc_hash_table<int, int, hash<int > > ht;


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    int a[n+1];

    for(int i=1;i<=n;i++)
       cin>>a[i];

    vector<int> v;
    int ans[n+1]={0};
    for(int i=n/2+1;i<=n;i++){
        ans[i]=a[i];
    }
    for(int i=n/2;i>=1;i--){
        int sum=0;
        for(int j=i+i;j<=n;j+=i){
            sum+=ans[j];
        }
        if(sum%2!=a[i]%2)
            ans[i]++;
    }

    for(int i=1;i<=n;i++){
        if(ans[i]){
            v.push_back(i);
        }
    }
    cout<<v.size()<<"\n";
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";

}


Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 0x7fffffff
string x1 = "dream";
string x2 = "erase";
int main()
{
    ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
    string ch;
    cin >> ch;
    int number = ch.size(),i;
    bool zero = 1;
    for (i = 0; i < number; )
    {
        if (ch[i] == 'd')
        {
            int j;
            for ( j = i; j <= i + 4; j++)
            {
                if (j >= number || x1[j - i] != ch[j])
                {
                    zero = 0;
                    break;
                }
            }
            if (j == i + 5)
            {
                i = j;
                if (ch[j] == 'e' && ch[j + 1] == 'r' && number == 7)
                    i + 2;
                else if (ch[j] == 'e' && ch[j + 1] == 'r' && ch[j + 2] != 'a')
                    i += 2;
            }
        }
        else if (ch[i] == 'e')
        {
            int j;
            for (j = i; j <= i + 4; j++)
            {
                if (j >= number || x2[j - i] != ch[j])
                {
                    zero = 0;
                    break;
                }
 
            }
            if (j == i + 5)
            {
                i = j;
                if (ch[j] == 'r')
                    i++;
            }
        }
        else
            zero = 0;
        if (!zero)
            break;
    }
    if (zero)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

int main(){
    int n,m; cin >> n >> m;
    vector<int> wa(n,0);
    vector<bool> solved(n,false);
    rep(i,m){
        int p; string s;
        cin >> p >> s;
        p--;
        if(s == "AC"){
            solved[p] = true;
        }else{
            if(!solved[p]) wa[p]++;
        }
    }
    int ac = 0, pena = 0;
    rep(i,n){
        if(solved[i]) ac++;
        if(solved[i]) pena += wa[i];
    }
    cout << ac << ' ' << pena;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  for(int i = 0; i <= 100000; i++){
    if((int)(i * 0.08) == a && (int)(i * 0.1) == b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3596
#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;

struct ST {
  int b, c;
};
bool operator<(const ST& x, const ST& y){
  return x.c > y.c;
}


int main(){
  int N, M;
  cin >> N >> M;
  priority_queue<int,std::vector<int>, std::greater<int>> que;
  rep(i,N){
    int a;
    cin >> a;
    que.push(a);
  }

  vector<ST> v;
  rep(i,M){
    ST st;
    cin >> st.b >> st.c;
    v.emplace_back(st);
  }
  sort(ALLOF(v));

  rep(i,v.size()){
    int b = v[i].b;
    int c = v[i].c;
    while(b>0){
      if(c <= que.top()) break;
      que.pop();
      que.push(c);
      b--;
    }
  }

  ll ret = 0;
  while(!que.empty()){
    ret += que.top(); que.pop();
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
int num(int n)
{
  int ans=0;
  while(n)
  {
    n/=10;
    ans++;
  }
  return ans;
}
int main()
{
  int n,ans=0;
  cin>>n;
  for(int i=1;i<=n;i++)
    if(num(i)&1)
      ans++;
  cout<<ans<<"\n";
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char s[100010];
  int n;
  long long int ans=0,cnt[4]={},th[100010],l,r;
  scanf("%s",s);
  n=strlen(s);
  th[0]=1;
  for(int i=1;i<n;i++)
    th[i]=th[i-1]*3%1000000007;
  for(int i=0;i<n;i++){
    if(i>1&&s[i]=='?')
      cnt[3]++;
    else if(i>1&&s[i]=='C')
      cnt[2]++;
    else if(i==0&&s[i]=='A')
      cnt[0]++;
    else if(i==0&&s[i]=='?')
      cnt[1]++;
  }
  l=cnt[0]*th[cnt[1]]%1000000007;
  if(cnt[1])
    l+=cnt[1]*th[cnt[1]-1]%1000000007;
  l%=1000000007;
  r=cnt[2]*th[cnt[3]]%1000000007;
  if(cnt[3])
    r+=cnt[3]*th[cnt[3]-1]%1000000007;
  r%=1000000007;
  if(s[1]=='B'||s[1]=='?')
    ans+=l*r%1000000007;
  for(int i=2;i<n-1;i++){
    if(s[i]=='?')
      cnt[3]--;
    else if(s[i]=='C')
      cnt[2]--;
    if(s[i-1]=='A')
      cnt[0]++;
    else if(s[i-1]=='?')
      cnt[1]++;
    if(s[i]=='B'||s[i]=='?'){
      l=cnt[0]*th[cnt[1]]%1000000007;
      if(cnt[1])
        l+=cnt[1]*th[cnt[1]-1]%1000000007;
      r=cnt[2]*th[cnt[3]]%1000000007;
      if(cnt[3])
        r+=cnt[3]*th[cnt[3]-1]%1000000007;
      ans+=l*r%1000000007;
      ans%=1000000007;
    }
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 1024
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()
    T = SS()
    len_S = len(S)
    len_T = len(T)

    ans = len(T)
    for i in range(len_S - len_T + 1):
        diff = len([(j, k) for j, k in zip(S[i:i+len_T], T) if j != k])
        ans = min(diff, ans)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9940
#include <iostream>
#include<vector>
#include<string>
#include<bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
using namespace std;





int main(){
ios::sync_with_stdio(false);
  cin.tie(0);
string s;
cin>>s;
int n=s.size();
vector<int> a;
int i=0;
while(i<n){
    if(s[i]=='A'){
        a.pb(1);

    }
    else if(i+1<n && s[i]=='B' && s[i+1]=='C'){
            a.pb(2);
    i++;

    }
   else {
        a.pb(3);

    }
    i++;

}
ll ans=0;
int x=0;
for(int i=0;i<a.size();i++){

    if(a[i]==3)
        x=0;
    if(a[i]==2)
        ans+=x;
    if(a[i]==1)
        x++;

}


cout<<ans<<endl;
}


Measured memory_bytes: 1680
#include<iostream>
#include<cstdio>
#define ll long long
#define up(a,b) a=(a+b)%mod
using namespace std;
const int mod=1000000007;
const int maxn=2000100;
int n;
ll f[maxn],s[maxn],ans=0;
int main()
{
	scanf("%d",&n);
	f[0]=s[0]=1;
	for(int i=1;i<=2*n;i++)
	{
		int l=max(0,i-n-1),r=min(n-1,i-3);
		if(l<=r) f[i]=(s[r]-(l==0?0:s[l-1])+mod)%mod;
		if(i<=n) up(f[i],f[i-1]);
		s[i]=(s[i-1]+f[i])%mod;
	}
	for(int i=n;i<=2*n;i++)
		up(ans,f[i]);
	for(int i=0;i<=n-2;i++)
		up(ans,f[i]*(n-1)%mod*(n-1)%mod);
	printf("%lld",ans);		
	return 0;
}

Measured memory_bytes: 31488
i,j = map(int,input().split())
a = list()
b = list()
c = list()
c_e = 0

for r in range(i):
    e = list(map(int,input().split()))
    a.append(e)
    
for r in range(j):
    n = int(input())
    b.append(n)
    
for r in range(i):
    for t in range(j):
        c_e += a[r][t]*b[t]
    else:
        c.append(c_e)
        c_e = 0
        
for s in range(len(c)):
    print(c[s])
    
    
    
    


Measured memory_bytes: 6016
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,a[100005],i,x;
main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x;
		x++;
		a[x]++;
		a[x-1]++;
		a[x+1]++;
	}
	x=0;
	for(i=0;i<100005;i++)x=max(x,a[i]);
	cout<<x;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,i,c=0;
int a[50];
int main()
{	
	cin >> n;
	for(i=0; i<n; i++)
	{
		cin >> a[i];
	}
	for(i=1; i<=n; i++)
	{
		if(a[i-1]!=i)
			c=c+1;		
	}
	if(c==0 || c==2) cout << "YES";
	else cout <<"NO";
	
	
}

Measured memory_bytes: 256
s = input()
n = len(s)
ans = 0
for i in range(n):
    if s[i] == 'A':
        ans -= i
##        print('i')
        break

for j in reversed(range(0, n)):
    if s[j] == 'Z':
        ans += j
        break

print(ans + 1)


Measured memory_bytes: 3516
#include <stdio.h>

int rot[4][7] = {
    {0, 2, 6, 3, 4, 1, 5}, // N
    {0, 4, 2, 1, 6, 5, 3}, // E
    {0, 3, 2, 6, 1, 5, 4}, // W
    {0, 5, 1, 3, 4, 6, 2}, // S
};

int dice[2][7];
int tr['Z'];

void dice_init(int *d_nums) {
    int i;
    int t[4] = {'N', 'E', 'W', 'S'};
    for (i = 1; i <= 6; i++)
        dice[0][i] = d_nums[i];
    for (i = 0; i < 4; i++)
        tr[t[i]] = i;
}

int main(void) {
    int i, k1, k2;
    int d_nums[7];
    char NEWS[101];
    char *p;
    for (i = 1; i <= 6; i++)
        scanf("%d", d_nums + i);
    scanf("%s", NEWS);
    dice_init(d_nums);
    p = NEWS;
    for (k1 = 0, k2 = 1; *p; k1 = !k1, k2 = !k2) {
        for (i = 1; i <= 6; i++)
            dice[k2][i] = dice[k1][rot[tr[*p]][i]];
        p++;
    }
    printf("%d\n", dice[k1][1]);
    return 0;
}


Measured memory_bytes: 2140
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N,L;cin>>N>>L;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  int check = 0;
  int point = -1;
  for (int i = 0; i < N-1; i++)
  {
    if((vec[i]+ vec[i+1]) >= L) check = 1,point = i+1;
  }
  if(check == 0){
    cout<<"Impossible"<<endl;
    return;
}
  
  cout<<"Possible"<<endl;
  for (int i = 1; i < point; i++)
  {
    cout<<i<<endl;
  }
  for (int i = N-1; i >= point+1; i--) 
  {
    cout<<i<<endl;
  }
  cout<<point<<endl;
  
  



  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double ans = w*h/2;
  int ans2;
  if(w/2 == x && h/2 == y)ans2 =1;
  else ans2 = 0;
  printf("%lf %d",ans, ans2);
  	
}


Measured memory_bytes: 256
n= int(input())
n -= 1
arr= sorted(list(map(int,input().split())))[::-1]
ans = arr[0]
i = 1
while n > 1:

    if n > 2:
        ans += arr[i]*2
        i += 1
        n -= 2
    elif n ==2:
        ans += arr[i]
        break
                
print(ans)

Measured memory_bytes: 31388
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp45 {
    class Program {
        static int ans;

        static void Main(string[] args) {
            int X = int.Parse(Console.ReadLine());

            //解答
            ans = X;

            bool loop = true;

            while (loop) {
                //Xが素数なら
                if (isPrime(ans)) {
                    //ループを抜ける
                    loop = false;
                } else {
                    //Xに1を足して次のループへ
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }

        static bool isPrime(int X) {
            for (int i = 2; i <= Math.Sqrt(X); i++) {
                if ((ans % i) == 0) {
                    return false;
                }
            }
            return true;
        }
    }
}


Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        string S = NextString();
        int N = S.Length;

        long len = 0, a = 0, ab = 0, abc = 0;
        foreach (char c in S)
        {
            if (c == 'A') { a += RepPow(3, len); }
            else if (c == 'B') { ab += a; }
            else if (c == 'C') { abc += ab; }
            else
            {
                abc = abc * 3 + ab;
                ab = ab * 3 + a;
                a = a * 3 + RepPow(3, len);
                len++;
            }
            a %= MOD;
            ab %= MOD;
            abc %= MOD;
        }
        Console.WriteLine(abc % MOD);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
    public static long RepPow(long x, long p, long m = 1000000007)
    {
        if (p == 0) return 1;
        if (p == 1) return x % m;
        long b = RepPow(x, p / 2, m) % m;
        if (p % 2 == 0) { return (b * b) % m; }
        else { return (x * ((b * b) % m)) % m; }
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 11744
n, a, b  = map(int, input().split())

for _ in range(n):
    if a < b:
        a += 1
        if a == b:
            print('Borys')
            exit()

    if b <= n:
        b += 1
    else:
        b -= 1
        if b == a:
            print('Alice')
            exit()
else:
    print('Draw')

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
  int N,L; cin>>N>>L;
  bool A=true;
  int ans=0;
  int count;
  rep(i,N){
    ans+=L+i;
    if(i==0)count=abs(L+i-0);
    else count=min(count,abs(L+i-0));
    if(L+1==0-count)A=false;
  }
  cout<<(A==false? ans+count:ans-count)<<endl;
}

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

typedef struct {
    int x;
    int y;
} point_t;
point_t a[300*300*2];
long b[300*300*2];

inline long dist(const point_t a, const point_t b){
    return labs(a.x-b.x)+labs(a.y-b.y);
}

int main(void){
    long h, w, d;
    scanf("%ld %ld %ld\n", &h, &w, &d);
    long t;
    for(long i=0; i<h; i++){
        for(long j=0; j<w; j++){
            scanf("%ld", &t);
            a[t].x = j;
            a[t].y = i;
        }
    }
    const long n = h*w-d+1;
    for(long i=0; i<n; i++){
        b[i+d] = b[i] + dist(a[i], a[i+d]);
    }
    long q;
    scanf("%ld", &q);
    long l, r;
    for(long i=0; i<q; i++){
        scanf("%ld %ld\n", &l, &r);
        printf("%ld\n", b[r]-b[l]);
    }
    return 0;
}


Measured memory_bytes: 2432
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) ((x) * (x))
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas
#define fname "parray"
#define fin fname".in"
#define fout fname".out"
#define files freopen(fin, "r", stdin);freopen(fout, "w", stdout);
namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n, d;
    cin >> n >> d;
    int ans = 0;
    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        ans += (x*x + y * y <= d*d);
    }
    put(ans);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
//    files
    int q = 1;
//    cin >> q;
    while (q--) solve();
}



Measured memory_bytes: 3188
N=int(input())
t=[0]*N
r=set(range(N))
for _ in[0]*N:
 x,y,z=list(map(int,input().split()))
 t[x]=[y,z]+[0]*2+[(y!=-1)+(z!=-1)]+[0]*2
 r-={y,z}
def f(i,p,s,d):
 if i<0:return-1
 l,r=t[i][:2]
 t[i][2:]=[p,s,t[i][4],d,max(f(l,i,r,d+1),f(r,i,l,d+1))+1]
 return t[i][-1]
f(r.pop(),-1,-1,0)
for i in range(N):
 print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(i,*t[i][2:],'root'if not t[i][5]else'internal node'if t[i][4]else'leaf'))


Measured memory_bytes: 5608
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll l[90];
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= 86; i++) {
        l[i] = l[i - 1] + l[i - 2];
    }
    int n;
    cin >> n;
    cout << l[n] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	string S,T;
	cin >> S >> T;
	string answer = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
  	bool B = false;
	for(int i = 0;i < S.size() - T.size() + 1;i++) {
		bool A = true;
		for(int j = 0;j < T.size();j++) {
			if(S.at(i + j) != '?' && S.at(i + j) != T.at(j)) {
				A = false;
			}
		}
		if(A == true) {
			string cnt = S;
			for(int j = 0;j < T.size();j++) {
				cnt.at(i + j) = T.at(j);
			}
			for(int j = 0;j < S.size();j++) {
				if(cnt.at(j) == '?') {
					cnt.at(j) = 'a';
				}
			}
			answer = min(answer,cnt);
          	B = true;
		}
	}
	if(B == false) {
		cout << "UNRESTORABLE" << endl;
	}
	else {
		cout << answer << endl;
	}
}

Measured memory_bytes: 256
n, a, b = gets.strip.split.map(&:to_i)

def digit_sum(n)
    sum = 0
    while n > 0 do
        sum += n % 10
        n /= 10
    end
    sum
end

ans = (1..n)
        .map { |i| [i, digit_sum(i)] }
        .select { |d| a <= d[1] && d[1] <= b }
        .inject(0) { |sum, d| sum + d[0] }

puts ans

Measured memory_bytes: 2172
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
 
int main(){
  int Q;
  cin>>Q;
  VI L(Q),R(Q);
  rep(i,Q) cin>>L[i]>>R[i];
  VI X(100100);
  rep(i,100100) if(i>1) X[i]=1;
  rep(i,100100){
    if(X[i]==1) rep(j,100100/i){
      if(i*(j+2)<100100) X[i*(j+2)]=0;
    }
  }
  VI B(100100);
  rep(i,100100) if(X[i] and X[(i+1)/2]) B[i]++;
  VI C(100100);
  rep(i,100100) if(i) C[i]=C[i-1]+B[i];
  rep(i,Q) cout<<C[R[i]]-C[L[i]-1]<<endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    private static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        long[] left = new long[n + 1];
        long[] right = new long[n + 1];
        for (int i = 0; i < n; i++) {
            left[i + 1] = gcd(left[i], a[i]);
            right[n - i - 1] = gcd(right[n - i], a[n - i - 1]);
        }
        long max = 0;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, gcd(left[i], right[i + 1]));
        }
        System.out.println(max);
    }

}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);
ll numberOfMul(ll a, ll b, ll val)
{
    return max((ll)0,b/val-(a-1)/val);
}
int main()
{
	IOS;
    cout.precision(30);
    ll a,b,c,d; cin >> a >> b >> c >> d;
    cout << b - a + 1 - ( numberOfMul(a,b,c) + numberOfMul(a,b,d) - numberOfMul( a , b , c * d / __gcd(c,d) ) );

    return 0;
}


Measured memory_bytes: 256
'use strict'
function main(input) {
  input = input.trim().split('\n')[1].split(' ').map(val => Number(val))
  const length = input.length
  const sorted = [...input].sort((a, b) => b - a)
  let ans = 0

  sorted.forEach((cur, i) => {
    let count = 0
    const diff = cur - (i === length - 1 ? 0 : sorted[i + 1])
    if (diff) {
      let newArray = []
      input.forEach((val, j) => {
        if (val === cur) {
          if (!(j && input[j - 1] === val)) {
            count++
          }
          newArray.push(val - diff)
        } else {
          newArray.push(val)
        }
      })
      ans += count * diff
      input = [...newArray]
    }
  })
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main(void) {

    int lateTime = 10, lateIndex = 0, ans = 0;
    vector<int> nums(5);
    for(int i=0;i<5;i++){
        cin >> nums[i];
        if( 0 < nums[i] % 10 && nums[i] % 10 < lateTime ){
            lateTime = nums[i] % 10;
            lateIndex = i;
        }
        while( nums[i] % 10 != 0 ){
            nums[i]++;
        }
        ans += nums[i];
    }
    cout << ans - (10-lateTime) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 = 1e10;
typedef pair<ll,ll> P;

int main(){
    int n;
    double x,y;
    double townx[8];
    double towny[8];
    double dist[10][10];
    cin >> n;
    rep(i,n){
        cin >> townx[i] >> towny[i];
    }
    double c = 0;
    double k = 1;
    rep(i,n-1) FOR(j,i+1,n){
        c +=  sqrt((townx[i]-townx[j])*(townx[i]-townx[j])+(towny[i]-towny[j])*(towny[i]-towny[j]));
    }
    cout << fixed << setprecision(10) << c*2/n << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 30
int main()
{
  int i,j,n,m,c,b[N]={},a[N][N]={},sum=0,ct=0;
  scanf("%d%d%d",&n,&m,&c);
  for(i=0;i<m;i++){
    scanf("%d",b+i);
  }
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      sum+=a[i][j]*b[j];
    }
    sum+=c;
    if(sum>0){
      ct++;
    }
    sum=0;
  }
  printf("%d\n",ct);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b, c, c7 = 0, c5 = 0;
    cin >> a >> b >>c;
    
    if(a == 5){
        c5++;
    } else if(a == 7){
        c7++;
    }
    
    if(b == 5){
        c5++;
    } else if(b == 7){
        c7++;
    }
    
    if(c == 5){
        c5++;
    } else if(c == 7){
        c7++;
    }
    
    
    if(c7 == 1 && c5 == 2 ){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    
    //cout << a.at(b - 1) << endl;

    return 0; 
}


Measured memory_bytes: 3568
#include<bits/stdc++.h> //Mr_Mandal
#define PI_INT 3.14159265358979323846
#define PI acos(-1.0)
#define LL long long
#define N 100000007
#define MOD 10000007
#define MX numeric_limits<long long>::max();
#define MN numeric_limits<long long>::min();
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define FILL(v, n) fill(v.begin(), v.end(), n);
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define PRINT(v) for(int i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;
#define SCAN(v) for(int i=0; i<n; i++) { int temp; cin>>temp; v.push_back(temp); }
#define SORT(v) sort(v.begin(), v.end());
#define VECT(v) vector<int>v
#define SCF(f) scanf("%d", &f)
#define PNF(f) printf("%d\n", f)
#define CASEP(v) cout<<"Case "<<c<<": "<<v<<"\n"

using namespace std;

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

    LL a=n/500;
    n%=500;
    LL b=n/5;

    LL sum=(a*1000)+(b*5);

    cout<<sum<<"\n";

    return 0;
}


Measured memory_bytes: 256
import numpy as np
d, g = map(int, input().strip().split(' '))
p = [0] * d
c = [0] * d
num = []
for i in range(d):
  p[i], c[i] = map(int, input().strip().split(' '))
for j in range( 2**d ):
  csum = 0; n = 0; jpl = []
  for i in range(d):
    if j >= 2**(d-i-1):
      jp = 1
      j = j - 2**(d-i-1)
    else:
      jp = 0
      jpl.append(i)
    csum = csum + ( 100 * (i+1) * p[i] + c[i] ) * jp
    n = n + p[i] * jp
  if csum < g and jpl != []:
    i = max(jpl)
    remain = int(np.ceil( ( g - csum ) / ( 100 * (i+1) ) ))
    if remain < p[i]:
      n = n + remain
      num.append(n)
    else:
      pass
  else:
    num.append(n)
print(min(num))

Measured memory_bytes: 14428
#define DEBUG 0

/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 3/23/2019, 10:22:47 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N;
vector<vector<int>> V;
typedef tuple<int, int> edge;
vector<edge> E;

void flush()
{
  int S = V.size();
  for (auto i = 0; i < S; i++)
  {
    for (auto j = i + 1; j < S; j++)
    {
      for (auto x : V[i])
      {
        for (auto y : V[j])
        {
          E.push_back(edge(x, y));
        }
      }
    }
  }
  cout << E.size() << endl;
  for (auto x : E)
  {
    cout << get<0>(x) << " " << get<1>(x) << endl;
  }
}

int main()
{
  cin >> N;
  if (N % 2 == 0)
  {
    for (auto i = 1; i <= N / 2; i++)
    {
      V.push_back({i, N + 1 - i});
    }
  }
  else
  {
    V.push_back({N});
    N--;
    for (auto i = 1; i <= N / 2; i++)
    {
      V.push_back({i, N + 1 - i});
    }
  }
  flush();
}

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

using namespace std;

class UnionFind {
  unordered_map<int, int> graph_;
  unordered_map<int, int> sizes_;

 public:
  int Root(int key) {
    if (graph_.count(key) == 0 || graph_[key] == key) {
      return key;
    } else {
      return graph_[key] = Root(graph_[key]);
    }
  }

  bool Same(int key1, int key2) { return Root(key1) == Root(key2); }

  void Unite(int key1, int key2) {
    if (Same(key1, key2)) {
      return;
    }

    int root1 = Root(key1);
    int root2 = Root(key2);
    int size = Size(root1) + Size(root2);
    graph_[root1] = root2;
    sizes_[root2] = size;
  }

  int Size(int key) {
    int root = Root(key);
    return sizes_.count(root) > 0 ? sizes_[root] : 1;
  }
};

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  UnionFind uf;
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    uf.Unite(y, x);
  }

  set<int> ans;
  for (int i = 0; i < n; ++i) {
    ans.insert(uf.Root(i));
  }

  cout << ans.size() << '\n';
}

Measured memory_bytes: 6448
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int N;
  cin >> N;
  int ans = N/3;
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main() {int N,M,i,j;char RB[105][105];while (scanf("%d %d",&N,&M)!=EOF && N && M) {for (i=0;i<N;scanf("%s",&RB[i++]));i=0,j=0;while (RB[i][j]!='?' && RB[i][j]!='.') {if (RB[i][j]=='>') RB[i][j++]='?'; else if (RB[i][j]=='<') RB[i][j--]='?'; else if (RB[i][j]=='^') RB[i--][j]='?'; else RB[i++][j]='?';} if (RB[i][j]=='.') printf("%d %d\n",j,i); else printf("LOOP\n");} return 0;}

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

vector<int> prime;
vector<int> ls;

void sieve(int N){
    prime.resize(N+1,1);
    prime[0] = prime[1] = 0;
    for(int i=2;i*i<=N;i++){
        for(int j=i*i;j<=N;j+=i){
            prime[j] = 0;
        }
    }
    for(int i=2;i<=N;i++){
        if(prime[i])ls.push_back(i);
    }
}

int main() {
    sieve(int(2e6));
    int n;
    while(cin >> n, n){
        int l=n, r=n;
        while(prime[l]==0)l--;
        while(prime[r]==0)r++;
        cout << r-l << endl;
    }
    return 0;
}


Measured memory_bytes: 11436
#include<iostream>
#include<cstring>

using namespace std;

const int N = 100005, MOD = (int)1e9 + 7;

string s;
int n;
int ten[N];
int memo[N][13];

int calc_rem(int dig, int indx){
	return (dig * ten[n - indx - 1]) % 13;
}

int dp(int indx, int rem){
	if(indx == n){
		return rem == 5;
	}else if(memo[indx][rem] != -1){
		return memo[indx][rem];
	}
	if(s[indx] == '?'){
		int ret = 0;
		for(int dig = 0 ; dig < 10 ; dig++){
			ret = (ret + dp(indx + 1, (rem + calc_rem(dig, indx)) % 13)) % MOD;
		}
		return memo[indx][rem] = ret;
	}else{
		int dig = s[indx] - '0';
		return memo[indx][rem] = dp(indx + 1, (rem + calc_rem(dig, indx)) % 13);
	}
}

int main(){
	memset(memo, -1, sizeof(memo));
	cin >> s;
	n = (int)s.size();
	ten[0] = 1;
	for(int i = 1 ; i < n ; i++){
		ten[i] = (ten[i - 1] * 10) % 13;
	}
	printf("%d\n", dp(0, 0));	
	return 0;
}

Measured memory_bytes: 13696
class ST
	def initialize a
		@l = (1<<(a.size-1).bit_length)-1
		@h = [nil]*@l + a
		(@l-1).downto(0){|i|
			j = 2*i+1
			@h[i] = fn(@h[j],@h[j+1])
		}
	end

	def [] l,r=l
		return q(l,r,0,0,@l)
	end

	def []= i,x
		i += @l
		@h[i] = x
		while 0<i
			i = (i-1)/2
			j = 2*i+1
			@h[i] = fn(@h[j],@h[j+1])
		end
	end

private
	def fn a,b
		return a ? (b ? a|b : a) : b
	end

	def q l,r,i,il,ir
		return if ir<l || r<il
		return @h[i] if l<=il && ir<=r
		return fn(
			q(l,r,2*i+1,il,il+(ir-il)/2),
			q(l,r,2*i+2,il+(ir-il+1)/2,ir)
		)
	end
end

gets
bs = ST.new [0]+gets.chomp.bytes.map{|c| 1<<(c-?a.ord) }
gets.to_i.times{
	c,d,e = gets.split
	case c
	when ?1
		bs[d.to_i] = 1<<e.ord-?a.ord

	when ?2
		p 26.times.inject([0,bs[d.to_i,e.to_i]]){|(n,b),| next n+(b&1),b>>1 }[0]
	end
}


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


int H, W, N;


int main() {
    cin >> H >> W >> N;
    int mx = max(H, W);
    int ans = N / mx;
    if (N % mx) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap};

struct UnionFind{
    n: usize,
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind{
    fn new(n: usize ) -> UnionFind{
        let mut parent = vec![0; n];
        for i in 0..n {
            parent[i] = i;
        }
        let size = vec![1; n];
        UnionFind{n, parent, size}
    }

    fn root(&mut self, x: usize) -> usize{
        if x == self.parent[x]{
            self.parent[x]
        }else{
            let res = self.root(self.parent[x]);
            self.parent[x] = res;
            self.parent[x]
        }
    }

    fn unite(&mut self, x: usize, y: usize){
        let a = self.root(x);
        let b = self.root(y);
        if a == b{
            return;
        }
        if self.size[a] <= self.size[b]{
            self.parent[b] = a;
            self.size[a] += self.size[b];
        }else{
            self.parent[a] = b;
            self.size[b] += self.size[a];
        }
    }

    fn is_same(&mut self, x: usize, y: usize) -> bool{
        self.root(x) == self.root(y)
    }

    fn get_size(&mut self, x: usize) -> usize{
        let a = self.root(x);
        self.size[a]
    }
}

fn main() {
    input! {
        n: Chars,
    }
    let mut t = 0;
    for &x in n.iter(){
        t += x as i32 - '0' as i32;
        t %= 9;
    }
    let ans = if t == 0 {"Yes"} else {"No"};
    println!("{}", ans);
}


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

typedef long long ll;
#define MOD1 1000000007
#define MOD2 1000000009
#define FOR(a,b) for(int i=a;i<b;i++)
#define nl "\n"

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

  string s, t;
  cin >> s >> t;
  int ans = t.size();
  for (int i = 0; i <= s.size() - t.size(); i++)
  {
    int diff = 0;
    for (int j = 0; j < t.size(); j++)
    {
      if (t[j] != s[i + j])
        diff++;
    }
    ans = min(ans, diff);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] nums=new int[n+2];
        for(int i=0;i<n;i++){
            nums[i+1]=sc.nextInt();
        }
        int ans=0;
        for(int i=0;i<n+1;i++){
            ans+=Math.abs(nums[i+1]-nums[i]);
        }
        for(int i=0;i<n;i++){
            System.out.println(ans-(Math.abs(nums[i+2]-nums[i+1])+Math.abs(nums[i+1]-nums[i])-Math.abs(nums[i+2]-nums[i])));
        }
    }
}


Measured memory_bytes: 63748