akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n, s) for (int i = s; i < n; i++)
#define graph map<int, vector<int>>
#define field vector<vector<int>>
using namespace std;
int main()
{
    int x;
    cin >> x;
    if (x >= 30)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
import heapq
N = int(input())
A = list(map(int, input().split()))
hq = []
for i in range(N):
    heapq.heappush(hq, -A[i])
X, x1, x2, Y, y1, y2= 0, 0, 0, 0, 0, 0
x1 = -heapq.heappop(hq)
while hq:
    x2 = -heapq.heappop(hq)
    if x1 == x2:
        X = x1
        break
    else:
        x1 = x2
if len(hq) != 0:
    y1 = -heapq.heappop(hq)
    while hq:
        y2 = -heapq.heappop(hq)
        if y1 == y2:
            Y = y1
            break
        else:
            y1 = y2
print(X*Y)

Measured memory_bytes: 65048
n = int(input())
num = [int(i) for i in input().split()]

count = 1
vertexCount = 0
rem = sum(num)
for m in num:
    vertexCount += count
    count -= m
    rem -= m
    if count < 0:
        vertexCount = -1
        break
    count = min(count*2, rem)

print(vertexCount)

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

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, K;
long long A[15];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> K;
  rep(i, N) cin >> A[i];
  long long m = (1LL<<60);
  for (int b=(1<<N)-1; b>=0; b--) {
    int c = 0;
    rep(i, N) {
      if (b & (1<<i)) c++;
    }
    if (c != K) continue;
    long long t = 0, x = 0;
    bool f = true;
    rep(i, N) {
      if ((b & (1<<i)) == 0) {
        if (A[i] >= x) {
          f = false;
          break;
        }
        continue;
      }
      x = max(x+1, A[i]);
      t += x - A[i];
    }
    if (!f) continue;
    m = min(m, t);
  }
  cout << m << "\n";
  return 0;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    ll n, k, ans = 0;
    cin >> n >> k;
    vector<ll> h(n);
    for (ll i = 0; i < n; ++i) {
        cin >> h[i];
    }
    sort(h.rbegin(), h.rend());
    for (int i = 0; i < n; ++i) {
        if (i <= k - 1)
            continue;
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vll path;
//***********//
class UnionFind {
public:
	vl rank, par, siz;
	UnionFind() {}
	UnionFind(ll N) {
		rank.resize(N, 0);
		par.resize(N, 0);
		siz.resize(N, 1);
		init(N);
	}
	void init(ll N) {
		for (ll i = 0; i < N; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	ll find(ll x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}
	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if (x != y) {
			if (rank[x] < rank[y]) {
				par[x] = y;
				siz[y] += siz[x];
			}
			else {
				par[y] = x;
				siz[x] += siz[y];
				if (rank[x] == rank[y]) rank[x]++;
			}
		}
	}
	bool issame(ll x, ll y) {
		return find(x) == find(y);
	}
	ll size(ll x) {
		return siz[find(x)];
	}
};
int main() {
	cin >> N;
	path.resize(N);
	UnionFind UF(N);
	ans = 0;
	vl enter(N+1);
	for (i = 0; i < N-1; i++) {
		ll u, v;
		cin >> u >> v;
		ll P = min(u, v);
		ll Q = max(u, v);
		ans -= P * (N - Q + 1);
	}
	for (i = 1; i <= N; i++) {
		ans += i * (N - i + 1);
	}
	co(ans);
}

Measured memory_bytes: 14332
N, X = map(int, input().split())
L_list = [1] * (N + 1)
for i in range(1, N+1):
    L_list[i] = 3+2*L_list[i-1]
paty_list = {(0, 1): 1}

def paty(L, n):
    if (L, n) in paty_list:
        return paty_list[L, n]
    ans = 0
    count = 0
    if count + 1 >= n:
        paty_list[(L, n)] = ans
        return ans
    count += 1
    if L_list[L-1] + count > n:
        ans += paty(L-1, n-count)
        paty_list[(L, n)] = ans
        return ans
    ans += paty(L-1, L_list[L-1])
    count += L_list[L-1]  
    if count + 1 > n:
        paty_list[(L, n)] = ans
        return ans
    ans += 1
    count += 1
    if L_list[L-1] + count > n:
        ans += paty(L-1, n-count)
        paty_list[(L, n)] = ans
        return ans
    ans += paty(L-1, L_list[L-1])
    paty_list[(L, n)] = ans
    return ans

print(paty(N, X))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main() {
  int w, h, s, t, x, y, ans;
  queue<vector<int>> que;
  while (cin >> w >> h, w) {
    ans = 0;
    vector< vector<int> > m(h+2, vector<int>(w+2, 0));
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
	cin >> m[i+1][j+1];
      }
    }
    s = 0; t = 0;
    while (s != h+1 || t != w+1) {
      if (!m[s][t]) {
	if (t < w+1) ++t;
	else {
	  t = 0;
	  ++s;
	}
      } else {
	que.push({s, t});
	m[s][t] = 0;
	while (!que.empty()) {
	  x = que.front()[0];
	  y = que.front()[1];
	  que.pop();
	  if (m[x-1][y]) {
	    m[x-1][y] = 0;
	    que.push({x-1, y});
	  }
	  if (m[x+1][y]) {
	    m[x+1][y] = 0;
	    que.push({x+1, y});
	  }
	  if (m[x][y-1]) {
	    m[x][y-1] = 0;
	    que.push({x, y-1});
	  }
	  if (m[x][y+1]) {
	    m[x][y+1] = 0;
	    que.push({x, y+1});
	  }
	  if (m[x+1][y+1]) {
	    m[x+1][y+1] = 0;
	    que.push({x+1, y+1});
	  }
	  if (m[x+1][y-1]) {
	    m[x+1][y-1] = 0;
	    que.push({x+1, y-1});
	  }
	  if (m[x-1][y+1]) {
	    m[x-1][y+1] = 0;
	    que.push({x-1, y+1});
	  }
	  if (m[x-1][y-1]) {
	    m[x-1][y-1] = 0;
	    que.push({x-1, y-1});
	  }
	}
	++ans;
      }
    }
    cout << ans << endl;
    m.erase(m.begin(), m.end());
  }
  return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    char u1,u2,u3;
    char d1,d2,d3;
    cin >>u1>>u2>>u3>>d1>>d2>>d3;

    if(u1 == d3 && u2 == d2 && d1==u3)flag=true;
    else flag=false;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout<<ans<<endl;
    if(flag)cout << "YES" <<endl;
    else cout << "NO" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);

    long long ans = 1;
    ans = k;

    int i;
    for (i = 0; i < n - 1; i++)
    {
        ans *= (k - 1);
    }
    
    printf("%lld",ans);
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

struct Edge{
  int to;
  long long cost;
};
struct NODE{
  int pos;
  long long cost;
};

bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
class dijkstra{
  public:
    const int MAX_V = 1000000;
    vector<Edge> g[100000],rg[100000];
    bool visit[100000];

    int N;
    const ll INF = 1e15;
    dijkstra(){};
    dijkstra(int n):N(n){};
    vector<ll> shorter_path(int s){
      priority_queue<NODE> Q;
      Q.push({s,0});
      vector<ll> res(N,INF);
      while(Q.size()){
        NODE q= Q.top();Q.pop();
        if(res[q.pos] == INF){
          res[q.pos] = q.cost;
        }
        else{
          continue;
        }
        for(auto n : g[q.pos]){
          Q.push({n.to,q.cost+n.cost});
        }
      }
      return res;
    }
    void push(int p,int to,int c){
      g[p].push_back({to,c});
      rg[to].push_back({p,c});
    }
    deque<ll> Topological_sort(){
      deque<ll> res;
      rep(i,N){
        dfs(res,i);
      }
      return res;
    }
    void dfs(deque<ll> &res,int k){
      if(!visit[k]){
        visit[k] = true;
        for (auto&& nxt : g[k]) {
          dfs(res,nxt.to);
        }
        res.emplace_front(k);
      }
    }
    pll farthest_point(int n,int p){
      pll r = {0,n};
      for (auto&& k : g[n]) {
        if(k.to != p){
          pll res = farthest_point(k.to,n);
          res.fi += k.cost;
          if(r.fi < res.fi) r = res;
        }
      }
      return r;
    }
    ll diameter(){
      pll a = farthest_point(0,-1);
      pll b = farthest_point(a.se,-1);
      return b.fi;
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll a,b,c;
  dijkstra d(n);
  rep(i,n-1){
    cin >> a >> b >> c;
    --a,--b;
    d.push(a,b,c);
    d.push(b,a,c);
  }
  ll q,k;
  cin >> q >> k;
  --k;
  auto dis = d.shorter_path(k);
  rep(i,q){
    cin >> a >> b;
    --a,--b;
    cout << dis[a] + dis[b] << endl;
  }
  return 0;
}


Measured memory_bytes: 19680
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
edge=[[]for _ in range(n)]
for i in range(n-1):edge[int(input())-1].append(i+1)
def dfs(v):
  d=[dfs(i)for i in edge[v]]
  d.sort()
  ans=0
  l=len(d)
  for i,j in enumerate(d):
    ans=max(ans,l-i+j)
  return ans
print(dfs(0))


Measured memory_bytes: 227968
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt(), y = sc.nextInt();
		
		System.out.println(gcd(x, y));
	}
	
	static int gcd(int x, int y) {
		if(y == 0) {
			return x;
		} else {
			return gcd(y, x % y);
		}
	}
}

