akhauriyash/Code-Regression huggingface dataset:
import sys,math,collections
from collections import defaultdict

#from itertools import permutations,combinations
    
def file():
    sys.stdin = open('input.py', 'r')
    sys.stdout = open('output.py', 'w') 
def get_array():
    l=list(map(int, input().split()))
    return l
def get_ints():   
    return map(int, input().split())
    #return a,b
def get_3_ints():   
    a,b,c=map(int, input().split())
    return a,b,c    
def sod(n):
    n,c=str(n),0
    for i in n: 
        c+=int(i)
    return c    
def isPrime(n):
    if (n <= 1):
        return False
    if (n <= 3):
        return True
    if (n % 2 == 0 or n % 3 == 0):
        return False
    i = 5
    while(i * i <= n):
        if (n % i == 0 or n % (i + 2) == 0):
            return False
        i = i + 6
  
    return True
def getFloor(A, x):

    (left, right) = (0, len(A) - 1)

    floor = -1
    while left <= right:
        mid = (left + right) // 2
        if A[mid] == x:
            return A[mid]
        elif x < A[mid]:
            right = mid - 1
        else:
            floor = A[mid]
            left = mid + 1
            
    return floor
def chk(aa,bb):
	f=0
	for i in aa:
		for j in bb:
			if(j[0]>=i[0] and j[1]<=i[1]):
				f+=1
			elif(j[0]<=i[0] and j[1]>=i[1]):	
				f+=1
			elif(i[0]==j[1] or i[1]==j[0]):
				f+=1
			else:
				continue
	return f			

#file()
def main():
	n=int(input())
	for i in range(n):
		print("ACL",end="")


	
	



		




				





		


	





        
            
        























    

    
    

        











        
        

        























































                

            







            
            
































        








if __name__ == '__main__':
    main()


Measured memory_bytes: 9428
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H,A[MAX+1];

void maxHeapify(int i){
  int l,r,largest,tmp;
  l=2*i;
  r=2*i+1;
 
  if(l<=H&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H&&A[r]>A[largest]) largest=r;
 
  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;
  if(H<1) return -INFTY;
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  if(key<A[i]) return;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    swap(A[i],A[i/2]);
    i=i/2;
  }
}

void insert(int key){
  H++;
  A[H]=-INFTY;
  increaseKey(H,key);
}

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s",com);
    if(com[0]=='e'&&com[1]=='n') break;
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }else{
      printf("%d\n",extract());
    }
  }
  return 0;
}

Measured memory_bytes: 6484
//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 5 * 100000 + 10;

#define int long long

int32_t main() {
    fio
    string s,t;
    cin >> s >> t;
    if(s + t[t.size()-1] == t) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}






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

