akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), cb(n + 1);
  vector<bool> taken(n);
  vector<vector<int>> ca(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ca[a[i]].emplace_back(i);
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    cb[b[i]]++;
  }
  priority_queue<pair<int, int>> pq;
  for (int i = 1; i <= n; ++i) {
    int lo = min((int)ca[i].size(), cb[i]);
    if (lo)
      pq.emplace(lo, i);
  }
  while (pq.size() >= 2) {
    auto [cx, x] = pq.top();
    pq.pop();
    auto [cy, y] = pq.top();
    pq.pop();
    if (cx == 1 && pq.size() == 1) {
      auto [cz, z] = pq.top();
      pq.pop();
      int px = ca[x].back();
      int py = ca[y].back();
      int pz = ca[z].back();
      taken[px] = taken[py] = taken[pz] = true;
      b[px] = y;
      b[py] = z;
      b[pz] = x;
      ca[x].pop_back();
      ca[y].pop_back();
      ca[z].pop_back();
      cb[x]--;
      cb[y]--;
      cb[z]--;
    } else {
      int px = ca[x].back();
      int py = ca[y].back();
      taken[px] = taken[py] = true;
      b[px] = y;
      b[py] = x;
      ca[x].pop_back();
      ca[y].pop_back();
      cb[x]--;
      cb[y]--;
      if (cx > 1)
        pq.emplace(cx - 1, x);
      if (cy > 1)
        pq.emplace(cy - 1, y);
    }
  }
  int idx = 0;
  if (!pq.empty()) {
    auto [cx, x] = pq.top();
    pq.pop();
    while (cb[x]) {
      while (idx < n && (taken[idx] || a[idx] == x))
        idx++;
      if (idx >= n)
        break;
      b[idx] = x;
      cb[x]--;
      taken[idx] = true;
    }
    if (cb[x]) {
      cout << "No" << flush;
      return 0;
    }
  }
  vector<int> rest;
  for (int i = 1; i <= n; ++i)
    if (cb[i]) {
      for (int j = 0; j < cb[i]; ++j)
        rest.emplace_back(i);
    }
  idx = 0;
  for (int i : rest) {
    while (taken[idx])
      idx++;
    b[idx] = i;
    taken[idx] = true;
  }
  cout << "Yes" << endl;
  for (int i : b)
    cout << i << " ";
  cout << flush;
}

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
const int N = 2e5 + 1;
const int lg = 20;
const ll mod = 0xfffff;

void solve() {
  ll n;
  scanf("%lld", &n);

  ll ans = 1, x = 2;
  if (n > 2) ans++;
  while (x * x <= n) {
    if (n % x == 1) {
      ll y = (n - 1) / x;
      ans += x == y ? 1 : 2;
    }
    if (n % x == 0) {
      ll y = n / x, m = n;
      if (x != y) {
        while (m % y == 0)
          m /= y;
        if (m % y == 1)
          ans++;
      }
      m = n;
      while (m % x == 0)
        m /= x;
      if (m % x == 1)
        ans++;
    }
    x++;
  }

  printf("%lld\n", ans);
}

int main() {
  // int _; scanf("%d", &_) while (_--)
  solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<bool,vector<ll>> VP;
vector<P> node[55];
vector<ll> use_edge[55];
bool used[55];
VP dfs(ll pos,ll goal){
  used[pos]=true;
  vector<ll> res;
  if(pos==goal) return VP(true,res);
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i].first,idx=node[pos][i].second;
    if(used[to]) continue;
    used[to]=true;
    VP vp=dfs(to,goal);
    if(vp.first){
      vp.second.push_back(idx);
      return vp;
    }
  }
  return VP(false,res);
}
int main(){
  ll n;
  cin>>n;
  for(int i=1;i<n;i++){
    ll s,t;
    cin>>s>>t;
    node[s].push_back(P(t,i));
    node[t].push_back(P(s,i));
  }
  ll m;
  cin>>m;
  for(int i=0;i<m;i++){
    ll s,t;
    cin>>s>>t;
    for(int j=1;j<=n;j++) used[j]=false;
    use_edge[i]=dfs(s,t).second;
  }
  ll ans=0;
  for(int b=0;b<(1<<m);b++){
    int cnt=0;
    bool check[55];
    for(int i=0;i<55;i++) check[i]=false;
    for(int i=0;i<m;i++){
      if(((b>>i)&1)==1){
        cnt++;
        for(int j=0;j<use_edge[i].size();j++) check[use_edge[i][j]]=true;
      }
    }
    ll cn2=0;
    for(int i=0;i<55;i++) if(check[i]) cn2++;
    ll kans=(ll)1<<(n-1-cn2);
    if(cnt%2==0) ans+=kans;
    else ans-=kans;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

N, M = map(int, input().split())
uf = UnionFind(N)

ABlist = [list(map(int, input().split())) for _ in range(M)]
ans = [0] * M
for i in reversed(range(M)):
    A, B = ABlist[i]
    if not uf.same(A-1, B-1):
        ans[i] = uf.size(A-1)*uf.size(B-1)
        uf.union(A-1, B-1)
num = 0
for a in ans:
    num += a
    print(num)


Measured memory_bytes: 33364
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

map<int, int> M;

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

	int ok = 1;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		M[a]--;
		if (M[a] < 0) ok = 0;
	}
	if (ok) printf("YES\n");
	else printf("NO\n");
	return 0;
}


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