Measured memory_bytes: 26172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int cnt[201];
int cnt2[201];
vi vec;

void yes(){cout << "Possible";}
void no(){cout << "Impossible";}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for(int i = 0; i < n; i++)
	{
		int x; cin >> x; vec.pb(x);
		cnt2[x]++;
	}
	sort(vec.begin(), vec.end());
	int d = vec[0];
	if(vec[n-1] > 2*d)
	{
		no(); return 0;
	}
	if(n == 2)
	{
		if(cnt2[1] == 2) yes();
		else no();
		return 0;
	}
	for(int i = 1; i <= d; i++)
	{
		for(int j = 0; j < 100; j++)
		{
			cnt[j] = cnt2[j];
		}
		bool pos = true;
		cnt[d]--;
		for(int j = 1; j <= i; j++)
		{
			if(cnt[d+j]==0)
			{
				pos = false;
				break;
			}
			cnt[d+j]--;
		}
		if(!pos) continue;
		for(int j = 1; j <= d; j++)
		{
			int val = max(j + i, d - j);
			if(cnt[val] == 0)
			{
				pos = false;
				break;
			}
			cnt[val]--;
		}
		if(!pos) continue;
		for(int j = 1; j <= d; j++)
		{
			if(cnt[j] > 0) pos = false;
		}
		for(int j = d + i + 1; j < n; j++)
		{
			if(cnt[j] > 0) pos = false;
		}
		if(pos)
		{
			//cerr << i << '\n'; 
			yes(); 
			return 0;
		}
	}
	no();
}	


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 5e5 + 10;
const int inf = 0x7ffffff;
ll n, k;
void solve()
{
    cin >> n >> k;
    ll tmp = min(abs(n % k - k), n % k);
    cout << tmp;
}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 256
a = 0
b = 0
c = []
ans = 10000000
N = int(input())
for i in input().split():
  a += int(i)
  c.append(int(i))