int main() {
  int N;
  cin >> N;
  
  int A[N+2] = {0};
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  
  
  
  int sum = 0;
  for (int i = 0; i <= N; i++) {
    sum += abs(A[i+1] - A[i]); 
  } 
  
  for (int i = 1; i <= N; i++) {
    int ans = sum;
    
    ans -= abs(A[i] - A[i-1]);
    ans -= abs(A[i+1] - A[i]);
    ans += abs(A[i+1]-A[i-1]);
    cout << ans << endl;
    
    
  }
  


}

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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define int long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vpll       vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(container) int((container).size())
#define rep(i,a,b) for(i=a;i<b;i++)
#define tr(container,it)   for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define mod 998244353
#define fs first
#define sc second
signed main()
{
  fastio
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
      cin>>a[i];
  int sum = 0; 
  int pow[61];
  pow[0]=1;
  for(int i=1;i<=60;i++)
  {
    pow[i]=(pow[i-1]*2)%hell;
  }
  for(int i=0;i<61;i++)
  {
    int zc=0,oc=0;
    int idsum=0;
    for(int j=0;j<n;j++)
    {
      if(a[j]%2==0)
        zc++;
      else
        oc++;
      a[j]/=2;
    }
    idsum= (((oc*zc)%hell)*pow[i])%hell;
    sum+=idsum;
    sum%=hell;
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 2560
#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 N, K;
vector<int> G[100005];

static const long long mod = 1000000007;
struct mint {
  long long x;
  mint(ll x = 0):x(x%mod) {}
  mint& operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    (x += mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint ret(*this);
    return ret += a;
  }
  mint operator-(const mint a) const {
    mint ret(*this);
    return ret -= a;
  }
  mint operator*(const mint a) const {
    mint ret(*this);
    return ret *= a;
  }
  mint pow(ll t) const {
    if(t==0) return mint(1);
    mint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  //for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint ret(*this);
    return ret /= a;
  }
};
ostream &operator<<(ostream& os, const mint& x) {
  os << x.x;
  return os;
}
class modutils {
  vector<mint> fact, invfact;
public:
  modutils(int n = 200005):fact(n+1),invfact(n+1) {
    fact[0] = 1;
    for(int i=1; i<=n; i++) fact[i] = fact[i-1] * i;
    invfact[n] = fact[n].inv();
    for(int i=n; i>=1; i--) invfact[i-1] = invfact[i] * i;
  }
  mint pow(mint x, ll n) {
    return x.pow(n);
  }
  mint comb(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[k] * invfact[n-k];
  }
  mint perm(ll n, ll k) {
    if(n<0 || k<0 || n<k) return 0;
    return fact[n] * invfact[n-k];
  }
  mint fac(ll n) {
    return fact[n];
  }
};

modutils mutil;
mint ret;

void dfs(int v, int p){
  ll M = 1;
  if(p!=-1) M++;
  ret *= mutil.perm(K-M, G[v].size() - ((p==-1)?0:1));
  rep(i,G[v].size()){
    if(G[v][i] == p) continue;
    dfs(G[v][i], v);
  }
}

int main(){
  cin >> N >> K;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  ret = 1;
  dfs(0, -1);
  ret *= K;
  
  cout << ret << endl;
  
  return 0;
}



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

int main() {
  int N, M, a, b;
  cin >> N >> M;
  vector<int> roadc(N);
  
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    
    roadc.at(a - 1) += 1;
    roadc.at(b - 1) += 1;
  }
  for (int i = 0; i < roadc.size(); i++) {
    cout << roadc.at(i) << endl;
  }
}


Measured memory_bytes: 256
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int int64_t
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){
    return ((n + d -1) / d);
}
/*
inline double Sqrt( const double &x)
{
        double         xHalf = 0.5 * x;
        int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
        double         xRes  = * (double*)&tmp;

        xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
        xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
        xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
        xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
        return xRes * x;
}
*/
// }}}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    int res = k;
    rep(i,n-1){
        res *= (k-1);
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int k,n;
    cin>>k>>n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int memo=k-(a[n-1]-a[0]);
    rep(i,n-1){
        chmax(memo,abs(a[i]-a[i+1]));
    }
    cout<<k-memo<<endl;
}

Measured memory_bytes: 1792
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++) 
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod1 = 1e9 + 7, mod = 998244353;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vi visit(sze, 0);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;

//int dp[10010][110];
//int dpe[10010][10][110];

bool dp[sze];
bool did[sze];

vi a(110);

bool rec(int k)
{
	if (did[k])
		return dp[k];

	did[k] = true;
	for (int i = 0; i < n; i++)
	{
		if (k - a[i] >= 0 && !rec(k - a[i]))
		{
			dp[k] = true;
			break;
		}	
	}

	return dp[k];
}

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

	/*string s;
	cin >> s >> m;
	n = SZ(s);

	for (int i = 1; i <= 9; i++)
	{
		dp[1][i % m] ++;
	}

	for (int i = 2; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			for (int z = 0; z <= 9; z++)
			{
				dp[i][(j + z) % m] = (dp[i - 1][j] + dp[i][(j + z) % m]) % mod;
			}
		}
	}

	int ans = 0;
	for (int i = 1; i < n; i++)
	{
		ans = (ans + dp[i][0]) % mod;
	}

	for (int i = 1; i <= s[0] - '0'; i++)
	{
		dpe[0][i][i % m]++;
	}

	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j <= 9; j++)
		{
			for (int z = 0; z < m; z++)
			{
				if (j == s[i - 1] - '0')
				{
					for (int a = 0; a <= s[i] - '0'; a++)
					{
						dpe[i][a][(z + a) % m] = (dpe[i][a][(z + a) % m] + dpe[i-1][j][z]) % mod;
					}
				}
				else
				{
					for (int a = 0; a <= 9; a++)
					{
						dpe[i][a][(z + a) % m] = (dpe[i][a][(z + a) % m] + dpe[i - 1][j][z]) % mod;
					}
				}
			}
		}
	}

	for (int i = 0; i <= 9; i ++)
	{
		ans = (ans + dpe[n - 1][i][0]) % mod;
	}

	cout << ans;*/

	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	rec(k) ? cout << "First" : cout << "Second";

	return 0;
}