using namespace std;

using int64 = long long;

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

  int h, w, n;
  cin >> h >> w >> n;
  int sr, sc;
  cin >> sr >> sc;
  sr--;
  sc--;
  string s, t;
  cin >> s >> t;

  // [xl, xu) is the live x region.
  int xl = 0;
  int xu = w;
  int yl = 0;
  int yu = h;
  for (int i = n - 1; i >= 0; i--) {
    // Aoki
    if (t[i] == 'L') {
      if (xl < xu) {
        if (xu < w) xu++;
      }
    } else if (t[i] == 'R') {
      if (xl < xu) {
        if (xl > 0) xl--;
      }
    } else if (t[i] == 'U') {
      if (yl < yu) {
        if (yu < h) yu++;
      }
    } else if (t[i] == 'D') {
      if (yl < yu) {
        if (yl > 0) yl--;
      }
    }

    // Takahashi
    if (s[i] == 'L') {
      if (xl < xu) {
        if (xl < w) xl++;
      }
    } else if (s[i] == 'R') {
      if (xl < xu) {
        if (xu > 0) xu--;
      }
    } else if (s[i] == 'U') {
      if (yl < yu) {
        if (yl < h) yl++;
      }
    } else if (s[i] == 'D') {
      if (yl < yu) {
        if (yu > 0) yu--;
      }
    }
  }

  if (yl <= sr && sr < yu && xl <= sc && sc < xu) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 920
#include <iostream>
using namespace std;
int n,d,p[10][10],ans;

void saiki(int sum,int x,int day,int I){
  int f=1;
  for(int i=I;i<n;i++)
    if(p[day][i]/p[day-1][i]&&x/p[day-1][i]) {
      f=0;
      saiki(sum+p[day][i],x-p[day-1][i],day,i);
    }
  if(f)ans=max(ans,sum+x);
}

