akhauriyash/Code-Regression huggingface dataset:
eval'K,X,Y='+`dd`.split*?,;x,y,*s=X.abs,Y.abs;d=x+y;x,y=y,x if f=x>y;K%2-d%2<0&&(p -1;exit);n=(d-1)/K+1;n+=d<K ? 1:(d-n*K)%2;a=n<2 ?x:(d-n*K)/2;b=K-a.abs;d%2-d/K>0&&(s=[[0,-K]];a=b=(d-K)/2);n.times{s<<[a,b];t=[x-a,K].min;a+=t;b+=K-t};p s.size;s.each{|a,b|f&&(a,b=b,a);puts [a*(X<=>0.1),b*(Y<=>0.1)]*?\s}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 998244353;

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

  int n,m;
  cin >> n >> m;
  vi h(n);
  rep(i,n)cin >> h[i];
  vi good(n,1);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    if(h[a] <= h[b])good[a] = 0;
    if(h[b] <= h[a])good[b] = 0;
  }
  int ret = 0;
  rep(i,n){
    if(good[i])ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 3988
//AcCepted

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    string s;cin>>s;
    bool flag = true;
    if(s[0]!='A')flag=false;
    int c=0;
    rep(i,1,s.size()){
        if(isupper(s[i])){
            if(i==1||i==s.size()-1||s[i]!='C')flag=false;
            else if(s[i]=='C')c++;
        }
    }
    if(c>1||c==0)flag=false;
    cout << (flag ? "AC" : "WA")<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

struct edge {int from;int to;int cost;};
edge es[5001];
ll d[2501];
ll V,E,P;

int main(){
    cin>>V>>E>>P;
    for(int i=0;i<2501;i++) d[i]=BIG;
    for(int i=0;i<E;i++){
        ll A,B,C;
        cin>>A>>B>>C;
        C=(P-C);
        es[i].from=A;
        es[i].to=B;
        es[i].cost=C;
    }

    

    d[1]=0;
    
    bool ans=true;

    int count=0;
    while(true){
        bool update=false;
        for(int i=0;i<E;i++){
            edge e=es[i];
            if(d[e.from]!=BIG && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                update=true;
                if(count>=V && e.to==V) {ans=false; break;}
            }
                 
        }
        if(update) count++;
        if(!update) break;   
        if(count>=2*V) break;
        
    }


    //for(int i=1;i<=V;i++) cout<<i<<' '<<-d[i]<<endl;

    //cout<<ans<<endl;

    if(ans && d[V]<0) cout<<-d[V]<<endl;
    else if(ans) cout<<0<<endl;
    else cout<<-1<<endl;
}

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

class dice{
	private:
		int top;
		int front;
		int right;
		int left;
		int back;
		int bottom;
	public:
		dice(int top,int front,int right,int left,int back,int bottom);
		void roll(char ch);
		void printtop();
		
};

dice::dice(int top,int front,int right,int left,int back,int bottom){
	this->top=top;
	this->front=front;
	this->right=right;
	this->left=left;
	this->back=back;
	this->bottom=bottom;	
}

void dice::roll(char ch){
	int temp;
	switch (ch){
		case 'E':
			temp = this->top;
			this->top = left;
			this->left = bottom;
			this->bottom = right;
			this->right = temp;
			break;
		case 'W':
			temp = this->top;
			this->top = right;
			this->right = bottom;
			this->bottom = left;
			this->left = temp;
			break;
		case 'S':
			temp = this->top;
			this->top = back;
			this->back = bottom;
			this->bottom = front;
			this->front = temp;
			break;
		case 'N':
			temp = this->top;
			this->top = front;
			this->front = bottom;
			this->bottom = back;
			this->back = temp;
			break;		
	}
}

void dice::printtop(){
	cout<<this->top<<endl;
}


int main(){
	
	
	int top,front,right,left,back,bottom;
	string d;
	int count;
	
	cin >>top>>front>>right>>left>>back>>bottom;
	
	dice dice1(top,front,right,left,back,bottom);
	
	cin >> d;
	count = d.length();
	
	for(int i=0;i<count;i++){
		dice1.roll(d[i]);		
	}
	
	dice1.printtop();
	
	
	return 0;	
}


Measured memory_bytes: 3172
n, m = map(int, input().split())

g = [[] for _ in range(1005)]

for i in range(m):
    a, b = map(int, input().split())
    g[a].append(b)

vis = [0] * 1005


def dfs(x, p):
    if vis[x]:
        return []
    p.append(x)
    vis[x] = 1
    for v in g[x]:
        if v in p:
            return p
        t = dfs(v, p)
        if len(t):
            return t
    p.pop()
    return []


tmp = 0
ans = 10 ** 10
tmpp = []
p = []
vs = [0] * 1005


def dfs2(x):
    global ans, p, tmp, tmpp
    if len(p) >= ans:
        return
    p.append(x)
    for v in g[x]:
        if v == tmp:
            ans = len(p)
            tmpp = p[:]
            continue
        if not vs[v]:
            vs[v] = 1
            dfs2(v)
    p.pop()


a = []
for i in range(1, 1 + n):
    tmp = i
    p = []
    vs = [0] * 1005
    dfs2(i)
    if len(tmpp) == ans:
        a = tmpp[:]

if not len(a):
    print(-1)
    exit(0)

print(len(a))
for i in a:
    print(i)

#
# pre = t[0]
# next = [0] * 1005
# for i in range(1, len(t)):
#     now = t[i]
#     next[pre] = now
#     pre = now
# next[t[-1]] = t[0]
# s = set()
# for i in t:
#     s.add(i)
#
# cnt = 0
# now = t[0]
# while cnt < len(s):
#     cnt += 1
#     for i in g[now]:
#         if i == next[now]:
#             continue
#         if i in s:
#             cnt = 0
#             k = next[now]
#             while k != i:
#                 s.remove(k)
#                 k = next[k]
#             next[now] = i
#     now = next[now]
#
# print(len(s))
# for i in s:
#     print(i)


Measured memory_bytes: 68572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((b - a == c - b) ? "YES" : "NO") << endl;
}

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