Measured memory_bytes: 15616
#include <iostream>

using namespace std;

int x, r, r2;

int main()
{
  cin >> x;
  r += x / 500;
  r *= 1000;
  x %= 500;
  r2 += x / 5;
  r2 *= 5;
  r += r2;
  cout << r;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int sosuhantei(int x) {
	if (x == 2)return 1;
	if (x % 2 == 0||x==1||x<=0)return 0;
	for (int i = 3; i <= sqrt(x); i += 2) {
		if (x%i == 0)return 0;
	}
	return 1;
}

int cnt_primary(int n) {
	int cnt = 0;
	for (int i = n + 1; i <= 2 * n; i++) {
		if (sosuhantei(i))cnt++;
	}
	return cnt;
}

int main() {
	int n;
	while (cin >> n&&n) {
		cout << cnt_primary(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC167D()
{
	int N;
	ll K;
	cin >> N >> K;
	vi A(N);
	for (auto& x : A)
	{
		int y;
		cin >> y;
		--y;
		x = y;
	}
	vi B(N+1);
	vi C(N, -1);
	B[0] = 0;
	C[0] = 0;
	int iStart = 0;
	int iEnd = 0;
	for (int i = 0; i < N; ++i)
	{
		B[i + 1] = A[B[i]];
		if (C[B[i + 1]] == -1)
		{
			C[B[i + 1]] = i + 1;
		}
		else
		{
			iStart = C[B[i + 1]];
			iEnd = i + 1;
		}
	}
	if (K <= iStart)
	{
		int x = B[K];
		++x;
		cout << x << endl;
		return;
	}
	int nLoop = iEnd - iStart;
	K -= iStart;
	K %= nLoop;
	int y = iStart + K;
	int x = B[y];
	++x;
	cout << x << endl;

}

int main()
{
	ABC167D();
	return 0;
}


Measured memory_bytes: 5636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <tuple>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		O.pln(48-I.nextInt());
	}
	public static void sort(long[] a) {Arrays.sort(a);}
	public static void sort(int[] a) {Arrays.sort(a);}
	public static void sort(String[] a) {Arrays.sort(a);}
	public static void sort(char[] a) {Arrays.sort(a);}
	public static void sort(StringBuilder[] a) {Arrays.sort(a);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(boolean x) {w.println(x);w.flush();}
	}
}

Measured memory_bytes: 25564
#include<iostream>
using namespace std;
int main(){
string st;
  cin>>st;
  int a=0;
  int b=0;
  for(int i=0; i<3; i++){
  if(st[i]=='A'){
  a++;
  }
    else{
    b++;}
  
  }
  if(a>0 && b>0){
  cout<<"Yes"<<endl;}
  else{
  cout<<"No";}
}

Measured memory_bytes: 256
n = int(input())
weight = list(map(int,input().split()))
minimum_weight = abs(sum(weight[0:1]) - sum(weight[1:n+1]))

for i in range(1,n-1):
  minimum_weight = min(minimum_weight, abs(sum(weight[0:i+1]) - sum(weight[i+1:n+1])))
  
print(minimum_weight)

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 1e5 + 5;
int dp[MAX];
int main()
{
	boost;
	int n, W, i;
	cin >> n >> W;
	int v[n], w[n];
	fo(i, 0, n)
	cin >> w[i] >> v[i];
	
	fill(dp, dp + MAX, inf);
	dp[0] = 0;
	fo(i, 0, n) {
		for(int j = MAX - 1; j >= v[i]; j--)
		dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
	}
	for(i = MAX - 1; i >= 0; i--) {
		if(dp[i] <= W) {
			cout << i;
			return 0;
		}
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int p,q;
  cin>>p>>q;
  q/=__gcd(p,q);
  for(int i=2;i*i<=q;i++){
    if(q%i==0){
      while(q%i==0)q/=i;
      q*=i;
    }
  }
  cout<<q<<endl;
  return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}

int main(void){
    ll n,i;
    scanf("%lld",&n);
    char s[n+5];
    scanf("%s",s);
    ll w[n],change,ans;
    for(i=0;i<n;i++){
        if(i==0){
            w[i]=0;
            if(s[i]=='W') w[i]++;
            continue;
        }
        w[i]=w[i-1];
        if(s[i]=='W') w[i]++;
    }
    for(i=0;i<n;i++){
        if(i==0){
            ans=(n-1)-(w[n-1]-w[i]);
            continue;
        }
        if(i==n-1){
            change=w[n-2];
            ans=min2(ans,change);
            continue;
        }
        change= w[i-1] + (n-i-1)-(w[n-1]-w[i]) ;
        ans=min2(ans,change);
    }
    // qsort(change,n,sizeof(ll),compare);
    printf("%lld\n",ans);
    return 0;
}


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

public class Program
{
    public static void Main(string[] args)
    {
        Console.ReadLine();
        var X = Console.ReadLine().Split(' ').Select(int.Parse);
        var min = X.Min();
        var max = X.Max();
        Console.WriteLine(
                Enumerable.Range(min, max - min + 1)
                .Select(p => X.Select(x => (x - p) * (x - p)).Sum())
                .Min());
    }
}


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

int main(){
	int N;
	double T,A,H,num=0,temp=10000;
	cin>>N>>T>>A;
	for(int k=0;k<N;k++){
		cin>>H;
      	if(temp>abs(A-(T-H*0.006))) {temp=abs(A-(T-H*0.006));num=k+1;}
	}
  cout<<num<<endl;
}

Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

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


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

int main(){
  int N;
  cin >> N;
  
  int x=0;
  for (int i=0 ; i<N ;i++){
    if (i+1==3*5*7 || i+1==3*3*3*5 || i+1==3*3*3*7 || i+1==3*5*11 || i+1==3*5*13)
      x++;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int[][][] residence = new int[4][3][10];

		int n = Integer.parseInt(br.readLine());
		for (int i = 0; i < n; i++) {
			String[] str = br.readLine().split(" ");
			int b = Integer.parseInt(str[0]);
			int f = Integer.parseInt(str[1]);
			int r = Integer.parseInt(str[2]);
			int v = Integer.parseInt(str[3]);
			residence[b - 1][f - 1][r - 1] += v;
		}

		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 10; k++) {
					System.out.print(" " + residence[i][j][k] );

				}
				System.out.print("\n");
			}
			
			if (i != 3) {
				System.out.println("####################");
			}

		}
	}
}
// for (int i=0;i<4;i++){
// for(int j=0;j<3;j++){
// for (int k=0;k<10;k++){
// sb.append(" ").append(residence[i][j][k]);
// }
// sb.("\n");
// }
// if (i !=4){
// System.out.print("##########");
// }

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