for i in range(N):
  b += c[i]
  ans = min(abs(a/2-b)*2, ans)

print(int(ans))

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
    x=0;char ch;bool flag = false;
    while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
    while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 45;
const double eps = 1e-15;
const double det = 0.99;
struct Point{
    double x,y,z;
    Point(const double &a=0,const double &b=0,const double &c=0){
        x=a;y=b;z=c;
    }
};
inline double dis(const Point &a,const Point &b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}
int n;double ans = 1e100;
Point p[maxn];
inline double f(const Point &x){
    double ret = 0;
    for(int i=1;i<=n;++i) ret = max(ret,dis(x,p[i]));
    if(ret < ans) ans = ret;
    return ret;
}
inline double ran(){
    return (rand() % 1000 + 1)/1000.0;
}
Point nw;
int main(){
    srand(2333);
    while(1){
        read(n);if(n == 0) break;
        nw.x = nw.y = nw.z = 0;
        ans = 1e100;
        for(int i=1;i<=n;++i){
            scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].z);
        }
        double T = 100.0,x;
        double dist;int pos;
        while(T > eps){
            dist = 0.0;
            for(int i=1;i<=n;++i){
                if(dist < dis(nw,p[i])){
                    pos = i;dist = dis(nw,p[i]);
                }
            }
            Point nx(
                nw.x+(p[pos].x-nw.x)/dist*T,
                nw.y+(p[pos].y-nw.y)/dist*T,
                nw.z+(p[pos].z-nw.z)/dist*T
                );
            x = f(nw) - f(nx);
            if(x > 0 || exp(x/T) > ran()) nw = nx;
            T *= det;
        }
        printf("%.5lf\n",ans);
    }
    getchar();getchar();
    return 0;
}


Measured memory_bytes: 3120
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]

def f(a, b, x, y):
    return abs(a-x) + abs(b-y)

ans = [0] * N
for i, _ab in enumerate(ab):
    temp = float("inf")
    for j, _cd in enumerate(cd):
        dist = f(_ab[0], _ab[1], _cd[0], _cd[1])
        if dist < temp: 
            temp, ans[i] = dist, j + 1

for r in ans:
    print(r)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e18);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    vector<ll> l(n),r(n);
    vector<pair<ll, ll>> x(n);
    rep0(i, n)cin >> l[i] >> r[i];
    sort(all(l));
    sort(all(r),greater<>());
    if(n % 2 == 0)pf((r[n / 2 - 1] + r[n / 2]) - (l[n / 2 - 1] + l[n / 2]) + 1);
    else pf(r[n / 2] - l[n / 2] + 1);
    return 0;
}


Measured memory_bytes: 9596
#include <stdio.h>
#include <vector>
#include <utility>
typedef long long ll;