using namespace std;

int main(int argc, char* argv[]) {
	int a, b, c; cin >> a >> b >> c;
	if (c >= a && c <= b) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left,bisect_right

N = int(input())
A_list = []
for i in range(N):
    A_list.append(int(input()))

A_unique = list(set(A_list))


A_list.sort()

ans = 0
for a in A_unique:
    if (bisect_right(A_list,a)-bisect_left(A_list,a))%2 == 1:
        ans += 1
        
print(ans)

Measured memory_bytes: 13204
#include <bits/stdc++.h>
 
using namespace std;
 
int n;
long long a[200200];
long long ans, len = 0;
 
int main() {
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
        len += a[i];
	}
	long long cur = 0;
    ans = len;
    for(int i = 0; i < n; i++){
        cur += a[i];
        ans = min(ans, abs(cur - (len - cur)));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


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

  int N; std::cin >> N;
  std::vector<int> a(1e5+4); 
  rep(i,N) {
    int ak; std::cin >> ak;
    a[ak] += 1;
    a[ak+3] -= 1;
  }
  rep(i,1e5+4) {
    if ( i != 0 ) a[i] += a[i-1];
  }

  std::cout << *std::max_element(all(a)) << std::endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n;
bool s[203][203];
vector<int>v,g[203];
int vis[203];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string s;cin>>s;
		for(int j=0;j<n;j++)
			if(s[j]=='1')g[i].push_back(j);
	}
	int ans=-1;
	for(int i=0;i<n;i++){
		queue<pair<int,int> >q;
		q.push(make_pair(i,1));
		int dis[203];
		memset(dis,0,sizeof(dis));
		dis[i]=1;
		while(!q.empty()){
			int x=q.front().first,len=q.front().second;
			q.pop();
			for(int j=0;j<g[x].size();j++)
				if(!dis[g[x][j]]){
					dis[g[x][j]]=len+1;
					q.push(make_pair(g[x][j],len+1));
				}else if(dis[g[x][j]]%2!=(len+1)%2){
					cout<<-1;
					return 0;
				}
		}
		int res=0;
		for(int j=0;j<n;j++)res=max(res,dis[j]);
		ans=max(ans,res);
	}
	cout<<ans;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int ans = 0;
		int time = 0;

		for(int i=0; i<=a; i++){
			for(int j=0; j<=b; j++){
				for(int k=0; k<=c; k++){
					ans = 500*i + 100*j + 50*k;
					if(ans == x){
						time++;
					}
				}
			}
		}

		System.out.println(time);
	}
}

Measured memory_bytes: 21972
from heapq import heappop,heappush
l,r=[],[]
ans=0
for _ in range(int(input())):
	a=list(map(int,input().split()))
	if a[0]==1:
		_,ia,ib=a
		heappush(l,-ia)
		heappush(r,ia)
		ll=heappop(l)
		rr=heappop(r)
		heappush(l,-rr)
		heappush(r,-ll)
		ans+=ib+abs(ll+rr)
	else:print(-l[0],ans)