using namespace std;

using int64 = long long;

using pi = pair< int, int >;

const int64 INF = 1LL << 60;

int main() {
  int N, L[100000], R[100000];
  cin >> N;

  set< pi > left;
  set< pi > right;
  for(int i = 0; i < N; i++) {
    cin >> L[i] >> R[i];
  }
  int64 ret = 0;
  for(int i = 0; i < 2; i++) {

    int64 add = 0;
    int pos = 0;

    bool f = false;
    for(int j = 0; j < N; j++) {
      left.emplace(R[j], j);
      right.emplace(L[j], j);
    }
    for(int j = 0; j < N; j++) {
      if((i + j) & 1) {
        auto it = left.begin();
        if(pos - it->first < 0) {
          break;
        }
        add += pos - it->first;
        pos = it->first;
        right.erase({L[it->second], it->second});
        left.erase(it);
      } else {
        auto it = --right.end();
        if(it->first - pos < 0) {
          break;
        }
        add += it->first - pos;
        pos = it->first;
        left.erase({R[it->second], it->second});
        right.erase(it);
      }
    }
    ret = max(ret, add + abs(pos));
  }
  cout << ret << endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;
int n, mn, mj, d[N], e[N], c[N], x[30];
string a, s;
int main() {
	int i, j, k;
	cin>>a;
	n = a.size();
	a = '.' + a;
	for(i=0; i<26; i++) x[i] = n+1;
	for(i=n; i>=0; i--) {
		mn = N;
		for(j=0; j<26; j++) {
			if(d[x[j]] < mn) {
				mn = d[x[j]];
				mj = j;
			}
		}
		d[i] = mn + 1;
		e[i] = x[mj];
		c[i] = mj;
		x[a[i]-'a'] = i;
	}
	for(i=0; i<=n; i=e[i]) s += c[i]+'a';
	cout<<s;
	return 0;
}

Measured memory_bytes: 2880
#include<bits/stdc++.h>
using namespace std;
#define int long long
string calc(string s){

  
  //cout<<s<<":";

  while(1){
    string t=s;
    int k;
    
    if((k=s.find("AAA"))!=-1) s.erase(k,3);
    if((k=s.find("BBB"))!=-1) s.erase(k,3);
    if((k=s.find("AB"))!=-1) s.erase(k,2);
    if((k=s.find("BA"))!=-1) s.erase(k,2);
    
    if((k=s.find("AA"))!=-1){
      s.erase(k,1);
      s[k]='B';
    }
    if((k=s.find("BB"))!=-1){
      s.erase(k,1);
      s[k]='A';
    }
    if(s==t) break;
  }
  
  //cout<<s<<endl;
  
  return s;
}
signed main(){
  string s,t;
  int q;
  cin>>s>>t>>q;
  int a[q],b[q],c[q],d[q];
  for(int i=0;i<q;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
  int n=s.size(),m=t.size();
  string ds[20][n];
  for(int i=0;i<n;i++) ds[0][i]=s[i];
  int tmp=1;
  for(int i=1;i<20;i++){
    for(int j=0;j<=n-tmp;j++){
      //cout<<i<<"/"<<j;
      ds[i][j]=calc(ds[i-1][j]+ds[i-1][j+tmp]);
    }
    tmp*=2;
    if(tmp>n) break;
  }
  string dt[20][m];
  for(int i=0;i<m;i++) dt[0][i]=t[i];
  tmp=1;
  for(int i=1;i<20;i++){
    for(int j=0;j<=m-tmp;j++){
      //cout<<i<<"/"<<j;
      dt[i][j]=calc(dt[i-1][j]+dt[i-1][j+tmp]);
    }
    tmp*=2;
    if(tmp>m) break;
  }
  int p[20];
  p[0]=1;
  for(int i=0;i<19;i++) p[i+1]=p[i]*2;

  //cout<<endl<<endl;
  for(int i=0;i<q;i++){
    a[i]--;b[i]--;c[i]--;d[i]--;
    string x,y;
    int e=b[i]-a[i]+1,f=a[i];
    for(int j=18;j>=0;j--){
      if((e>>j)&1){
	//cout<<j<<" "<<f<<" "<<ds[j][f]<<endl;
	//cout<<ds[j][f]<<endl;
	x=calc(x+ds[j][f]);
	f+=p[j];
      }
      //cout<<f<<"-";
      //cout<<x<<endl;
    }
    //cout<<endl;
    int g=d[i]-c[i]+1,h=c[i];
    for(int j=18;j>=0;j--){
      if((g>>j)&1){
	//cout<<j<<" "<<h<<" "<<dt[j][h]<<endl;
	y=calc(y+dt[j][h]);
	h+=p[j];
      }
      //cout<<h<<"-";
      //cout<<y<<endl;
    }
    //cout<<endl;
    //cout<<x<<":"<<y<<endl;
    cout<<(x==y?"YES":"NO")<<endl;
  }
  return 0;
}


Measured memory_bytes: 174720
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MAX(a,b) ((a >= b) ? (a) : (b))
#define MIN(a,b) ((a >= b) ? (b) : (a))
#define ABS(a) (((a) > 0) ? (a) : (-a))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))

int main() {

	int h1, m1, h2,m2, k, st, end, ans = 0;
	cin>>h1>>m1>>h2>>m2>>k;

	st = (h1*60) + m1;
	end = (h2*60) + m2 - k;

	printf("%d\n", (end - st));
	

	return 0;
}

Measured memory_bytes: 3752
#include<stdio.h>
long long ans;
void dfs(long long l, long long s) {
    if(l % s == 0) {
        ans += l * 2 - s;
        return;
    }
    ans += l / s * s * 2;
    dfs(s, l % s);
}
int main() {
    long long n, x;
    scanf("%lld%lld", &n, &x);
    ans = n;
    if(x > n - x) dfs(x, n - x);
    else dfs(n - x, x);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
// 2011/04/03 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string str;
		cin >> str;
		if(cin.eof())
			break;

		int num[10];
		for(int i=0; i<10; i++)
			num[i] = str[i]-'0';

		for(int i=9; i>=1; i--)
			for(int j=0; j<9; j++)
				num[j] = (num[j]+num[j+1])%10;

		cout << num[0] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
H, W = map(int, input().split())

grid = []

for i in range(H):
    grid.append(list(map(int, input().split())))

ope = []
tmp = True
p = 0
for h in range(H):
    if(tmp is True):
        W_list = [j for j in range(W)]
        tmp = False
    else:
        W_list = [j for j in reversed(range(W))]
        tmp = True

    for j in range(len(W_list)):
        w = W_list[j]
        if((grid[h][w] + p) % 2 == 0):
            p = 0
            continue

        if(w == W_list[-1]):
            nw = w
            nh = h + 1
        else:
            nw = W_list[j + 1]
            nh = h
        if(nh == H):
            continue

        ope.append([h + 1, w + 1, nh + 1, nw + 1])
        p = 1

print(len(ope))
for h, w, nh, nw in ope:
    print(h, w, nh, nw)

Measured memory_bytes: 30536
N=int(input())
A=[]
for _ in range(N):
  A.append(int(input())-1)
visited=[0]*N
i,ans= 0,0
while i != 1:
  if visited[i] == 0:
    visited[i] = 1
    i = A[i] # next position
    ans += 1
  else:
    ans = -1
    break
print(ans)



Measured memory_bytes: 7884
N=int(input())
ls=[int(s) for s in input().split()]
b=sum(ls)
x=b//N
y=x+1
sumx=0
sumy=0
for e in ls:
  sumx+=(x-e)*(x-e)
  sumy+=(y-e)*(y-e)
print(min([sumx,sumy]))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int dig(int N) {//桁数
	int dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}

int main() {
	int N, K; cin >> N >> K;
	cout << N - K + 1 << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

#pragma warning(disable : 4996)

using namespace std;

int N, K, A, B, dp[11][2001];

vector<int> R[10];

int main()
{
	scanf("%d", &N);
	scanf("%d", &K);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A);
		scanf("%d", &B);

		R[B - 1].push_back(A);
	}

	for (int i = 0; i < 10; i++)
	{
		sort(R[i].begin(), R[i].end(), greater<int>());

		for (int j = 1; j < R[i].size(); j++)
		{
			R[i][j] = R[i][j] + R[i][j - 1] + j * 2;
		}
	}

	for (int i = 1; i < 11; i++)
	{
		for (int j = 1; j <= K; j++)
		{
			dp[i][j] = dp[i - 1][j];

			for (int k = 0; k < R[i - 1].size(); k++)
			{
				if (j - k >= 1)
				{
					dp[i][j] = max(dp[i][j], dp[i - 1][j - k - 1] + R[i - 1][k]);
				}
			}
		}
	}

	printf("%d\n", dp[10][K]);

	return 0;
}

Measured memory_bytes: 3308
n = int(input())
a = [int(i) for i in input().split(" ")]

flag = True
counter = 0

while flag :
  for i in range(len(a)):
    if a[i] % 2 == 0:
      a[i] /= 2
    else:
      flag = False
      break
  counter += 1

print(counter - 1)

Measured memory_bytes: 3060
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    r,g = IR(2)
    print(2*g-r)

#B
def B():
    n = I()
    k = I()
    a = 1
    for i in range(n):
        if a > k:
            a += k
        else:
            a *= 2
    print(a)
#C
def C():
    def check(a,b):
        for i in range(len(a)):
            if a[i] != b[i] and a[i] != "?":
                return False
        return True
    def f(c):
        if c == "?":return "a"
        return c
    s = S()
    t = S()
    n = len(s)
    l = len(t)
    ans = []
    for i in range(n-l+1)[::-1]:
        if check(s[i:i+l],t):
            c = [f(s[j]) for j in range(i)]
            c += t
            for j in range(i+l,n):
                c += f(s[j])
            ans.append(c)
    if not len(ans):
        print("UNRESTORABLE")
    else:
        ans.sort()
        for i in ans[0]:
            print(i,end = "")
        print()
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 41968
fun main(args:Array<String>):Unit {
    val (n, m, d) = readLine()!!.trim().split(' ').map(String::toDouble)
    println(
            String.format("%.10f",
                    if (d != 0.0) 2.0 * (n - d) / n / n * (m - 1)
                    else 1.0 / n * (m - 1)
            )
    )
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A >= 13) {
    cout << B << endl;
  } else if (A <= 12 && A >= 6) {
    cout << B / 2 << endl;
  } else {
    cout << 0 << endl;
  }
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') ch = getchar(), f = -1;
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> void out(Tp x) {
	if (x > 9) out(x / 10);
	putchar(x % 10 + '0');
	return;
}

template <typename Tp> Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;}
template <typename Tp> Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;}
template <typename Tp> bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);}
template <typename Tp> bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);}