int main(){
  cin>>n>>d>>ans;
  for(int i=0;i<d;i++)
    for(int j=0;j<n;j++)cin>>p[i][j];

  for(int i=0;i<d-1;i++)saiki(0,ans,i+1,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1164
import scala.io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(a, b, k) = in.readLine.split(" ").map(_.toInt)

  val f = (a to b).take(k).toArray
  val l = (a to b).takeRight(k).toArray
  val ans = (f ++: l).distinct
  ans.foreach(out.println)
  out.flush
}

Measured memory_bytes: 27160
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(){
  int N, X, Y;
  cin >> N >> X >> Y;
  Graph G(N);
  for(int i=0; i<N-1; ++i){
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  if(X+1!=Y){
    G[X-1].push_back(Y-1);
    G[Y-1].push_back(X-1);
  }
  vector<int> min_dist(N-1,0);
  for(int i=0; i<N-1; ++i){
    vector<int> dist(N, -1);
    queue<int> que;
    dist[i] = 0;
    que.push(i);
    while(!que.empty()){
      int v = que.front();
      que.pop();
      for(int nv : G[v]){
        if(dist[nv] != -1) continue;
        dist[nv] = dist[v] + 1;
        que.push(nv);
      }
    }
    for(int j=i+1; j<N; ++j){
      if(dist.at(j)>0) ++min_dist.at(dist.at(j)-1);
    }
  }
  for(int i=0; i<N-1; ++i) cout << min_dist.at(i) << endl;
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
    
    static final int MOD = (int)1e9+7;
    
    static int n;
    static ArrayList<Integer>[] g;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        n = Integer.parseInt(sc.next());
        g = new ArrayList[n];
        for(int i=0; i<n; i++){
            g[i] = new ArrayList<>();
        }
        
        for(int i=0; i<n-1; i++){
            int a = Integer.parseInt(sc.next())-1;
            int b = Integer.parseInt(sc.next())-1;
            g[a].add(b);
            g[b].add(a);
        }
        
        ArrayDeque<Integer> q = new ArrayDeque<>();
        q.addLast(0);
        int[] color = new int[n];
        Arrays.fill(color, -1);
        color[0] = 0;
        while(q.size()!=0){
            int now = q.removeLast();
            for(int next : g[now]){
                if(color[next] == -1){
                    q.addLast(next);
                    color[next] = color[now]^1;
                }
            }
        }
        
        int[] cnt = new int[2];
        for(int i=0; i<n; i++){
            cnt[color[i]]++;
        }
        
        int[] ans = new int[n];
        int[] used = new int[3];
        if(cnt[0]<=n/3 || cnt[1]<=n/3){
            for(int i=0; i<n; i++){
                if(color[i] == (cnt[0]<cnt[1] ? 0:1)){
                    ans[i] = (used[2]+1)*3;
                    used[2]++;
                }else{
                    for(int j=0; j<3; j++){
                        if(used[j]*3+j+1<=n){
                            ans[i] = used[j]*3+j+1;
                            used[j]++;
                            break;
                        }
                    }
                }
            }
        }else{
            for(int i=0; i<n; i++){
                if(used[color[i]]*3+color[i]+1<=n){
                    ans[i] = used[color[i]]*3+color[i]+1;
                    used[color[i]]++;
                }else{
                    ans[i] = (used[2]+1)*3;
                    used[2]++;
                }
            }
        }
        
        StringJoiner sj = new StringJoiner(" ");
        for(int i=0; i<n; i++){
            sj.add("" + ans[i]);
        }
        
        System.out.println(sj.toString());
    }
}


Measured memory_bytes: 117236
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX =2e5+6;
const long long inf=1e18;
vector<int>adj[MAX];
int arr[MAX];
int vis[MAX];
void dfs(int a){
	vis[a]=1;
	for(int i=0;i<adj[a].size();i++){
		if(!vis[adj[a][i]]){
			arr[adj[a][i]]+=arr[a];
			dfs(adj[a][i]);
		}
	}
}
int main(){
	int n , m;
	cin>>n>>m;
	for(int i=0;i<n-1;i++){
		int x, y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for(int i=0;i<m;i++){
		int a, b;
		cin>>a>>b;
		arr[a]+=b;
	}
	dfs(1);
	for(int i=1;i<=n;i++)
		cout<<arr[i]<<" ";

}

Measured memory_bytes: 24320
import java.util.Scanner;

public class Main {
  static final long INF = Long.MAX_VALUE / 2;
  static long n, s;

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

    n = sc.nextLong();  s = sc.nextLong();

    long ans = INF;
    if(n == s){
      ans = n + 1;
    }
    for(long b = 2; b * b <= n; b++){
      if(f(b, n) == s){
        ans = b;
        break;
      }
    }
    if(ans == INF){
      for(long p = 1; p * p <= n; p++){
        long b = (n - s) / p + 1;
        if(b < 2){
          continue;
        }
        if(f(b, n) == s){
          ans = Math.min(ans, b);
        }
      }
    }

    if(ans == INF){
      System.out.println(-1);
    }
    else{
      System.out.println(ans);
    }
  }

  private static long f(long b, long n){
    if(n < b){
      return n;
    }
    return f(b, n / b) + (n % b);
  }
}


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

using namespace std;

int main(){
	int A, B, K, count = 0, ans;
	cin >> A >> B >> K;
	
	for(int i = A; i >= 1; i--){
		if(A % i == 0 && B % i == 0){
			count++;
		}
		if(count == K){
			ans = i;
			break;
		}
	}
	
	cout << ans << endl;
	
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int main(){
   int n;
   cin >> n;
   vector<int> p;
   for(int i=0; i < n; i++){
      int p_tmp;
      cin >> p_tmp;
      p.push_back(p_tmp);
   }
   sort(p.begin(), p.end());
   int p_max = p.back();

   int p_sum = 0;
   for(int i = 0; i < (int)p.size() -1; i++){
      p_sum += p[i];
   }
   p_sum += p_max/2;
   cout << p_sum << endl;

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int n;
	cin >> n;
	ll ans = 0;
	ll tmp;
	for(int i=0; i<n; i++){
		cin >> tmp;
		while(tmp%2==0){
			ans++;
			tmp /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

unsigned next_combination(unsigned sub) {
    unsigned x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

struct city {
    int x;
    int y;
    ll p;
};

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<city> c(n);
    for (auto &e : c) cin >> e.x >> e.y >> e.p;
    ll ans_prev = (ll)1e18;
    rep (k, n + 1) {
        eprintf("k:%d\n", k);
        ll ans = ans_prev;
        bool ok = false;
        unsigned bit = (1 << k) - 1;
        if (k > 0) {
            for (; bit < (1 << n); bit = next_combination(bit)) {
                rep (dir, (1 << k)) {
                    vector<P> l;
                    int tmp = 0;
                    ll ans_tmp = 0;
                    rep (i, n) {
                        if (bit & (1 << i)) l.emplace_back(c[i].x, c[i].y);
                    }
                    rep (i, n) {
                        ll x = c[i].x, y = c[i].y;
                        if (bit & (1 << i)) continue;
                        ll dist = min(abs(x), abs(y));
                        rep (j, k) {
                            chmin(dist, ((dir & (1 << j)) 
                            ? abs(x - l[j].first) 
                            : abs(y - l[j].second)));
                        }
                        ans_tmp += c[i].p * dist;
                        if (ans_tmp >= ans) break;
                    }
                    chmin(ans, ans_tmp);
                }
            }
        } else {
            ans = 0;
            rep (i, n) {
                ans += c[i].p * min(abs(c[i].x), abs(c[i].y));
            }
        }
        cout << ans << "\n";
        ans_prev = ans;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){

    string s1, s2, s3;

    cin >> s1 >> s2 >> s3;

    char c1 = toupper(s1[0]);
    char c2 = toupper(s2[0]);
    char c3 = toupper(s3[0]);


    cout << c1 << c2 << c3 << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int h,a;
  float num=0,num2=0,num3=0;
  cin>>h>>a;
  if(h%a==0)cout<<h/a;
  else{
    num2=h;
    num3=a;
    cout<<ceil(num2/num3);
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<vector<ll>> F(N,vector<ll>(10));
    for(auto& vec:F) for(auto& in:vec) cin >> in;
    
    vector<vector<ll>> P(N,vector<ll>(11));
    for(auto& vec:P) for(auto& in:vec) cin >> in;
    res = -LINF;
    for(int i = 1; i < (1<<10);i++){
        ll T = 0;
        vector<ll> C(N);
        for(int j = 0; j < 10;j++){
            if(!((i>>j)&1)) continue;
            for(int k = 0; k < N;k++){
                if(F[k][j]) C[k]++;
            }
        }
        for(int j = 0; j < N;j++){
            T += P[j][C[j]];
        }
        res= max(res,T);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  long long int a,b,n,x,y,s=0;
  cin>>a>>b>>n;
  x=b-1;
  if(b>n)
    x=n;
  y=a*x;
  y/=b;
  cout<<y<<endl;
}

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

long long int N, a[55], b[55], A;
vector<long long int> ans;

int con(int n){
    for(int loop = 0; loop < N; ++loop){
        int s[55];
        fill(s, s + 55, 0);
        s[a[loop]] = 1;
        for(auto i : ans){
            for(int j = 0; j < 55; ++j){
                s[j % i] |= s[j];
            }
        }
        for(int i = n; i; --i){
            for(int j = 0; j < 55; ++j){
                s[j % i] |= s[j];
            }
        }
        if(!s[b[loop]])return false;
    }
    return true;
}

int main(){
    scanf("%lld", &N);
    for(int i = 0; i < N; ++i)scanf("%lld", a + i);
    for(int i = 0; i < N; ++i){
        scanf("%lld", b + i);
    }
    for(int i = 55; i >= 0; --i){
        if(!con(i))ans.push_back(i + 1);
    }
    for(auto i : ans){
        A += 1LL << i;
    }
    cout << (A > (1LL << 51) ? -1 : A) << endl;
}

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

int main() {
  string N;
  cin >> N;
  
  if (N.at(0) == N.at(1) && N.at(1) == N.at(2)) cout << "Yes" <<endl;
  else if (N.at(1) == N.at(2) && N.at(2) == N.at(3)) cout << "Yes" <<endl;
  else cout << "No" << endl;
 }

Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())
cnt = sum([1 for i in range(N) if A[i] < 0])
if cnt % 2 == 0:
    print(sum([abs(a) for a in A]))
else:
    A.sort(key=abs)
    print(sum([abs(a) for a in A[1:]]) - abs(A[0]))

Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
typedef long long ll;
 
ll dp[1 << 21];
ll n;
ll a[23][23];
ll bitcnt[1<<21];
 
int main(){
    cin >> n;
    for(int i = 0;i < n;i++)
        for(int j = 0;j < n;j++)
            cin >> a[i][j];
 
    dp[0] = 1;
    for(int s = 1;s < (1<<n);s++){
        bitcnt[s] = bitcnt[s/2] + s%2;
        for(int l = 0;l < n;l++){
            if((s >> l) % 2 == 0)continue;
            dp[s] += dp[s - (1 << l)] * a[bitcnt[s] - 1][l];
            dp[s] %= MOD;
        }
    }
    cout << dp[(1 << n) - 1] << endl;    
    return 0;
}

Measured memory_bytes: 36300
def check(A):
    """ check bingo or not
    :param A: 3*3 matrix, 1 or 0
    :return: is_bingo bool
    """
    for row_id in range(3):
        if sum(A[row_id])==3:
            return True
    
    for column_id in range(3):
        column_sum = 0
        for row_id in range(3):
            column_sum += A[row_id][column_id]
        if column_sum == 3:
            return True

    lr_sum = 0
    rl_sum = 0
    for rc_id in range(3):
        lr_sum += A[rc_id][rc_id]
        rl_sum += A[rc_id][2-rc_id]
    if lr_sum == 3 or rl_sum == 3:
        return True
        
    return False


def search(query, A):
    for row_id in range(3):
        for column_id in range(3):
            if query == A[row_id][column_id]:
                return column_id, row_id 
    return None, None


if __name__ == '__main__':
    A = [list(map(int, input().split())) for _ in range(3)]
    B = [[0, 0, 0] for _ in range(3)]

    N = int(input())

    for _ in range(N):
        query = int(input())
        i, j = search(query, A)
        if i != None and j != None:
            B[i][j] = 1

    if check(B):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 9232
m=int(input())
n=int(input())
car_list=[n]
c=n
for i in range(m):
    a,b=map(int,input().split())
    c+=a-b
    car_list.append(c)

if min(car_list)<0:
    print(0)
else:
    print(max(car_list))


Measured memory_bytes: 5912
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    sort(s.begin(), s.end());
    rep(i, n) cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int L, R;
    cin >> L >> R;
    int d;
    cin >> d;
    int ans=0;
    for(int i=L; i<=R; i++){
        if(i%d==0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
from sys import stdin
import numpy as np
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)
N = int(stdin.readline().rstrip().split()[0])

MOD = 10**9 + 7


def f(_arr,a, n, num):
  arr = _arr+[a]
  if n == N:
    #print(arr)
    def print_abc(array):
      abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
      pr = []
      for a in array:
        pr.append(abc[a])
      print("".join(pr))
    print_abc(arr)
    return 0
  for i in range(num+1):
    if i==num:
      f(arr,i,n+1,num+1)
    else:
      f(arr,i,n+1,num)
  
f([], 0, 1, 1)

Measured memory_bytes: 15524
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
s = [input() for _ in range(n)]
s.sort()

ans = 1
for i in range(1,n):
    if s[i] != s[i-1]:
        ans += 1

print(ans)


Measured memory_bytes: 45876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e6+5;
int n,x,y,cir;
ll cnt[N],tmp[N];
void solve(int len){
	rep(i , 1 , n + 1)tmp[i] = 0;
	rep(i , 1 , len + 1)
		cnt[i] += len - i + 1;
	rep(i , 2 , cir + 1){
		int mn = min(i - 1,cir - i + 1 );
		tmp[mn + 1]++;
		tmp[mn + len + 1]--;
	}
	rep(i , 1 , n + 1)tmp[i] += tmp[i-1];
	rep(i , 1 , n + 1)cnt[i] += tmp[i];
}
int main()
{
	cin>>n>>x>>y;
	cir = y - x + 1;
	solve(x - 1);
	solve(n - y);
	
	int la = n - y + 1;
	rep(i , 1 , n + 1)tmp[i] = 0;
	rep(i , 1 , x){
		tmp[x - i + 2]++;
		tmp[la + x - i + 1]--;
	}
	rep(i , 1 , n + 1)tmp[i] += tmp[i-1];
	rep(i ,1 , n + 1)cnt[i] += tmp[i];
	rep(i , 1 , cir/2 + 1)
		cnt[i] += cir;
	if(cir%2== 0)cnt[cir/2] -= cir/2;
	rep(i , 1 , n)
		cout<<cnt[i]<<"\n";
	
	return 0;
}



Measured memory_bytes: 2304
#include <math.h>
#include <stdlib.h>
#define MIN(a, b) (a<b?a:b)
#define MAX(a, b) (a>b?a:b)


int main()
{
    int n, m;
    int a[10000];
    scanf("%d %d", &n, &m);
    for( int i=0; i<m; i++ )
    {
        scanf("%d", a+i);
        n -= a[i];
    }
    printf("%d", MAX(-1, n));

    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  int A,B,C; cin >> A>> B >> C;
  if((A == B && B == C) || (A != B && B != C && A != C)){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}


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

long comb(long a)
{
  if (a==2) return 1;
  long k = a;
  long j = a-1;

  return (k * j) / 2;
}
int main()
{
  int N; cin >> N;
  map<string, long> v;
  for (int i=0; i<N; i++) {
    string s; cin >> s;
    sort(s.begin(), s.end());
    v[s]++;
  }

  long max_num = 0;
  for (auto p : v) {
    if (p.second <= 1) continue;
    
    max_num += comb(p.second);
  }
  
  cout << max_num << endl;
}

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

int gcd (int a, int b) {
  if(b == 0) {
    return a;
  } else {
    return (gcd(b, a%b));
  }
}
signed main () {
  cin.tie(0);
  cout << setprecision(10);
  //21:25:30
  int n; cin >> n;
  vector<int> t(n);
  REP(i, n) {
    cin >> t[i];
  }

  int ans = 1;
  REP(i, n) {
    ans *= t[i] / gcd(ans , t[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  string t,p;
  cin >> t >> p;
  rep(i,t.size()){
    if(t.substr(i,p.size()) == p) cout << i << endl;
  }
  return 0;
}


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

//Slim Span
public class Main{

	class E implements Comparable<E>{
		int s, t, w;
		public E(int s, int t, int w) {
			this.s = s;
			this.t = t;
			this.w = w;
		}
		public int compareTo(E o) {
			return w-o.w;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt();
			if((n|m)==0)break;
			E[] e = new E[m];
			for(int i=0;i<m;i++){
				e[i] = new E(sc.nextInt()-1, sc.nextInt()-1, sc.nextInt());
			}
			Arrays.sort(e);
			int res = 1<<29;
			for(int i=0;i<m;i++){
				UnionFind u = new UnionFind(n);
				for(int j=i;j<m;j++){
					if(!u.find(e[j].s, e[j].t))u.union(e[j].s, e[j].t);
					if(u.num==1){
						res = Math.min(res, e[j].w-e[i].w); break;
					}
				}
			}
			System.out.println(res==1<<29?-1:res);
		}
	}
	
	class UnionFind {
		final int[] tree;
		int num;
		public UnionFind(int n) {
			this.tree = new int[n];
			Arrays.fill(tree, -1);
			num=n;
		}
		void union(int x, int y) {
			x = root(x);
			y = root(y);
			if(x != y) {
				if(tree[x] < tree[y]) {
					x ^= y; y ^= x; x^= y;
				}
				tree[x] += tree[y];
				tree[y] = x;
				num--;
			}
		}
		boolean find(int x, int y) {
			return root(x) == root(y);
		}
		int root(int x) {
			return tree[x] < 0 ? x : (tree[x] = root(tree[x]));
		}
		int size(int x) {
			return -tree[root(x)];
		}
		int getNum() {
			return num;
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

namespace ABC123 {
	class ABC123_A {
		static void Main(string[] args) {
			// a-eの入力を配列に格納する - list intの配列にする int[5]で良いか
			// kの入力を受け付ける int
			// 正攻法の場合
			// a-b a-c の順に比較して、最後までたどり着いたら、Yay!と出力する
			// a-b a-c の順に比較して、途中で値を超えたら、:(と出力する
			var AE = new int[5];
			for (int i=0; i<5; i++) {
				AE[i] = int.Parse(Console.ReadLine());
			}
			var k = int.Parse(Console.ReadLine());
			//CombinateAtoE(AE, k);
			CompareMax(AE, k);
		}

		private static void CompareMax(int[] AE, int k) {
			for(int i=1; i<AE.Length; i++) {
				if((AE[i] - AE[0]) > k) {
					Console.WriteLine(":(");
					return;
				}
			}
			Console.WriteLine("Yay!");
		}

		private static void CombinateAtoE(int[] AE, int k) {
			for(int i=0; i<AE.Length; i++) {
				for(int j=i+1; j<AE.Length; j++) {
					if((AE[j] - AE[i]) > k) {
						Console.WriteLine(":(");
						return;
					}
				}
			}
			Console.WriteLine("Yay!");
		}
	}
}


Measured memory_bytes: 13140
s = gets.chomp.chars
k = gets.to_i
d = s.each_index.inject(k) do |m, i|
    r = ('z'.ord - s[i].ord + 1) % 26
    if r <= m
        s[i] = 'a'
        m - r
    else
        m
    end
end
if d > 0
    s[-1] = ('a'.ord + (s[-1].ord - 'a'.ord + d) % 26).chr
end
puts s.join


Measured memory_bytes: 11260
#include<stdio.h>
#define N 500001
typedef struct{
  int k, p, l, r;
} node;
node A[N];

int hs = 0;

void maxheap(int i){
  int le, ri, lar;
  node temp;
  le = 2*i;
  ri = 2*i+1;
  if(le <= hs && A[le].k > A[i].k) lar = le;
  else lar = i;
  if(ri <= hs && A[ri].k > A[lar].k) lar = ri;
  if(lar != i){
    temp = A[i];
    A[i] = A[lar];
    A[lar] = temp;
    maxheap(lar);
  }
}

int main(){
  int i;
  scanf("%d", &hs);
  for(i = 1; i <= hs; i++) scanf("%d", &A[i].k);
  for(i = 1; i <= hs; i++){
    if(i != 1) A[i].p = A[i/2].k;
    if(2*i <= hs) A[i].l = A[2*i].k;
    if(2*i+1 <= hs) A[i].r = A[2*i+1].k;
  }
  for(i = hs/2; i > 0; i--){
    maxheap(i);
  }
  for(i = 1; i <= hs; i++){
    printf(" %d", A[i].k);
  }
  printf("\n");
return 0;
}

Measured memory_bytes: 8408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

ll	n , k;
vector<int> a(1000001),f(1000001);

// 二分探索法
// index が条件を満たすかどうか
bool isOK(ll index) {
	ll  c = 0;
	for(int i=0;i<n;i++) {
		if ((ll)a[i]*f[i] > index) c += a[i] - index / f[i];
	}
	if (c > k) return false;
    else return true;
}
// 汎用的な二分探索のテンプレ
ll binary_search() {
    ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right = 1000000000001; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        ll mid = right + (left - right) / 2;

        if (isOK(mid)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

int main() {
	ll		b,c,d,w,h,i,j,l,m,x,y,z;
	ll		ans = 0;
	string	s;
	cin >> n >> k;
	for(i=0;i<n;i++) cin >> a[i];
	for(i=0;i<n;i++) cin >> f[i];

	auto itra = a.begin();
	auto itrf = f.begin();
	sort(itra , itra + n);
	sort(itrf , itrf + n);
	reverse(itra , itra + n);

	ans = binary_search();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10988
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random

def check(index_person, x_true_or_false, bin_str):
    return (bin_str[index_person] == x_true_or_false)


def main():
    n = int(input().strip())
    ll_xy = [[] for _ in range(n)]
    for i in range(n):
        a = int(input().strip())
        for j in range(a):
            l = list(map(int, input().strip().split()))
            l[0]-=1
            ll_xy[i].append(l)

    cnt=0
    ans=0
    for i in range(2 ** n):     # 場合ループ
        bin_str = list(map(int,(format(i,'b').zfill(n))))
        # eprint("bin_str ",end=": ")
        # eprint(bin_str)
        failure_flag=0
        for j in range(n):      # 人ループ
            if bin_str[j]==1:   # その人を「真実の人」だと仮定している場合
                a=len(ll_xy[j])
                for k in range(a):  # 証言ループ
                    p=ll_xy[j][k][0]
                    if ll_xy[j][k][1] == 0:
                        if check(p,0,bin_str):
                            pass
                        else:
                            failure_flag=1

                    elif ll_xy[j][k][1] == 1:
                        if check(p,1,bin_str):
                            pass
                        else:
                            failure_flag=1
        if failure_flag==0:
            cnt+=1
            ans_temp=0
            for x in bin_str:
                if x==1:
                    ans_temp+=1
            ans=max(ans_temp,ans)
    print(ans)
    return

if __name__ == '__main__':
    main()


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

int main(void)
{
	for (int i = 1; i <= 9; ++i) {
		for (int j = 1; j <= 9; ++j) {
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int H, N, A, sum = 0;
	scanf("%d %d", &H, &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &A);
		sum += A;
	}
	if (sum >= H) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

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();
		sc.close();
		System.out.println((a < c && c < b) || (b < c && c < a) ? "Yes" : "No");
	}
}


Measured memory_bytes: 25300
# D - Grid Repainting

from collections import deque

H, W = map(int, input().split())
maze = []
maze.append(['#'] * (W+2))
for _ in range(H):
    maze.append(['#'] + list(str(input())) + ['#'])
maze.append(['#'] * (W+2))

kuro = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if maze[i][j] == '#':
            kuro += 1

dist = [[0] * (W+2) for _ in range(H+2)]
q = deque()
q.append((1,1))
dist[1][1] = 1
siro = -1
while len(q) > 0:
    y, x = q.popleft()
    if (y, x) == (H, W):
        siro = dist[y][x]
        break
    for vy, vx in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
        ny = y + vy
        nx = x + vx
        if maze[ny][nx] == '.' and dist[ny][nx] == 0:
            dist[ny][nx] = dist[y][x] + 1
            q.append((ny, nx))

if siro == -1:
    print(siro)
else:
    print(H*W - kuro - siro)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    vector<ll> b(n);
    ll sum=0,cnt=0;
    for(int i=0;i<n;i++){
        ll a;cin >> a;
        sum+=abs(a);
        b[i]=abs(a);
        if(a<0){
            cnt++;
        }
    }
    sort(b.begin(),b.end());
    if(cnt%2==0){
        cout << sum << endl;
    }
    else{
        cout << sum-b[0]*2 << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
const long long INF = 1LL << 60;

int main(){
  vector<vector<int> > c(3,vector<int>(3));
  rep(i,3){
    rep(j,3){
      cin >> c[i][j];
    }
  }
  vector<int> r_min(3,10000), c_min(3,10000);
  r_min[0] = 0;
  rep(i,3) c_min[i] = c[0][i] - r_min[0];

  for(int i = 1; i < 3; ++i) r_min[i] = c[i][0] - c_min[0];
  rep(i,3){
    rep(j,3){
      if(r_min[i] + c_min[j] != c[i][j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

// definitions
#define __Imperial_Lord__ ONLINE_JUDGE
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c <<endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d <<endl
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<endl
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<long double> vld;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF=1e18;

template <class ...Args>
istream &read(Args &...args) {return (cin >> ... >> args);}
#define cin(...)   __VA_ARGS__; read(__VA_ARGS__)

// cin and cout overloaded for vectors
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v) 
        is >> i;        
    return is;
}
template<typename T>             
ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v) 
        os << i << ' '; 
        return os;
}

// code beigns in main
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    while(t--)
    {
    	ll cin(a);
    	ll s=a+a*a+a*a*a;
    	p0(s);
    }		
    exec;
}


Measured memory_bytes: 3764
import heapq
class edge:
    def __init__(self,to,cost):
        self.to=to
        self.cost=cost

H,W=map(int,input().split())
G=[list() for i in range(H*W)]
s=[]
for j in range(H):
    s.extend(input())

for i in range(H):
    for j in range(W):
        if(j<W-1 and  s[W*i+j+1]=="."):
            G[W*i+j].append(edge(W*i+j+1,1))
        if(i<H-1 and  s[W*i+j+W]=="."):
            G[W*i+j].append(edge(W*i+j+W,1))
        if(j>0 and  s[W*i+j-1]=="."):
            G[W*i+j].append(edge(W*i+j-1,1))
        if(i>0 and  s[W*i+j-W]=="."):
            G[W*i+j].append(edge(W*i+j-W,1))
            
        
        
    

def dijkstra(o):
    d=[float('inf') for i in range(H*W)]
    d[o]=0
    hq=[]
    prev=[[] for i in range(H*W)]
    heapq.heappush(hq,(0,o))
    while hq:
        p=heapq.heappop(hq)
        v=p[1]
        if(d[v]<p[0]):
            continue
        for i in G[v]:
            if(d[i.to]>d[v]+i.cost):
                d[i.to]=d[v]+i.cost
                prev[i.to]=prev[v]+[str(sorted([v,i.to]))]
                heapq.heappush(hq,(d[i.to],i.to))
    return d,prev


ans=set()
for i in range(1):
    tmp=dijkstra(i)[0]
    if(tmp[H*W-1]==float('inf')):
        print(-1)
    else:
        #-1:start
        print(H*W-s.count('#')-1-tmp[H*W-1])

Measured memory_bytes: 6644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n; cin>>n;
  	ll arr[n]; 
  	map<ll,ll> m;
  for(int i=0;i<n;i++) {
    cin>>arr[i];
  	m[arr[i]]++;
  }
  ll dp[n]={0};
  ll ans=0;
  for(auto it:m){
  	dp[it.first]=(it.second*(it.second-1))/2;
  	ans+=dp[it.first];
  }
 
  	for(int i=0;i<n;i++){
       ll sol=0;
    	sol+=ans-dp[arr[i]];
      ll x=m[arr[i]]-1;
      	sol=sol+((x*(x-1))/2);
    	cout<<sol<<"\n";
    }
}

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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

int main() {

  int n;
  cin>>n;
  VI v(n);
  REP(i,n){
    cin>>v[i];
  }

  long long ans =pow(10,9);
  long long sum;

  FOR(p,1,100){
    sum = 0;
    REP(i,n){
      sum += pow((v[i] - p), 2);
    }
    ans = min(ans, sum);
  }

  ANS(ans);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
//.....#####
int n; string s;
int ans = 999999, b[200002] = {}, h[200002] = {};

int main() {
	cin >> n >> s;
	for (int i = 1; i <= n; i++) {
		b[i] = b[i - 1] + (s[i - 1] == '#' ? 1 : 0);
		h[i] = h[i - 1] + (s[i - 1] == '.' ? 1 : 0);
	}
	ans = min(b[n], h[n]);
	for (int i = 0; i < n; i++) //s[i]|s[i+1]
		ans = min(ans, b[i + 1] + h[n] - h[i + 1]);
	cout << ans << endl;
	return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] A = new int[N];
		
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		
		Arrays.sort(A);
		
		System.out.println(A[N - 1] - A[0]);
		
	}
}


Measured memory_bytes: 23764