Measured memory_bytes: 19064
#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[250];
    char res[250];
    int i;

    gets(str);

    for (i = 0, memcpy(res, str, sizeof(str)); str[i]; i++) {
        if(str[i] >= 97 && str[i] < 123)
        res[i] = str[i] - 32;
    }

    puts(res);

    return 0;
}

Measured memory_bytes: 524
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<String> list = new ArrayList<String>();
    
    int[] iList = new int[k]; 
    
    for(int i = 0; i<k; i++){
      iList[i] = sc.nextInt();
      String str = String.valueOf(iList[i]);
      list.add(str);
    }
    
    while(true){
      boolean boo = true;
      String nstr = String.valueOf(n);
      for(String str : list){
        if(nstr.contains(str)){
          boo = false;
          break;
        }
      }
      if(boo){
        break;
      }
      n++;
    }
    System.out.println(n);
  }
}


Measured memory_bytes: 26836
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T, typename U> U read(ll V, T a, U b) {
  REP(i, V) {
    cin >> a;
    b.push_back(a);
  }
  return b;
}

ll s(ll n) {
  ll ans = 0;
  while (n > 0) {
    ans += n % 10;
    n /= 10;
  }
  return ans;
}

ll f(ll n) {
  double ans1 = llINF;
  ll ans2 = 0;
  REP(d, log10(n) + 2) {
    ll x = ((ll)pow(10, d + 1) * ((n / (ll)pow(10, d + 1)) + (ll)1)) - (ll)1;
    double y = (double)x / (double)s(x);
    if (ans1 > y) {
      ans2 = x;
      ans1 = y;
    }
  }
  return ans2;
}

int main() {
  ll K;
  ll now = 9;
  ll count = 0;
  cin >> K;
  for (ll i = 1; i < 10 && count < K; i++) {
    cout << i << endl;
    count++;
  }
  while (count < K) {
    now = f(now + 1);
    cout << now << endl;
    count++;
  }

  return 0;
}


Measured memory_bytes: 512
def gcd(x,y):
  r=x%y
  return gcd(y,r) if r else y
#最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

n=int(input())
A=[int(input()) for i in range(n)]

#リスト内最小公倍数
k=A[0]
for i in A[1:]:
  k=lcm(k,i)
print(k)


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