int n;
LL sum;

int main()
{
	in(n);
	char flag = true;
	int min = 0x3f3f3f3f;
	FOR(i, 1, n) {
		int x, y; in(x); in(y); sum += x;
		if (x != y) flag = false;
		if (x > y) chkmin(min, y);
	}
	if (flag) puts("0");
	else printf("%lld\n", sum - min);
	return 0;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
if 0 in set(a):
    print(0)
    quit()
res = 1
for x in a:
    res *= x
    if res > 10**18:
        print(-1)
        quit()
print(res)

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

#define FOR(i, a, b) for(int(i)=(a);(i)<(b);(i)++)
#define REP(i, n) FOR((i), 0, (n))

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

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

	int N;
	cin>>N;

	vector<int> A(N);
	vector<int> B;
	cin>>A[0];
	B.push_back(A[0]);
	for(int i=1; i<N; i++){
		cin>>A[i];
		if(A[i-1] != A[i]){
			B.push_back(A[i]);
		}
	}

	bool flag;
	if(B[0] < B[1]){
		flag=true;
	}else{
		flag=false;
	}
	
	int ans=0;
	N = B.size();
	for(int i=1; i<N; i++){
		if(flag && B[i-1] > B[i]){
			ans++;
			i++;
			if(B[i-1] < B[i]){
				flag=true;
			}else{
				flag=false;
			}
		}else if(!flag && B[i-1] < B[i]){
			ans++;
			i++;
			if(B[i-1] < B[i]){
				flag=true;
			}else{
				flag=false;
			}
		}
	}
	
	cout<<ans+1<<endl;

	return 0;
}



Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
const int mx=100005;
vec v[2*mx]; vec c(2,0); vec vis(2*mx,false);
void dfs(ll x)
{
	if(vis[x])
	return ;
	vis[x]=true;
	if(x>mx)
	c[1]++;
	else
	c[0]++;
	ll y=v[x].size();
	rep(i,0,y)
	{
		if(!vis[v[x][i]])
		dfs(v[x][i]);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll j,l,m,h,w,f,k,b,n,ans;
    	cin>>n;
    	rep(i,0,n)
    	{
    		cin>>l>>h;
    		h+=mx;
    		v[l].pb(h);
    		v[h].pb(l);
		}
		ans=0;
    	repi(i,1,mx)
    	{
    		if(!vis[i])
    		{
    			c[0]=0 ; c[1]=0;
    			dfs(i);
    			ans+=c[0]*c[1];
			}
		}
    	cout<<ans-n;
    }
	return 0;
}