int main(void) {
  ll inf = 10e15;
  ll i, j, k, v, r, e;
  scanf("%lld%lld%lld", &v, &e, &r);
  ll dis[v], now = r, smax = 1;
  char flag[v];
  std::vector< std::pair<ll, ll> > vec[v];
  std::vector< std::pair<ll, ll> >::iterator it;
  std::pair<ll, ll> seg[4 * v];
  while(smax < v) smax *= 2;
  for(i = 0; i <= smax * 2; ++i) {
    seg[i].first = inf; seg[i].second = i - smax;
  }
  for(i = 0; i < smax; ++i) seg[i].second = 1000000;
  seg[1].second = r;
  for(i = 0; i < v; ++i) dis[i] = inf, flag[i] = 1;
  flag[r] = 0;
  dis[r] = 0;
  for(i = 0; i < e; ++i) {
    ll ta, tb, tc;
    std::pair<ll, ll> p;
    scanf("%lld%lld%lld", &ta, &tb, &tc);
    p = std::make_pair(tb, tc);
    vec[ta].push_back(p);
  }
  for(k = 1; k < v; ++k) {
    for(it = vec[now].begin(); it != vec[now].end(); ++it) {
      if(flag[(*it).first] && dis[(*it).first] > dis[now] + (*it).second) {
        dis[(*it).first] = dis[now] + (*it).second;
        seg[smax + (*it).first].first = dis[now] + (*it).second;
        ll tmp = smax + (*it).first;
        tmp /= 2;
        while(tmp) {
          seg[tmp] = seg[tmp * 2] > seg[tmp * 2 + 1] ? seg[tmp * 2 + 1] : seg[tmp * 2];
          tmp /= 2;
        }
      }
    }
    if(now == seg[1].second || seg[1].first == inf) break;
    now = seg[1].second;
    flag[now] = 0;
    ll tmp = now + smax;
    seg[tmp].first = inf;
    tmp /= 2;
    while(tmp) {
      seg[tmp] = seg[tmp * 2] > seg[tmp * 2 + 1] ? seg[tmp * 2 + 1] : seg[tmp * 2];
      tmp /= 2;
    }
    /*for(i = 0; i < v; ++i) printf("%lld ", dis[i]);
    printf("&%lld\n", now);*/
  }
  for(i = 0; i < v; ++i) {
    if(dis[i] != inf) printf("%lld\n", dis[i]);
    else printf("INF\n");
  }
  return 0;
}


Measured memory_bytes: 23268
def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    c = [int(x) for x in input().split()]

    answer = sum(b)
    for i in range(n-1):
        if a[i+1] == a[i]+1:
            answer += c[a[i]-1]
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void dfs(ll n, vector<ll> c, ll d) {
	if (n == 0) {
		// cout << (int)c.size() << ": "; 
		rep(i, (int)c.size()-1) {
			printf("%c", c[i]+'a');
		}
		printf("%c\n", c[(int)c.size()-1]+'a');
	} else {
		vector<ll> res;
		rep(i, (int)c.size()) {
			res.emplace_back(c[i]);
		}
		rep(i, d+1) {
			res.emplace_back(i);
			if (i != d) dfs(n-1, res, d); else dfs(n-1, res, d+1);
			res.erase(res.end()-1);
		}  
	}
	
}

void solve(long long N){
	vector<ll> r = {};
	dfs(N, r, 0);
}

int main(){	
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}



Measured memory_bytes: 1536
#include <iostream>
#include<iomanip>
using namespace std;
int main(){
    int input;
    int kosu;
    int a,b,c,d,e,f,g,h,i;
    cin >> a >> b >> c;
    cin >> d >> e >> f;
    cin >> g >> h >> i;
    cin >> kosu;
    for (int j = 0; j < kosu; j++){
        cin >> input;
        if(a==input){
            a=0;
        }else if(b==input){
            b=0;
        }else if(c==input){
            c=0;
        }else if(d==input){
            d=0;
        }else if(e==input){
            e=0;
        }else if(f==input){
            f=0;
        }else if(g==input){
            g=0;
        }else if(h==input){
            h=0;
        }else if(i==input){
            i=0;
        }
        input = 0;
    }
    if(a==b&&b==c){
        cout << "Yes" << endl;
    }else if(d==e&&e==f){
        cout << "Yes" << endl;
    }else if(g==h&&h==i){
        cout << "Yes" << endl;
    }else if(a==d&&d==g){
        cout << "Yes" << endl;
    }else if(b==e&&e==h){
        cout << "Yes" << endl;
    }else if(c==f&&f==i){
        cout << "Yes" << endl;
    }else if(a==e&&e==i){
        cout << "Yes" << endl;
    }else if(c==e&&e==g){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace Computation
{
    class Min__Max_and_Sum
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split(' ').Take(n).Select(s =>long.Parse(s)).ToArray();

            //var min = array[0];
            //var max = array[0];
            //var sum = 0;

            //for(int i = 0; i < n; i++)
            //{
            //    if (array[i] < min) min = array[i];
            //    if (array[i] > max) max = array[i];
            //    sum += array[i];
            //}

            Console.WriteLine(array.Min() + " " + array.Max() + " " + array.Sum());
            //Console.WriteLine(min + " " + max + " " + sum);
        }
    }
}

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

struct vec{
    double x,y;
    vec operator-(vec b){
        vec& a = *this;
        vec c;
        c.x=a.x-b.x;c.y=a.y-b.y;
        return c;
    }
};

double inner_product(vec& a, vec& b){
    return a.x*b.x+a.y*b.y;
}