int main(int argc, char* argv[]) {
  int T, X;
  std::cin >> T >> X;
  std::cout << (double)T / X << std::endl;
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

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

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

const int N=200005;

void solve(){
  int n,m;
  cin>>n>>m;
  vi a(n);
  cin>>a;
  vector<int>flag(n,1);
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    if(a[x]==a[y]){
      flag[x]=0;
      flag[y]=0;
    }
    else if(a[x]<a[y]){
      flag[x]=0;
    }
    else{
      flag[y]=0;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=flag[i];
  }
  cout<<ans;
      
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



Measured memory_bytes: 4028
#include<iostream>
#include<deque>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	long long n, b, sum = 0;
	cin >> n;
	deque<long long> d(n);

	for (int i = 0; i < n; i++) {
		cin >> d[i];
		d[i] -= (i + 1);
	}
	sort(d.begin(), d.end());

	if (n % 2 == 1) {
		b = d[n / 2];
	}
	else {
		b = (d[n / 2] + d[n / 2 - 1]) / 2;
	}

	for (int i = 0; i < n; i++) {
		sum += abs(d[i] - b);
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>

#define N 2000001
#define K 10000

int A[N],B[N],C[N];

int main(){

int n,i,j;

scanf("%d",&n);

for(i=1;i<n+1;i++){
    scanf("%d",&A[i]);
}

for(i=0;i<=K;i++) C[i]=0;

for(j=1;j<=n;j++) C[A[j]]++;

for(i=1;i<=K;i++) C[i]=C[i]+C[i-1];

for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
}

for(i=1;i<n;i++) printf("%d ",B[i]);

printf("%d\n",B[n]);

return 0;

}

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  int h, w, n;
  cin >> h >> w >> n;
  arr(a,n);

  vec ar;
  rep(i,n){
    rep(j,a[i]){
      ar.pb(i+1);
    }
  }

  bool rev=false;
  rep(i,h){
    rep(j,w){
      if(!rev) cout << ar[i*w+j] << (j!=w-1?" ":"\n");
      else cout << ar[i*w+w-j-1] << (j!=w-1?" ":"\n");
    }
    rev = !rev;
  }

}


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

int n,fa,fb;
string s;
int chang;
int bh;
int main(){
	cin>>s;
	chang=s.length();
	bh=0;
	for(int i=0;i<=chang-1;i++){
		if(s[i]-'0'!=bh){
			fa++;
		}
		if(bh==0){
			bh=1;
		}else{
			bh=0;
		}
	}
	bh=1;
	for(int i=0;i<=chang-1;i++){
		if(s[i]-'0'!=bh){
			fb++;
		}
		if(bh==0){
			bh=1;
		}else{
			bh=0;
		}
	}
	n=min(fa,fb);
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int res = 0;
  for(int i = 0; i <(int)s.length();i++) {
  	if(s[i]!=t[i])res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int A, B;
    cin >> A>> B;
    if (A == B) {
        cout << A * 2 << endl;
    } else {
        cout << max(A, B) * 2 - 1 << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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



int main() {
    int N;
    cin>>N;
    vector <int>d(N);
    for(int i=0;i<N;i++)
        cin>>d.at(i);
    set<int> d2(d.begin(),d.end());
    cout<<d2.size()<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;


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

    long long ri, sa, n = k / 2;;
    if(k % 2 == 0) {
        ri = 1 + (pow(4, n) - 1) / 3;
        sa = ri - 1;
    }
    else {
        ri = 2 * (pow(4, n) - 1) / 3;
        sa = ri + 1;
    }

    long long A = ri * a + sa * b + sa * c,
              B = sa * a + ri * b + sa * c;

    cout << (abs(A - B) > 1e18 ? "Unfair" : to_string(A - B)) << endl;;
    return 0;
}

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

int main() {
	int i, j, m, h, sc;
	char tmp, dum;
	while (1) {
		queue<char> c;
		while (1) {
			cin.get(tmp);
			if (tmp == '-')return 0;
			else if (tmp == '\n')break;
			c.push(tmp);
		}
		cin >> m;
		for (i = 0; i < m; i++) {
			cin >> h;
			for (j = 0; j < h; j++) {
				c.push(c.front());
				c.pop();
			}
		}
		sc = c.size();
		for (i = 0; i < sc; i++) {
			cout << c.front();
			c.pop();
		}
		cout << endl;
		cin.get(dum);
	}
	return 0;
}

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<long long> vll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    ll r;
    cin >> r;
    cout << r*r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<string>s(n);
    int ans=0;
    rep(i,n){
        cin>>s[i];
        rep(j,s[i].size()-1){
            if(s[i][j]=='A'&&s[i][j+1]=='B')ans++;
        }
    }
    int a=0,b=0,ab=0;
    rep(i,n){
        if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')ab++;
        if(s[i][0]=='B'&&s[i][s[i].size()-1]!='A')b++;
        if(s[i][0]!='B'&&s[i][s[i].size()-1]=='A')a++;
    }
    if(a==0&&b==0&&ab>=2)cout<<ans+ab-1<<endl;
    else cout<<ans+min(ab+a,ab+b)<<endl;
}

Measured memory_bytes: 768
n = int(input())
a = list(map(int, input().split()))
b = [0] * 100010
for i in a:
    b[i] += 1

ans = 0
for i in range(1, 10 ** 5 - 1):
    ans = max(ans, b[i - 1] + b[i] + b[i + 1])
print(ans)

Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

ll dp[1001][1001];

int main() 
{
    fastio();

    int h,w;
    cin>>h>>w;
    char ch;
    dp[1][1] = 1;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>ch;
            if( i==0 && j==0 ) continue;
            if( ch == '.' )
            {
                dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1];
                dp[i+1][j+1] = mod(dp[i+1][j+1]);
            }
        }
    }
    cout<<dp[h][w],nl;
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<tuple>
#include<sstream>
#include<functional>
#include<list>
#include<queue>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> p;
typedef pair<int, pair<int, pair<int, int>>> PP;
typedef vector<int> vec;
using Graph = vector<vector<int>>;
using graph = vector<vector<ll>>;

const long long INF = 1LL << 60;
const int inf = 1e9;
const long long MOD = 1e9+7;

ll modpow(ll a, ll b, ll mod) {
	ll res = 1;
	while (b) {
		if (b & 1)res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	cout << 1 - n << endl;
	return 0;
}

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

#define MAX 100

int main(){
    int n, x[MAX];
    cin >> n;
    rep(i,n) cin >> x[i];

    int ans = 10000000;
    for(int p = 0; p <= 100; p++){
        int sum = 0;
        for(int i = 0; i < n; i++){
            sum += (x[i]-p)*(x[i]-p);
        }
        ans = min(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main() { 
   ll n; cin >> n;
   ll cnt = 0, num = 10;
   if(n%2==1) cout << 0 << ln;
   else{
        while(num <= n){
            cnt += n/num;
            num *= 5;
        }
        cout << cnt << ln;
   }
}








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

int r, c, k;
int grid[7][7], cpy[7][7];

void copy_mat()
{
	for (int i = 0; i < r; ++i)
		for (int j = 0; j < c; ++j)
			cpy[i][j] = grid[i][j];
}

int assign(int R, int C)
{
	int ans = 0;

	for (int i = 0; i < r; i++)
		if ((1 << i) & R)
		{
			int rn = i;

			for (int j = 0; j < c; ++j)
				ans += cpy[rn][j],
				       cpy[rn][j] = 0;
		}

	for (int i = 0; i < c; i++)
		if ((1 << i) & C)
		{
			int cn = i;

			for (int j = 0; j < r; ++j)
				ans += cpy[j][cn],
				       cpy[j][cn] = 0;
		}

	return ans;
}

int main()
{
	int ans = 0, cb = 0;	cin >> r >> c >> k;

	for (int i = 0; i < r; ++i)
		for (int j = 0; j < c; ++j)
		{
			char c;	cin >> c;
			if (c == '#')
				grid[i][j] = 1,
				             cb++;
		}

	// if (k > cb)	ans = 0; //cout << 0 << endl;
	// else if (k == cb)	ans = 1; //cout << 1 << endl;

	// else
	{
		for (int i = 0; i < (1 << r); ++i)
			for (int j = 0; j < (1 << c); ++j)
			{
				copy_mat();
				int val = assign(i, j);


				// cout << i << " " << j << " " << val << endl;

				if ((cb - val) == k)
					ans++;
			}
	}

	cout << ans << endl;

}

Measured memory_bytes: 3532
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll tmpa1=0, tmpa2=0;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
        if (tmpa1 < a[i]) tmpa1 = a[i];
        else if (tmpa2 < a[i]) tmpa2 = a[i];
    }
    REP(i, n) {
        if (a[i] == tmpa1) cout << tmpa2 << '\n';
        else cout << tmpa1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
const int N = 4e2 + 3 , OO = 0x3f3f3f3f;
typedef long long ll ;
int arr[N] , n ;
ll mem[N][N];
ll solve(int s , int e){
    if(s >= e)
        return 0;
    ll &ret = mem[s][e];
    if(~ret)
        return ret ;
    ret = 1LL * OO * OO ;
    ll sum = 0;
    for(int i = s ; i<=e ; ++i) sum+=arr[i];
    for(int i = s ; i<=e ; ++i)
        ret = min(ret , solve(s , i ) + solve(i + 1 , e) + sum);
    return ret;
}
int main(){
    memset(mem , -1 , sizeof mem);

    cin >> n;

    for(int i = 0 ; i < n ; ++i) {
        cin >> arr[i];
    }
    cout << solve(0 , n-1);
}


Measured memory_bytes: 1536
object Main extends App {
  import java.{ util => ju }
  import scala.annotation._
  import scala.collection._
  import scala.collection.{ mutable => mu }
  import scala.collection.JavaConverters._
  import scala.math._
  import scala.io.StdIn.readLine

  val sc = new ju.Scanner(System.in)

  val n = sc.nextInt()
  var nums = Array.fill(n)(sc.nextInt())

  for (i <- 0 until n) {
    val v = nums(i)
    var j = i - 1
    while (j >= 0 && v < nums(j)) {
      nums(j + 1) = nums(j)
      nums(j) = v
      j -= 1
    }
    printArray(nums)
  }

  def printArray(nums: Array[Int]) {
    for (i <- 0 until nums.length - 1) print(nums(i) + " ")
    println(nums.last)
  }
}

Measured memory_bytes: 49396
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 24 21:42:42 2019

@author: Owner
"""


X, Y = list(map(int, input().split()))
cnt = 0
for n in range(Y):
    if X*2**n ==Y:
        cnt = n +1
        break
    elif X*2**n >Y:
        cnt = n
        break
    else:
        pass

print(cnt)

Measured memory_bytes: 3060
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int power(int x, int y, int p)
{
    int res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

int main(){
    int p = 2019;
    string s;
    getline(cin, s);
    int n = s.length();
    vector <int> rem(n+1);
    rem[n] = 0;
    for (int i = n-1; i >= 0; i--){
        rem[i] = (((s[i]-'0')%p)*power(10, n-1-i, 2019) + rem[i+1])%p;
    }
    map <int, int> m;
    set <int> q;
    for (int i = 0; i < n; i++){
        m[rem[i]]++;
        //cout << rem[i] << endl;
        q.insert(rem[i]);
    }
    ll ans = 0;
    for (auto i = q.begin(); i != q.end(); i++){
        //cout << m[*i] << endl;
        if (*i == 0){
            ans += (m[*i]*(m[*i]+1))/2;
        }
        else
         ans += (m[*i]*(m[*i]-1))/2;
    }
    cout << ans;
    return 0;
}




Measured memory_bytes: 4364
#include<cstdio>
int t,n,c[510],s[510],f[510],i,a,j;main(){for(scanf("%d",&n);~scanf("%d%d%d",c+j++,s+j,f+j););for(f[j-1]=1;i<n;a=!printf("%d\n",a))for(j=i++;t=s[j];)a=(a<t?t:(~-a/f[j]+1)*f[j])+c[j++];}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

long long power(int a, int b){
	long long ret = 1;
	for(int i=b;i>0;i--){
		ret *= a;
	}
	return ret;
}

int main(void){
	vector<int> input(3);
	cin >> input[0] >> input[1] >> input[2];
	sort(input.begin(), input.end());
	if(input[0] + input[1] == input[2]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()

m = a[-1]
res = m
temp = 0
for i in range(n):
    if res > abs(m - 2*a[i]):
        res = abs(m - 2*a[i])
        temp = a[i]

print(m, temp)


Measured memory_bytes: 14056
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int A[N],B[N],C[N];
    int sum = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    for(int i = 0; i < N-1; i++){
        cin >> C[i];
    }

    for(int i = 0; i < N; i++){
        sum += B[A[i]-1];
        if(i >= 1 && A[i-1] == A[i]-1){
            sum += C[A[i-1]-1];
        }
    }

    cout << sum << endl;


}

Measured memory_bytes: 256
module IntSet = Set.Make (struct
  type t = int
  let compare = (-)
end)

let read_ns () = Scanf.scanf "%d %d " (fun x y -> (x, y))

let () =
  let (n, m) = read_ns () in
  let rec doit i to1 toN =
    if i = m then (to1, toN)
    else
      let (a, b) = read_ns () in
      doit (i + 1)
        (if a = 1 then IntSet.add b to1 else to1)
        (if b = n then IntSet.add a toN else toN) in
  let (to1, toN) = doit 0 IntSet.empty IntSet.empty in
  print_endline
    (if IntSet.is_empty (IntSet.inter to1 toN) then "IMPOSSIBLE"
     else "POSSIBLE")

Measured memory_bytes: 16256
import java.io.*;
class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] str_Three_Number = br.readLine().split(" ");
    int[] three_Number = new int[3];
    for(int i = 0; i < 3; i++){
      three_Number[i] = Integer.parseInt(str_Three_Number[i]);
    }
    for(int i = 0; i <= three_Number.length - 1; i++){
      for(int j = three_Number.length - 1; j > 0 ; j-- ){
        if(three_Number[j-1] > three_Number[j]){
          int tmp = three_Number[j];
          three_Number[j] = three_Number[j - 1];
          three_Number[j - 1] = tmp;
        }
      }
    }
    System.out.println(three_Number[0] + " " + three_Number[1] + " " + three_Number[2]);
  }
}



Measured memory_bytes: 24328
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main()
{
    ll a,b,c,i,j,k,x,z,y;
    cin>>a>>b>>c;
    if(b>c)swap(b,c);
    j=(c-b);
    if(j%2==0)
    {
        cout<<(j/2)<<endl;
    }
    else
    {
        i=(a-c);
        k=(b-1);
        x=min(k,i);
        if(i==x)
        {
           b=b+x;
           z=(a-b+1)/2+x;
        }
        else
        {
            c=c-x;
            z=(c)/2+x;
        }
        cout<<z<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  while(cin>>n,n){
    int x[n][n],y[n][n];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	cin>>x[j][i]>>y[j][i];
    bool used[n][n];
    bool visit[n][n];
    memset(used,0,sizeof(used));
    int ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(used[i][j]) continue;
	memset(visit,0,sizeof(visit));
	int tx=i,ty=j;
	bool f=1;
	while(!visit[tx][ty]){
	  //cout<<tx<<" "<<ty<<endl;
	  if(used[tx][ty]){
	    f=0;
	    break;
	  }
	  visit[tx][ty]=1;
	  int py=ty,px=tx;
	  tx=x[px][py];
	  ty=y[px][py];
	}
	if(f){
	  ans++;
	  while(!used[tx][ty]){
	    used[tx][ty]=1;
	    int py=ty,px=tx;
	    tx=x[px][py];
	    ty=y[px][py];
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyg"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYG";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  vector<double> a(N);
  rep(i,N) cin>>a[i];
  sort(a.begin(),a.end());
  rep(i,N-1){
    a[i+1]=(a[i]+a[i+1])/2;
  }
  cout<<a[N-1]<<endl;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
//g++ -std==c++14
//setprecision(10)
int n, m, out, a, b;
vector <vector <int> > G;
vector <int> used;
void dfs(int a){
    bool h = true;
    for(int i = 0; i < n; i++)
        if(!used[i])
            h = false;
    if(h)
        out++;
    for(int i = 0; i < G[a].size(); i++){            
        int to = G[a][i];
        if(used[to])continue;
        used[to] = true;
        dfs(to);
        used[to] = false;
    }
}

int main(){
    cin >> n >> m;
    G = vector <vector <int> > (n);
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--;    b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    used = vector <int> (n);
    used[0] = true;
    dfs(0);
    cout << out << endl;
}

Measured memory_bytes: 256
N = int(input())
S = input()
S_l = S[:N]
S_r = S[N:][::-1]
dict_l = {}
dict_r = {}
ans = 0
for num in range(2**N):
  tmpl_1 = ""
  tmpl_2 = ""
  tmpr_1 = ""
  tmpr_2 = ""
  for n in range(N):
    if (num >> (N-1-n) & 1):
      tmpl_1 += S_l[n]
      tmpr_1 += S_r[n]
    else:
      tmpl_2 += S_l[n]
      tmpr_2 += S_r[n]
  dict_l[tmpl_1+"_"+tmpl_2] = dict_l.get(tmpl_1+"_"+tmpl_2, 0) + 1
  dict_r[tmpr_1+"_"+tmpr_2] = dict_r.get(tmpr_1+"_"+tmpr_2, 0) + 1
for k, v in dict_l.items():
  ans += v*dict_r.get(k,0)
print(ans)



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

vector<int> edges[100001];
int dp[100001] = {};
bool vis[100001] = {};

int dfs(int u) {
	if(edges[u].size() == 0) return 0;
	if(vis[u]) return dp[u];
	vis[u] = true;
	for(int v:edges[u]) {
		dp[u] = max(dp[u], dfs(v));
	}
	dp[u]++;
	return dp[u];
}

int main() {
	int N,M;
	cin >> N >> M;
	for(int i=0;i<M;i++) {
		int u, v;
		cin >> u >> v;
		edges[v].push_back(u);
	}
	int ans = 0;
	for(int i=1;i<=N;i++) {
		ans = max(ans, dfs(i));
	}
	cout << ans;
}

Measured memory_bytes: 9216
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

typedef struct{
  int x;
  int y;
}point;


void in_next(vector<point> &list,vector<vector<int> > &map,int m,int d,int i){

  int dx=0,dy=0;

  if(d==0){
    dx=-1;
  }
  else if(d==1){
    dy=1;
  }
  else if(d==2){
    dx=1; 
  }
  else if(d==3){
    dy=-1; 
  }


  list[i].x=list[m].x + dx;
  list[i].y=list[m].y + dy;

  map[list[i].y][list[i].x]=1;
}


int main()
{

  while(true){

    int w=420,h=420;
    int n;
    cin >> n;

    if(n==0){
      break;
    }

    int x=210,y=210;
    vector<point> list(n);
    vector<vector<int> > map(h,vector<int>(w,0));    



    for(int i=0;i<n;i++){
      if(i==0){
        point tmp;
        tmp.x=x;
        tmp.y=y;
        list[i].x=x;
        list[i].y=y;
        map[list[i].y][list[i].x]=1;
      }else{
        int m,d;
        point p;
        cin >> m >> d; 
        in_next(list,map,m,d,i); 
      }
    }
    
    int max_up=1000,max_down=0,max_left=1000,max_right=0;
    

    for(int i=0;i<h;i++){
      for(int k=0;k<w;k++){
        if(map[i][k]==1){
          if(max_up>i) max_up = i;
          if(max_down<i) max_down = i;
          if(max_left>k) max_left = k;
          if(max_right<k) max_right = k;
        }
      }
    }

    cout << max_right-max_left+1 << " " << max_down-max_up+1 << endl;  

  }

  return 0;
}

Measured memory_bytes: 1860
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cmp::{max, min, Ordering};
use std::collections;
use std::io::{stdin, BufRead};

macro_rules! get {
  ($rd:ident; V; $t:ty) => {
    scanl($rd, b'\n')
      .split_whitespace()
      .map(|w| get_inner!{w; $t})
      .collect::<Vec<_>>()
  };
  ($rd:ident; T; $($t:ty),+) => {
    {
      let s = scanl($rd, b'\n');
      let mut i = s.split_whitespace();
      ( $( get_inner!{i.next().unwrap(); $t}),+ )
    }
  };
  ($rd:ident; $t:ty) => (get_inner!{scanl($rd, b'\n'); $t});
}

macro_rules! get_inner {
  ($src:expr; $t:ty) => {
    $src.parse::<$t>().expect("Parse Error")
  };
}

macro_rules! gets {
  ($rd:ident; $n:expr; $($tok:tt)*) => {
    (0..)
      .take($n)
      .map(|_| get!{$rd; $($tok)*})
      .collect::<Vec<_>>()
  };
}

fn solve(rd: &mut BufRead) {
  let n = get!(rd; u64);
  let mut x = (n as f64).sqrt() as u64;

  loop {
    if n % x == 0 {
      break;
    }
    
    x -= 1;
  }
  
  println!("{}", n / x + x - 2);
}

fn scanl(rd: &mut BufRead, delim: u8) -> String {
  let mut buf = Vec::new();
  let _ = rd.read_until(delim, &mut buf).expect("Read Failed");
  String::from_utf8(buf)
    .expect("Invalid UTF-8 String")
    .trim_right()
    .to_string()
}

fn main() {
  let rd = stdin();
  let mut rd = rd.lock(); // std::io::StdinLock
  solve(&mut rd);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	cin>>a>>b>>c;
	int maxn=max(a,max(b,c));
	int ans=0;
	if(a==maxn)
	{
		ans=(a-b)/2+(a-c)/2;
		if((a-b)%2==0&&(a-c)%2==0);
		else
		if((a-b)%2==1&&(a-c)%2==1)ans++;
		else ans+=2;
	}
	else
	if(b==maxn)
	{
		ans=(b-a)/2+(b-c)/2;
		if((b-a)%2==0&&(b-c)%2==0);
		else
		if((b-a)%2==1&&(b-c)%2==1)ans++;
		else ans+=2;
	}
	else
	if(c==maxn)
	{
		ans=(c-a)/2+(c-b)/2;
		if((c-b)%2==0&&(c-a)%2==0);
		else
		if((c-b)%2==1&&(c-a)%2==1)ans++;
		else ans+=2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
    int a;
    cin >> a;

    int x, y, z;
    x = a % 10;
    y = ((a - x) / 10) % 10;
    z = ((a - x - y * 10) / 100);

    if (x == 7 || y == 7 || z == 7) {
        cout << "Yes";
    } else {
        cout << "No";
    }



    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<l_l> v;
    rep(i, N){
        cin >> A[i];
        v.push_back({A[i],i});
    }
    sort(all(v));
    sort(all(A));
    vector<ll> ans(N);
    rep(i,N){
        if(i < N/2){
            ans[v[i].second] = A[N/2];
        }
        else{
            ans[v[i].second] = A[N/2-1];
        }
    }
    rep(i,N){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 9448
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Sun Dec 30 23:19:11 2018
//
package main

import "fmt"

type pos struct {
	x, y int
}

func (p pos) dist(q pos) int {
	return abs(p.x-q.x) + abs(p.y-q.y)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var H, W, D int

	_, _ = fmt.Scan(&H, &W, &D)

	arr := make([]pos, H*W+1)
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			var a int
			_, _ = fmt.Scan(&a)
			arr[a].x = i + 1
			arr[a].y = j + 1
		}
	}

	dists := make([][]int, D)
	for i := 1; i <= H*W; i++ {
		if i <= D {
			dists[i%D] = append(dists[i%D], 0)
			if i == D {
				dists[i%D] = append(dists[i%D], 0)
			}
		} else {
			dists[i%D] = append(dists[i%D], arr[i].dist(arr[i-D]))
		}
	}

	for i := range dists {
		for j := range dists[i] {
			if j+1 < len(dists[i]) {
				dists[i][j+1] += dists[i][j]
			}
		}
	}

	var Q int
	_, _ = fmt.Scan(&Q)
	for i := 0; i < Q; i++ {
		var l, r int
		_, _ = fmt.Scan(&l, &r)
		fmt.Println(dists[r%D][r/D] - dists[l%D][l/D])
	}
}


Measured memory_bytes: 8192