Measured memory_bytes: 11648
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            List<SalesData> list = new ArrayList<>();
            while (n-- > 0) {
                SalesData data = new SalesData(sc.nextInt(), sc.nextInt(), sc.nextInt());
                if (list.isEmpty()) {
                    list.add(data);
                } else if (!isAdded(list, data)) {
                    list.add(data);
                }
            }
            boolean notOver = true;
            for (SalesData s : list) {
                if (s.amount >= 1000000) {
                    notOver = false;
                    System.out.println(s.id);
                }
            }
            if (notOver) {
                System.out.println("NA");
            }
            list.clear();
        }
    }

    static boolean isAdded(List<SalesData> list, SalesData data) {
        for (SalesData s : list) {
            if (s.id == data.id) {
                s.amount += data.amount;
                return true;
            }
        }
        return false;
    }
}

class SalesData {
    int id;
    int amount;

    SalesData(int id, int price, int n) {
        this.id = id;
        this.amount = price * n;
    }
}



Measured memory_bytes: 35076
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	d, g := nextInt(), nextInt()
	c, s := make([]int, d), make([]int, d)
	for i := 0; i < d; i++ {
		c[i] = nextInt()
		s[i] = nextInt()
	}

	min := 1 << 30
	// 全完する得点の問題をbit全探索
	for bit := 0; bit < (1 << uint(d)); bit++ {
		sum, num := 0, 0

		for i := 0; i < d; i++ {
			if bit & (1 << uint(i)) != 0 {
				sum += (i+1) * 100 * c[i] + s[i]
				num += c[i]
			}
		}

		// 全完だけで目標を超えていたら次の探索
		if sum >= g {
			if min > num {
				min = num
			}
			continue
		}

		// 1番得点の高い問題から順に解いていく
		for i := d-1; i >= 0; i-- {
			if bit & (1 << uint(i)) != 0 {
				continue
			}
			for j := 0; j < c[i]; j++ {
				if sum >= g {
					break
				}
				sum += (i+1) * 100
				num++
			}
		}

		if min > num {
			min = num
		}
	}

	fmt.Println(min)
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