double outer_product(vec& a, vec& b){
    return a.x*b.y-a.y*b.x;
}
const double eps = 0.00001;
int main(void){
    vec p0,p1,p2,p3,v1,v2;
    int q;
    cin >> q;
    for(int k=0;k<q;k++){
        cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
        v1=p1-p0; v2=p3-p2;
        double i,o;
        i=inner_product(v1,v2);
        o=outer_product(v1,v2);
        if(abs(o)<eps){
            cout << 2 << endl;
        }else if(abs(i)<eps){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	string s;
	int cnt = 0;
	cin >> s;
	for(int i = 0; i < 3; i++){
		if(s[i] == s[i+1]){
			break;
		}else{
			cnt++;
		}
	}
	if(cnt == 3){
		cout << "Good" << endl;
	}else{
		cout << "Bad" << endl;
	}
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;


#[fastout]
fn main() {
    input! {
    n: usize
    }
    let mut an = vec![];
    let mut xyn = vec![];
    for _ in 0..n {
        input! {
        a: usize,
        xy: [(Usize1, usize); a]
        }
        an.push(a);
        xyn.push(xy);
    }
    let mut ans = 0;
    for i in 0..1 << n {
        let mut honest = (i as usize).count_ones();
        for j in 0..n {
            let (a, xy) = (an[j], &xyn[j]);
            if i & 1 << j == 0 {continue}
            for k in 0..a {
                let (x, y) = xy[k];
                if (i >> x) % 2 != y {
                    honest = 0;
                }
            }
        }
        ans = max(honest, ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2176
/*
 * ITP1_11_B: Rolling the dice II
 */

#include <stdio.h>

// rolling relations by index (N, S, E, W, clockwise, anti-clockwise)
int T[6][1 + 6] = {{0, 2, 6, 3, 4, 1, 5},
                   {0, 5, 1, 3, 4, 6, 2},
                   {0, 4, 2, 1, 6, 5, 3},
                   {0, 3, 2, 6, 1, 5, 4},
                   {0, 1, 3, 5, 2, 4, 6},
                   {0, 1, 4, 2, 5, 3, 6}};
int move['Z'];

void rotate(int direction, int p[])
{
    int q[1 + 6];
    int i;

    for (i = 1; i <= 6; i++)
        q[i] = p[T[move[direction]][i]];

    for (i = 1; i <= 6; i++)
        p[i] = q[i];

    return;
}

int main(void)
{
    int dice[1 + 6]; // one-based indexing
    int ntry; // 
    int top, front;
    int i;

    move['N'] = 0;
    move['S'] = 1;
    move['E'] = 2;
    move['W'] = 3;
    move['C'] = 4; // Clockwise
    move['A'] = 5; // Anti-clockwise

    for (i = 1; i <= 6; i++)
        scanf("%d", &dice[i]);

    scanf("%d", &ntry);

    for (i = 0; i < ntry; i++) {
        scanf("%d %d", &top, &front);

        // align the top face.
        if      (top == dice[2])
                rotate('N', dice);
        else if (top == dice[3])
                rotate('W', dice);
        else if (top == dice[4])
                rotate('E', dice);
        else if (top == dice[5])
                rotate('S', dice);
        else if (top == dice[6]) {
                rotate('N', dice);
                rotate('N', dice);
        }

        // align the front face.
        while (dice[2] != front)
            rotate('C', dice);

        // print right face.
        printf("%d\n", dice[3]);
    }

    return 0;
}



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

int main(void) {
	int n;
	cin >> n;
	vector<int> colors(9, 0);
	rep (i, n) {
		int a; cin >> a;
		if (1 <= a && a <= 399) colors[0]++;
		else if (400 <= a && a <= 799) colors[1]++;
		else if (800 <= a && a <= 1199) colors[2]++;
		else if (1200 <= a && a <= 1599) colors[3]++;
		else if (1600 <= a && a <= 1999) colors[4]++;
		else if (2000 <= a && a <= 2399) colors[5]++;
		else if (2400 <= a && a <= 2799) colors[6]++;
		else if (2800 <= a && a <= 3199) colors[7]++;
		else colors[8]++;
	}
	int cnt = 0;
	rep (i, 8) {
		if (colors[i]) cnt++;
	}
	int add = 0;
	if (cnt == 0 && colors[8]) add = 1;
	cout << cnt + add << endl;
	cnt += colors[8];
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
          int[] n = ReadLine().Split(' ').Select(int.Parse).ToArray();
          if(n[0] == n[1]) WriteLine("Yes");
          else WriteLine("No");
      }
   }
}

Measured memory_bytes: 13396
#include <stdio.h>
#define max(a, b) ((a)>(b) ? (a) : (b))

int main(void){
  int n, happiness[100001][3], dp[100002][3] = {0};
  scanf("%d", &n);
  for(int i=0; i<n; i++) for(int j=0; j<3; j++) scanf("%d", &happiness[i][j]);

  for(int i=0; i<n; i++){
    for(int j=0; j<3; j++){
      for(int k=0; k<3; k++){
	if(j == k) continue;
	dp[i+1][k] = max(dp[i+1][k], dp[i][j]+happiness[i][k]);
      }
    }
  }

  printf("%d\n", max(max(dp[n][0], dp[n][1]), dp[n][2]));
  return 0;
}
    
   


Measured memory_bytes: 2560
//chiragjn
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define gibe_de_fast_io_b0ss ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF/2;
ll arr[3001];
ll csum[3001] = {0};
ll cache[3001][3001];

ll recur(int i, int j) {
	if(cache[i][j] != -1) {
		return cache[i][j];
	}
	if(i == j) {
		cache[i][j] = arr[i];
	}
	else {
		cache[i][j] = max(arr[i] + (csum[j] - csum[i]) - recur(i + 1, j),
		                  arr[j] + (csum[j - 1] - csum[i - 1]) - recur(i, j - 1));
	}
	// cout<<i<<" "<<j<<" "<<cache[i][j]<<endl;
	return cache[i][j];
}

int main(){
    gibe_de_fast_io_b0ss;
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++) {
    	cin>>arr[i];
    	csum[i] = csum[i - 1] + arr[i];
    }
    for(int i = 0; i <= n; i++) {
    	for(int j = 0; j <= n; j++) {
    		cache[i][j] = -1;
    	}
    }
    ll first = recur(1, n);
    ll second = csum[n] - first;
    cout<<first - second;
    return 0;
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int a[maxn],vis[maxn],n;
ll sum=0;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<n;i++)
        sum+=abs(a[i]-a[i-1]);
    sum+=abs(a[0])+abs(a[n-1]);
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            ll ans=sum;
            ans-=abs(a[0])+abs(a[0]-a[1]);
            ans+=abs(a[1]);
            printf("%lld\n",ans);
        }
        else if(i==n-1)
        {
            ll ans=sum;
            ans-=abs(a[n-1])+abs(a[n-1]-a[n-2]);
            ans+=abs(a[n-2]);
            printf("%lld\n",ans);
        }
        else
        {
            ll ans=sum;
            ans-=abs(a[i]-a[i-1])+abs(a[i+1]-a[i]);
            ans+=abs(a[i+1]-a[i-1]);
            printf("%lld\n",ans);
        }
    }
}

Measured memory_bytes: 1664
import copy
N = int(input())
S = list(input())
S_ans = copy.deepcopy(S)
app = 0
q = [0]
save = 0
for i in range(N):
    if S[i] == '(':
        q.append(q[-1] + 1)
        
    else:
        q.append(q[-1] - 1)
        if q[-1] == -1:
            S_ans.insert(app + save,"(")
            app += 1
            q[-1] = 0

for i in range(q[-1]):
    S_ans.append(")")
print("".join(S_ans))

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

int main() {
  int n,k,r,s,p;
  int64_t ans=0;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  vector<bool> flg(n,false);
  for(int i=0;i<n;i++){
    if (i>=k && t[i] == t[i-k] && flg[i-k]){
      flg[i] = false;
      continue;
    }
    if (t[i] == 'r') ans += p;
    if (t[i] == 's') ans += r;
    if (t[i] == 'p') ans += s;
    flg[i] = true;
  }
  cout << ans << endl;
}


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

int main() {
  int n;
  cin>>n;
  ll ans=0;
  rep(i,1,10){
    int now=0;
    if(n>=i) now++;
    if(n>=i*11) now++;
    if(n>=i*101) {
      now+=min((n-i*101)/10+1,10);
    }
    if(n>=i*1001){
      now+=min((n-i*1001)/10+1,100);
    }
    if(n>=i*10001){
      now+=min((n-i*10001)/10+1,1000);
    }
    if(n>=i*100001){
      now+=min((n-i*100001)/10+1,10000);
    }
    ans+=now*now;
  }
  
  rep(i,1,9){
    rep(j,i+1,10){
      int cura=0;
      if(n>=j*10+i) cura++;
      if(n>=j*100+i) {
        cura+=min((n-j*100-i)/10+1,10);
      }
      if(n>=j*1000+i){
        cura+=min((n-j*1000-i)/10+1,100);
      }
      if(n>=j*10000+i){
        cura+=min((n-j*10000-i)/10+1,1000);
      }
      int curb=0;
      if(n>=i*10+j) curb++;
      if(n>=i*100+j) {
        curb+=min((n-i*100-j)/10+1,10);
      }
      if(n>=i*1000+j){
        curb+=min((n-i*1000-j)/10+1,100);
      }
      if(n>=i*10000+j){
        curb+=min((n-i*10000-j)/10+1,1000);
      }
      if(n>=i*100000+j){
        curb+=min((n-i*100000-j)/10+1,10000);
      }
      ans+=cura*curb*2;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String N = sc.next();
		int sum = 0;

		for(int i = 0; i < N.length(); i++) {
			sum = sum + Integer.parseInt(N.substring(i, i+1));
		}

		if((Integer.parseInt(N) % sum) == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
from itertools import permutations

N = int(input())
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())

perm = list(permutations(range(1, N + 1), N))
i = 0
a = 0; b = 0;
for i in range(len(perm)):
    if a > 0 and b > 0: break
    if perm[i] == P:  a = i + 1
    if perm[i] == Q:  b = i + 1

print(abs(b - a))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std; 
int main(){
  int N, L;  
  cin >> N >> L;  
  vector<string> v;  
  string s;  
  for(int i = 0; i < N; i++){
    cin >> s;  
    v.push_back(s); 
  }
  for(int i = 0; i < N-1; i++){
    for(int j = 0; j < N-i-1; j++)
      if(v[j+1] < v[j]){
        s = v[j];
        v[j] = v[j+1]; 
        v[j+1] = s;  
      }   
  }
  for(int i = 0; i < N; i++)
    cout << v[i]; 
  return 0;  
}


Measured memory_bytes: 256
n=int(input())
spots=[int(i) for i in input().split()]
spots=[0]+spots+[0]

total=0
for i in range(n+1):
    total+=abs(spots[i]-spots[i+1])

for i in range(1,n+1):
    if spots[i-1]<spots[i] and spots[i+1]<spots[i]:
        diff=min(abs(spots[i-1]-spots[i]),abs(spots[i+1]-spots[i]))
        print(total-abs(diff)*2)
    elif spots[i]<spots[i-1] and spots[i]<spots[i+1]:
        diff=min(abs(spots[i-1]-spots[i]),abs(spots[i+1]-spots[i]))
        print(total-abs(diff)*2)
    else:
        print(total)

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

int main() {
    int N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    vector<int> l(Q);
    vector<int> r(Q);
    for (int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
    }

    vector<int> dp(N, 0);
    for (int i = 0; i < N - 1; i++) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            if (i == 0) {
                dp[i] = 1;
            } else {
                dp[i] = dp[i - 1] + 1;
            }
        } else {
            if (i == 0) {
                dp[i] = 0;
            } else {
                dp[i] = dp[i - 1];
            }
        }
    }
    dp[N - 1] = dp[N - 2];

    for (int i = 0; i < Q; i++) {
        int count = 0;
        count = dp[r[i] - 1];
        // cout << dp[r[i] - 1] << " " << dp[l[i] - 2] << endl;
        if (r[i] != N) {
            if (S[r[i] - 1] == 'A' && S[r[i]] == 'C') {
                count--;
            }
        }
        // if (l[i] != 1) {
        //     if (S[l[i] - 1] == 'A' && S[l[i]] == 'C') {
        //         count--;
        //     }
        // }
        count -= dp[l[i] - 2];
        cout << count << endl;
    }

    return 0;
}


Measured memory_bytes: 4540
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
template <class Key, class Compare = less<Key>>
using Tree = __gnu_pbds::tree<Key, __gnu_pbds::null_type, Compare, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;



const ll mod = 1e9 + 7;

int R, C;
bool a[1001][1001];
ll dp[1001][1001];

ll dfs(int r, int c) {
  ll& res = dp[r][c];
  if (res != -1) {
    return res;
  }
  res = 0;
  if (r+1 == R && c+1 == C) {
    res = 1;
  }
  if (r+1 < R && a[r+1][c] == 0) {
    res += dfs(r+1, c);
  }
  if (c+1 < C && a[r][c+1] == 0) {
    res += dfs(r, c+1);
  }
  res %= mod;
  return res;
}

void Main() {
  cin >> R >> C;
  for (int r = 0; r < R; ++r) {
    for (int c = 0; c < C; ++c) {
      char ch;
      cin >> ch;
      a[r][c] = ch == '#';
    }
  }
  memset(dp, -1, sizeof(dp));
  ll ans = dfs(0, 0);
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
//  cin.tie(nullptr);
  #ifdef _DEBUG
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  #endif
  Main();
  return 0;
}


Measured memory_bytes: 9216
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = sc.nextInt();

        long count = 0;
        Map<String, Integer> map = new HashMap<String, Integer>(N);
        for (int i = 0; i < N; i++) {
            char[] s = sc.next().toCharArray();
            Arrays.sort(s);
            String S = String.valueOf(s);
            if (map.containsKey(S)) {
                Integer temp = map.get(S);
                count += temp.intValue();
                map.put(S, temp.intValue() + 1);
            } else {
                map.put(S, 1);
            }
        }
        sc.close();

        out.printf("%d\n", count);
        out.flush();
    }
}