long long func(long long n, long long x){
    if(n == -1) return 0;
    else return n/x + 1;
}

int main()
{
    long long a, b, x;
    cin >> a >> b >> x;
    long long ans = func(b, x) - func(a-1, x);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int Z = scan.nextInt();
		int W = scan.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		if(N == 1) {
			System.out.println((int)Math.abs(a[0] - W));
		} else {
			System.out.println((int)Math.max(Math.abs(a[N - 1] - W), Math.abs(a[N - 1 - 1] - a[N - 1])));
		}
		scan.close();

	}

}


Measured memory_bytes: 25836
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7,p=1e9+7;
int n,xt,yt,w[N],f[N],col[N],len[N],siz[N]; vector<int>v[N]; long long ans;
inline int read(){
	long long num=0; char t='+',g=getchar(); while(g<48||57<g) t=g,g=getchar();
	while(47<g&&g<58) num=(num<<1)+(num<<3)+g-48,g=getchar(); if(t=='-') return 0-num; return num;
}
inline long long pows(long long u,int v){
	long long ans=1; while(v>0) {if(v&1) ans=ans*u%p; u=u*u%p,v=v>>1;} return ans;
}
inline int find(int u){
	if(f[u]==u) return u; return f[u]=find(f[u]);
}
inline void merge(int u,int v) {if(find(u)==find(v)) return; f[find(u)]=find(v);}
inline void getret(int u){
	for(long long i=1;i<=u;i++) ans=ans*i%p;
}
int main(){
	n=read(),xt=read(),yt=read(),w[0]=1e9,ans=1;
	for(int i=1;i<=n;i++) f[i]=i,col[i]=read(),w[i]=read(),v[col[i]].push_back(i),len[col[i]]++;
	for(int i=1;i<=n;i++){
		int pos=0;
		for(int x=0;x<len[i];x++) if(w[pos]>=w[v[i][x]]) pos=v[i][x];
		for(int x=0;x<len[i];x++) if(w[v[i][x]]+w[pos]<=xt) merge(v[i][x],pos);
	}
	int posl=0,posr=0;
	for(int i=1;i<=n;i++) if(w[posl]>=w[i]) posl=i;
	for(int i=1;i<=n;i++) if(w[posr]>=w[i]&&col[i]!=col[posl]) posr=i;
	for(int i=1;i<=n;i++) if(w[posl]+w[i]<=yt&&col[posl]!=col[i]) merge(posl,i);
	for(int i=1;i<=n;i++) if(w[posr]+w[i]<=yt&&col[posr]!=col[i]) merge(posr,i);
	for(int i=1;i<=n;i++) siz[find(i)]++;
	for(int i=1;i<=n;i++) getret(siz[i]); memset(siz,0,sizeof(siz));
	for(int i=1;i<=n;i++){
		for(int x=0;x<len[i];x++) siz[f[v[i][x]]]++,ans=ans*pows(siz[f[v[i][x]]],p-2)%p;
		for(int x=0;x<len[i];x++) siz[f[v[i][x]]]--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13696
import java.util.*

fun main(args : Array<String>) {

  val scanner = Scanner(System.`in`)
  val s = scanner.nextLine().split(" ") ;

  val x1 = s[0].toDouble()
  val y1 = s[1].toDouble()
  val x2 = s[2].toDouble()
  val y2 = s[3].toDouble()

  val xLine = x2 - x1
  val yLine = y2 - y1

  val line = Math.sqrt( Math.pow(xLine, 2.0) + Math.pow(yLine, 2.0) )

  println("%.8f".format(line))
}



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

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

  string str;
  stack<int> s1;
  stack<pair<int, int> > s2;
  stack<int> s3;
  int sum = 0;

  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '\\') {
      s1.push(i);
    } else if (str[i] == '/' && !s1.empty()) {
      int j = s1.top();
      s1.pop();
      int area = i - j;
      sum += area;
      while (s2.size() > 0 && s2.top().first > j) {
        area += s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(j, area));
    }
  }

  cout << sum << endl;
  cout << s2.size();
  while (s2.size() > 0) {
    s3.push(s2.top().second);
    s2.pop();
  }
  while (s3.size() > 0) {
    cout << " " << s3.top();
    s3.pop();
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 1328
n , m = map(int, input().split())
h = list(map(int, input().split()))
l = [True]*n 
for _ in range(m):
	i , j = map(int, input().split())
	i-=1 
	j-=1 
	if h[i] - h[j] > 0 : 
		l[j] = False 
	elif h[j] - h[i] > 0  : 
		l[i] = False 
	else : 
	    l[i] = False 
	    l[j] = False 

print(l.count(True))

Measured memory_bytes: 19976