Measured memory_bytes: 54240
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef pair<int, int> P1;
typedef pair<int, pair<int, int> > P2;
static const int INF = 1ll<<60;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };
static const int mod = 1000000007;

int N,K;
vector<int> node[100005];
int P[100005];
bool isPossible;
priority_queue< P1,vector<P1>,greater<P1> > pq;

void solve(){
    isPossible = true;
    while(!pq.empty()){
        int v = pq.top().second;
        pq.pop();
        //cout<<v<<endl;
        for(auto u : node[v]){
            //cout<<u<<endl;
            if(P[u]!=-1){
                if(abs(P[u]-P[v])!=1){
                    isPossible = false;
                    return ;
                }
            }
            else {
                P[u] = P[v]+1;
                pq.push(P1(P[u],u));
            }
        }
    }
}

signed main(){
    memset(P,-1,sizeof(P));
    cin>>N;
    for(int i=0;i<N-1;++i){
        int a,b;
        cin>>a>>b;
        a--,b--;
        node[a].PB(b);
        node[b].PB(a);
    }
    cin>>K;
    for(int i=0;i<K;++i){
        int v,p;
        cin>>v>>p;
        v--;
        P[v] = p;
        pq.push(P1(p,v));
    }
    solve();
    if(!isPossible){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    for(int i=0;i<N;++i)cout<<P[i]<<endl;
}


Measured memory_bytes: 9460
#include<iostream>

using namespace std;

int D,G;
int p[10];
int c[10];
pair<int,int> m[10];
int ans=1e8;
/*
void func(int sum,int res,int Index){
    if(sum>=G){
        ans=min(res,ans);
        return;
    }
    if(Index==D||res>=ans)return ;
    for(int i=0;i<=p[Index];i++){
        int temp =0;
        if(p[Index]==i)temp=c[Index];
        func((Index+1)*100*i+temp+sum,res+i,Index+1);
    }
    return ;
}*/

void func(int sum,int res,int index,long flag){
    if(sum>=G){
        ans=min(ans,res);
        return ;
    }
    if(index==D){
        int fi=D-1;
        while(G>sum&&res<=ans){
            if(!(flag&(1<<fi))){
                for(int j=0;j<p[fi];j++){
                    sum+=(fi+1)*100;
                    res++;
                    if(sum>=G)break;
                }
                flag^=(1<<(fi));
            }
            fi--;
        }
        ans=min(ans,res);
        return ;
    }
    flag^=(1<<index);
    func(m[index].first+sum,m[index].second+res,index+1,flag);
    flag^=(1<<index);
    func(sum,res,index+1,flag);
    return ;
    
}


int main(){
    cin>>D>>G;
    for(int i=0;i<D;i++){
        cin>>p[i]>>c[i];
        m[i].first=p[i]*(i+1)*100+c[i];
        m[i].second=p[i];
    }
    
    func(0,0,0,0);
    
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=2020;
pii a[N];
int dp[N][N];
int32_t main(){
    int n;
    cin>>n;
    forn(i,n){
        cin>>a[i].f;a[i].s=i;
    }
    sort(a,a+n);
    reverse(a,a+n);
    for(int sum=1;sum<=n;++sum){
        int i=sum-1;
        int val=a[i].f,pos=a[i].s;
        for(int l=0;l<=sum;++l){
            int r=sum-l;
            int posl=l-1,posr=n-r;
            if(l)upx(dp[l][r],dp[l-1][r]+val*abs(pos-posl));
            if(r)upx(dp[l][r],dp[l][r-1]+val*abs(pos-posr));
        }
    }
    int ans=0;
    forn(i,n+1)upx(ans,dp[i][n-i]);
    cout<<ans<<'\n';


    return 0;
}


Measured memory_bytes: 26348
def main():
    import itertools
    n,m,q = map(int,input().split())
    Q = []
    for i in range(q):
        Q.append(list(map(int,input().split())))
    cmb = [i for i in range(1,m+1)]
    ans = 0
    for que in itertools.combinations_with_replacement(cmb,n):
        m = 0
        for i in range(q):
            [a,b,c,d] = Q[i]
            if que[b-1]-que[a-1]==c:
                m += d
        if m>ans:
            ans = m
    print(ans)

if __name__ == "__main__":
    main()


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

using namespace std;

int main()
{
	int R;
	cin >> R;
	if (R < 1200)
		cout << "ABC";
	else if (R >= 1200 && R < 2800)
		cout << "ARC";
	else
		cout << "AGC";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define INF 2000000000
using namespace std;
void Max_Heap(vector<long int> &max_heap,int i){
    long int l = i * 2;
    long int r = i * 2 + 1;
    long int largest;
    if(l<max_heap.size() && max_heap[i]<max_heap[l]){
        largest = l;
    }else{
        largest = i;
    }
    if(r<max_heap.size() && max_heap[largest]<max_heap[r]){
        largest = r;
    }
    if(largest != i){
        swap(max_heap[i],max_heap[largest]);
        Max_Heap(max_heap,largest);
    }
}
void increaceKey(int i,int key,vector<long int> &S){
    if(key < S[i]){
        return ;
    }
    //cout << key << endl;
    S[i] = key;
    while(i>1 && S[i/2] < S[i]){
        swap(S[i],S[i/2]);
        i = i / 2 ; 
    }
    //cout << S[i] << ' ' << S[i-1] << endl;
}
void insert(int key,vector<long int> &S){
    S.push_back(INF*-1);
    increaceKey(S.size()-1,key,S);
}
long int extract(vector<long int> &S){
    long int maxv;
    if(S.size()<1){
        return INF * -1;
    }
    maxv = S[1];
    S[1] = S[S.size()-1];
    S.pop_back();
    Max_Heap(S,1);
    return maxv;
}
int main(void){
    vector<long int> S;
    vector<long int> &rS = S;
    S.push_back(0);
    while(true){
        string command;
        cin >> command;
        if(command=="insert"){
            long int key;
            cin >> key;
            insert(key,rS);
        }else if(command=="extract"){
            cout << extract(rS) << endl;
        }else{
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 11284
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

const int maxn = 1e5+5;

vector<int> adj[maxn];

int dp[maxn];

int n, m;

int solve(int u)
{
	if(dp[u] != -1) return dp[u];
	int best = 0;
	for(int v : adj[u])
	{
		best = max(best, 1+solve(v));
	}
	return dp[u] = best;
}
int main()
{
	memset(dp, -1, sizeof dp);
	scanf("%d %d", &n, &m);
	for(int i = 1; i<= m; i++)
	{
		int x, y; scanf("%d %d", &x, &y);
		adj[x].pb(y);
	}
	int best = 0;
	for(int i = 1; i<= n; i++) best = max(best, solve(i));
	printf("%d\n", best);
}

Measured memory_bytes: 8192