akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

class UnionFind {
public:
    struct Node {
        long long parent, rank, weight;
        Node() = default;
        Node(const long long& _parent,
             const long long& _rank,
             const long long& _weight = 0) :
            parent(_parent),
            rank(_rank),
            weight(_weight) { }
    };

    std::vector<Node> node;

    UnionFind(const long long& num_node) :
        node(num_node) {
        for(long long i = 0; i < num_node; i++) {
            node[i].parent = i;
        }
    }

    long long searchAndZipRoot(const long long& x) {
        auto& px = node[x].parent;
        if(px == x) {
            return x;
        }
        else {
            auto r = searchAndZipRoot(px);
            node[x].weight += node[px].weight;
            return px = r;
        }
    }

    long long calcWeight(const long long& x) {
        searchAndZipRoot(x);
        return node[x].weight;
    }

    void unite(const long long& x,
               const long long& y,
               const long long& weight = 0) {
        auto rx = searchAndZipRoot(x);
        auto ry = searchAndZipRoot(y);
        if(rx != ry) {
            auto  yw = weight + calcWeight(x) - calcWeight(y);
            auto& xr = node[rx].rank;
            auto& yr = node[ry].rank;
            if(xr < yr) {
                std::swap(rx, ry);
                yw *= -1;
            }
            node[ry].parent = rx;
            node[ry].weight = yw;
            if(xr == yr) {
                xr++;
            }
        }
    }

    long long calcDiff(const long long& x,
                       const long long& y) {
        return std::abs(calcWeight(x) - calcWeight(y));
    }

    template<class... A>
    bool checkWhetherRootIsSame(const A&... nodes) {
        auto node_list = std::initializer_list<long long>{nodes...};
        if(node_list.size() < 2) return false;
        auto v = searchAndZipRoot(*node_list.begin());
        for(size_t i = 1; i < node_list.size(); i++) {
            if(v != searchAndZipRoot(*(node_list.begin() + i))) return false;
        }
        return true;
    }
};

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

    int N, M;
    std::cin >> N >> M;

    UnionFind tree(N);

    string ans = "Yes";
    REP(i, M) {
        int l, r, d;
        std::cin >> l >> r >> d;
        l--; r--;

        if(!tree.checkWhetherRootIsSame(l, r)) {
            tree.unite(l, r, d);
        }
        else {
            auto diff = tree.calcDiff(l, r);
            if(diff != d) {
                ans = "No";
                break;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

ll pow(ll a, ll n, ll m) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a % m) {
		if (n % 2LL == 1LL) {
			ret = ret * a % m;
		}
	}
	return ret;
}

int main() {
  ll N,A,B,C;
  cin>>N>>A>>B>>C;
  ll ans = 0LL;
  ll comb = 1LL;
  ll Q = pow(A+B,N,mod);
  for(ll i = 0LL; i < N; i++){
    ll P = (pow(A,N,mod)*pow(B,i,mod))%mod;
    P=(P*comb)%mod;
    ll R = (P*pow(Q,mod-2,mod))%mod;
    ll S = (100LL*(N+i)*pow(A+B,mod-2,mod))%mod;
    ll a = (R*S)%mod;
    P = (pow(B,N,mod)*pow(A,i,mod))%mod;
    P=(P*comb)%mod;
    R = (P*pow(Q,mod-2,mod))%mod;
    ll b = (R*S)%mod;
    ans=(ans+a+b)%mod;
    comb=(comb*(N+i))%mod;
    comb=(comb*pow(1+i,mod-2,mod))%mod;
    Q=(Q*(A+B))%mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace Atcoder.Abc
{
    //https://atcoder.jp/contests/abc175/tasks/abc175_a
    public class Abc175_A
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string S = Console.ReadLine();

            switch (S)
            {
                case "RRR":
                    WriteLine("3"); 
                    break;
                case "RRS":
                    WriteLine("2");
                    break;
                case "SRR":
                    WriteLine("2");
                    break;
                case "SSS":
                    WriteLine("0");
                    break;
                default:
                    WriteLine("1");
                    break;
            }


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 17272
def main():
    dict = {"SUN": 7,
            "MON": 6,
            "TUE": 5,
            "WED": 4,
            "THU": 3,
            "FRI": 2,
            "SAT": 1,
            }
    day = input()
    ans = dict[day]
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()


def dsum(x):
    r = 0
    while x:
        r += x % 10
        x //= 10
    return r


def solve():
    ans = 1 << 60
    for a in range(1, N // 2 + 2):
        b = N - a
        ans = min(ans, dsum(a) + dsum(b))
    return ans


print(solve())


Measured memory_bytes: 9128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    int[][] a = new int[h][w];
    int[] gyou = new int[h];
    int[] retu = new int[w];
    for(int i = 0;i<h;i++){
      String ss = sc.next();
      for(int j = 0;j<w;j++){
        // System.out.println("i= "+i+" j= "+j);
        String s = ss.substring(j,j+1);
        if(s.equals("#")){
          a[i][j]=1;
          gyou[i] = 1;
          retu[j] = 1;
        }
      }
    }
    for(int i = 0;i<h;i++){
      for(int j = 0;j<w;j++){
        if(gyou[i] == 0 || retu[j] == 0){
          a[i][j] = -1;
        }
      }
    }
    for(int i = 0;i<h;i++){
      boolean ch = false;
      for(int j = 0;j<w;j++){

        if(a[i][j] == 0){
          System.out.print(".");
          ch = true;
        }else if(a[i][j] == 1){
          System.out.print("#");
          ch = true;
        }
      }
      if(ch)System.out.println("");
    }

  }
}


Measured memory_bytes: 39296
#!/usr/bin/env python3
import sys

A,B,C,K = list(map(int, input().split()))

if K <= A:
    print(K)
    sys.exit()
elif K <= A + B:
    print(A)
    sys.exit()
else:
    numB = K - (A + B)
    print(A - numB)
    sys.exit()

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/04  Problem: 064_arc_c / Link: https://arc064.contest.atcoder.jp/tasks/arc064_c?lang=en  ----- */
/* ------問題------

xy 平面があります。 すぬけ君は座標 (xs,ys) から座標 (xt,yt) まで移動しようとしています。 すぬけ君は好きな向きへ速さ 1 で動くことができます。 なお、すぬけ君は大きさのない点と見なすことにします。
平面上には N 個の円形のバリアが張ってあります。 i 番目のバリアは中心が (xi,yi) で半径が ri です。 バリアは互いに重なっていたり、互いを含んでいたりすることがあります。
平面上の各座標について、その座標がどのバリアの内部にも含まれない場合、その座標には宇宙線が降り注いでいます。
すぬけ君は移動中にできるだけ宇宙線を浴びたくないので、宇宙線を浴びる時間が最小になるように移動します。 すぬけ君が移動中に宇宙線を浴びる時間の最小値を求めてください。

-----問題ここまで----- */
/* -----解説等-----

移動する人の気持ちになると円から円の移動は中心から中心へ移動するのが最適なのでこれに工夫なく辺を張れば良い
なぜ600点?

----解説ここまで---- */



using Type = pair<double, int>;

vector<double> Dijkstra(vector<vector<pair<int,double>>>& G, int s) {
	vector<double> dist(SZ(G), LINF);
	dist[s] = 0;
	priority_queue<Type, vector<Type>, greater<Type>> que;
	que.push(Type(0LL, s));

	while (!que.empty()) {
		Type p = que.top(); que.pop();
		int v; /* 頂点*/ double d; /* 頂点vまでの距離 */
		tie(d, v) = p;

		if (d > dist[v]) continue;

		FOR(i, 0, (int)G[v].size()) {
			int nv = G[v][i].first;
			if (dist[nv] > dist[v] + G[v][i].second) {
				dist[nv] = dist[v] + G[v][i].second;
				que.push(Type(dist[nv], nv));
			}
		}
	}
	return dist;
}

LL N;

double ans = 0LL;
struct Circle {
	double x, y, r;
	Circle() { x = y = r = 0; }
};

double distance(Circle &a, Circle &b) {
	double d =hypot(a.x - b.x, a.y - b.y)- (a.r + b.r );
	return (d > 0 ? d : 0);
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	double sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty >> N;
	vector < Circle > Cir(N + 2);
	FOR(i, 0, N) {
		cin >> Cir[i].x >> Cir[i].y >> Cir[i].r;
	}
	const int S = N;
	const int T = N + 1;
	Cir[S].x = sx; Cir[S].y = sy;
	Cir[T].x = tx; Cir[T].y = ty;
	N += 2;
	
	vector<vector<pair<int,double>>> G(N);
	FOR(i, 0, N) {
		FOR(j, i + 1, N) {
			double d = distance(Cir[i], Cir[j]);
			G[i].push_back(pair<int, double>(j,d));
			G[j].push_back(pair<int, double>(i,d));
		}
	}
	vector<double> dist = Dijkstra(G, S);
	ans = dist[T];
	cout << fixed<<setprecision(10)<<ans << "\n";

	return 0;
}


Measured memory_bytes: 21872
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
 
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;
 
int main(void) {
    ll x, happy=0;
    cin >> x;
    happy += x/500 * 1000;
    x = x%500;
    happy += x/5 * 5;
    cout << happy << endl;
}


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

int main(){
  string T;
  cin >> T;

  // 1文字だけの場合
  if (T.size() == 1 && T.at(0) == '?'){
    T.at(0) = 'D';

  }else{
    // 2文字以上の場合
    int idx = 0;
    // 1文字目の処理
    if (T.at(idx) == '?'){
      T.at(idx) = (T.at(idx+1) == 'P' ? 'D' : 'P');
    }
    idx++;
  
    // 2文字目以降の処理
    for (; idx < T.size(); idx++){
      if (T.at(idx) == '?'){
	T.at(idx) = 'D';
      }
    }
  }
  
  cout << T << endl;
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORR(i,n,a) for(int i=(n); i>=(a); i--)
#define REPR(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;


int main() {
	int n,t;
	cin >> n;
	V<V<int> > v;
	V<int> now(n, 0);

	REP(i,n) {
		V<int> a;

		REP(j, n-1) {
			cin >> t;
			a.push_back(t);
		}
		v.push_back(a);
	}

	int ans = 0;
	int l = n*n/2;
	REP(i, l) {
		V<int> c(n, 0);
		int any = 0;
		REP(j, n) {
			if(now[j] != n-1 && c[j] != 1) {
				int opo = v[j][now[j]]-1;
				if(c[opo] != 1 && v[opo][now[opo]] == j+1) {
					c[j] = 1;
					now[j]++;
					c[opo] = 1;
					now[opo]++;
					any++;
				}	
			}
		}
		if(any == 0) {
			break;
		}
		ans += 1;
	}
	REP(i,n) {
		if(now[i] != n-1) {
			ans = -1;
		}
	}

	cout << ans << endl;
}



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

int main(){
  int n,i;
  cin >> n;
  long long x[n],b[n];
  for(i=0;i<n;i++){
    cin >> x[i];
    b[i] = x[i];
  }
  sort(x,x+n);
  long long cen = x[(n-1)/2];
  //cout << cen << endl;
  for(i=0;i<n;i++){
    if(b[i]>cen)cout << x[(n-1)/2] << endl;
    else cout << x[(n-1)/2+1] << endl;
  }
  return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<stdio.h>
using namespace std;



int partition(int A[], int n, int p, int r) {
  int i, j, t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ) {
    if (A[j] <= x) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

void quickSort(int A[], int n, int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}




int main() {
  int A[100], N;
  double sum, a;
  cin >> N;
  for (int i = 0; i < N ; i++) cin >> A[i];
  quickSort(A, N, 0, N-1);
  sum = 0;
  for (int i = 0; i < N ; i++) {
    a = double(1.0/A[N - 1 - i]);
    sum += a;
  }
  cout << 1/sum << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
box  = []
prime = []
ans = 0
def Prime_Factorization(n):
    i = 2
    prime_factors = []
    while n > 1:
        if n % i == 0:
            prime_factors.append(i)
            n = n / i
        else:
            i += 1
    return prime_factors

for i in range(1,n+1):
    prime = Prime_Factorization(i)
    box.append(prime.count(2))
    #print(box)


if n == 1:
    print(1)
else:
    ans = box.index(max(box)) + 1
    print(ans)


Measured memory_bytes: 3064
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

// Returns a number of elements less than a specified value.
// The input array needs be sorted.
fun countLessThan(xs: IntArray, v: Int): Int {
  var l  = 0
  var u = xs.size - 1
  while (l <= u) {
    val m = (l + u + 1) / 2
    if (xs[m] < v) {
      l = m + 1
    } else {
      u = m - 1
    }
  }
  return l
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val xs = fastReadInts(n)
  val ys = fastReadInts(n)

  val mods = Array(30, { IntArray(n) })
  for (b in 0 until 30) {
    for (i in 0 until n) {
      mods[b][i] = xs[i] % (1 shl (b + 1))
    }
    mods[b].sort()
  }

  var ans = 0
  for (b in 0 until 30) {
    for (y in ys) {
      val dy = y % (1 shl (b + 1))
      var count = 0
      // m + dy in [2 ^ b, 2 ^ (b + 1))
      // i.e.
      // If dy <= 2 ^ b: m in [2 ^ b - dy, 2 ^ (b + 1) - dy)
      // If not: [0, 2 ^ (b + 1) - dy), [2 ^ b - dy + 2 ^ (b + 1), 2^ (b + 1))
      if (dy <= 1 shl b) {
        count += countLessThan(mods[b], (1 shl (b + 1)) - dy) -
            countLessThan(mods[b], (1 shl b) - dy)
      } else {
        count += countLessThan(mods[b], (1 shl (b + 1)) - dy) +
            n -
            countLessThan(mods[b], (1 shl b) - dy + (1 shl (b + 1)))
      }

      if (count % 2 == 1) {
        ans = ans xor (1 shl b)
      }
    }
  }
  println(ans)
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
// Description: グラフの型定義(これは最小費用流)
// Verifyed: Many Diffrent Problem 

//Appropriately Changed
using edge=struct{int to;};
using G=vector<vector<edge>>;

//Appropriately Changed
void add_edge(G &graph,int from,int to){ 
	graph[from].push_back({to});
	graph[to].push_back({from});
}

const int nmax=100010;
int color[nmax];

bool dfs(const G &graph,int v,int c){
	if(color[v]==-1) color[v]=c;
	
	bool ok=true;
	for(auto &e:graph[v]){
		if(color[e.to]==-1){
			ok&=dfs(graph,e.to,c^1);
		}else{
			ok&=(color[e.to]==(c^1));
		}
	}

	if(color[v]!=c) ok=false;
	return ok;
}

int main(void){
	ll n,m;
	cin >> n >> m;

	G graph(n);


	rep(i,m){
		int a,b;
		cin >> a >> b;
		add_edge(graph,a-1,b-1);
	}

	
	ll niso=n,even=0,odd=0;
	rep(v,n) color[v]=-1;

	rep(v,n){
		if(color[v]!=-1) continue;
		if(int(graph[v].size())==0){
			niso--;
			continue;
		}

		if(dfs(graph,v,0))
			even++;
		else
			odd++;
	}

	//cout << niso << " " << even << " " << odd <<  endl;
	ll ans=1LL*n*n-1LL*niso*niso;
	ans+=2LL*even*even;
	ans+=2LL*even*odd;
	ans+=1LL*odd*odd;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11776
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
S=['']*N
for i in range(N):
    S[i]=input()

enda=0
startb=0
both=0
cntab=0
for i in range(N):
    if S[i].startswith('B') and S[i].endswith('A'):
        both+=1
    elif S[i].startswith('B'):
        startb+=1
    elif S[i].endswith('A'):
        enda+=1
    cntab+=S[i].count('AB')

cntab+=max(both-1, 0)
mnab=min(enda, startb)
cntab+=mnab
if max(enda, startb)!=0 and both!=0:
    cntab+=1
print(cntab)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = n / (a + b) * a + min(a, n % (a + b));
  cout << ans << endl;
  return 0;
}


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

int check( int a, int b, int c ){

    if( a == b || b == c || c == a ) return 0;

    if( a + b <= c || b + c <= a || c + a <= b ) return 0;

    return 1;
}



int main(){

    int N, i, j, k;
    cin >> N;

    vector<int> L(N);
    for( i = 0; i < N; i++ ){
        cin >> L[i];
    }

    int ans=0;
    int flag;
    int a, b, c;
    for( i = 0; i < N-2; i++ ){
        a = L[i];
        for( j = i+1; j < N-1; j++ ){
            b = L[j];
            for( k = j+1; k < N; k++ ){
                c = L[k];

                flag = check( a, b, c );
                if( flag == 1 ) ans += 1;
            }
        }
    }

    cout << ans << endl;

}




Measured memory_bytes: 3568
N = int(input())
x = []
y = []
h = []
for i in range(N):
    a,b,c = [int(hoge) for hoge in input().split()]
    x.append(a)
    y.append(b)
    h.append(c)

cx = 0
cy = 0
H = 0
done_flag = False

for i in range(101):
    for j in range(101):
        # (x, y) = (i, j)
        cand_h = []
        min_h = []

        for k in range(N):
            if h[k] != 0:
                cand_h.append(h[k] + abs(x[k] - i) + abs(y[k] - j))
            else:
                min_h.append(abs(x[k] - i) + abs(y[k] - j))
                
        min_h = min(min_h) if len(min_h) > 0 else 100000000000
    
        if len(set(cand_h)) == 1 and list(set(cand_h))[0] <= min_h:
            print("{} {} {}".format(i, j, cand_h[0]))
            done_flag = True
            break
    if done_flag:
        break

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;

long long ctoi(char num) {
	return num - '0';
}

long long eval(vector<char>s) {
	vector<long long> num; vector<char>ope;
	long long number = ctoi(s[0]);
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == '+') {
			ope.push_back('+');
			num.push_back(number);
			number = 0;
		}
		else if (s[i] == '-') {
			ope.push_back('-');
			num.push_back(number);
			number = 0;
		}
		else {
			number = number * 10 + ctoi(s[i]);
		}
		if (i == s.size() - 1) {
			num.push_back(number);
		}
	}
	long long ans = num[0];
	for (int i = 1; i < num.size(); i++) {
		if (ope[i - 1] == '+') {
			ans += num[i];
		}
		else if (ope[i - 1] == '-') {
			ans -= num[i];
		}
	}
	return ans;
}

int main() {
	string s;
	cin >> s;
	vector<char> k;
	int num;
	long long ans = 0;
	if (s.length() > 1) {
		for (int i = 0; i < pow(2, s.length() - 1); i++) {
			num = i;
			k = {};
			for (int j = 0; j < s.length() - 1; j++) {
				k.push_back(s[j]);
				if (num % 2 == 1) {
					k.push_back('+');
				}
				num /= 2;
			}
			k.push_back(s[s.length() - 1]);
			ans += eval(k);
			k = {};
		}
		cout << ans << endl;
	}
	else {
		cout << s[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,a,b,c,d;
  cin >> N;
  a = N/1000;
  b = (N-a*1000)/100;
  c = (N%100)/10;
  d = N%10;
  if ((a == b && b == c) || (b == c && c == d)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

a.sort()
a.reverse()

Alice = sum(a[i] for i in range(len(a)) if i % 2 == 0)
Bob = sum(a[i] for i in range(len(a)) if i % 2 == 1)

print(Alice - Bob)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
#define ll long long
#define trace(x) cerr << #x << " = " << x << endl
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main()
{
   /*
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("ouput.txt","w",stdout);
    #endif 
   */

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while(t--){
        int x;
	cin>>x;
	if(x)
		cout<<0<<endl;
	else
		cout<<1<<endl;
    }
    return 0;
} 


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

int main() {
    int N, tmp;
    int div = 0;
    cin >> N;
    tmp = N;
    while (tmp != 0) {
        div += tmp % 10;
        tmp /= 10;
    }
    if (N % div == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  rep(i,N){
    cin >> p[i];
  }
  int m = p[0];
  int ans = 1;
  for(int i = 1;i<N;i++){
    if(m >= p[i]) ans++;
    m = min(m,p[i]);
  }
  cout << ans << endl;
 }

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	string ss;
	cin >> ss;
	int q;
	cin >> q;
	int t,f,temp = 0;
	char c;
	for(int i = 1;i <= q;i++){
		cin >> t;
		if(t == 1){
			temp++;
		}
		else if(t == 2){
			cin >> f >> c;
			if(f == 1){
				if(temp % 2 == 1) ss.insert(ss.end(),c);
				else ss.insert(ss.begin(),c);
			}
			else if(f == 2) {
				if(temp % 2 == 1) ss.insert(ss.begin(),c);
				else ss.insert(ss.end(),c);
			}
		}
	}
	if(temp % 2 == 1) reverse(ss.begin(),ss.end());
	cout << ss << endl;
	return 0;
}


Measured memory_bytes: 900
#include <cstdio>
#include <cstring>

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

Measured memory_bytes: 128
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [ for i in 1..n do yield stream.ReadLine().Split() |> Array.map f ]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)
  
let N = util.Scan1 int

let cl n =
  match n%2 with
  | 0 -> n/2
  | _ -> 3*n+1 

let rec rfn i x xs =
  let c = cl x
  if List.contains c xs
    then i+1
    else rfn (i+1) (cl x) (c::xs)

rfn 1 N [N]
|> printfn "%d"

util.Close()


Measured memory_bytes: 14812
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define All(x) (x).begin(),(x).end()
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<int,int> PII;
const double PI=acos(-1.0);
const double eps=1e-6;
const long long mod=998244353;
const int inf=0x7fffffff;
const int maxn=100005;
ll qpow(ll x,ll y,ll Mod) {ll ans=1,base=x%Mod; while(y){if(y&1)ans=(ans*base)%Mod;base=(base*base)%Mod;y>>=1;} return ans;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// fast read
template<class T> void read(T &x) {
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}

int n,s,a[maxn];
ll dp[3005][3005];
int main(){
	//freopen("test.in","r",stdin);
	read(n),read(s);
	rep(i,1,n) read(a[i]);
	// ll inv2=qpow(2,mod-2,mod);
	dp[0][0]=1;
	rep(i,1,n){
		rep(j,0,s){
			dp[i][j]=(dp[i][j]+dp[i-1][j]*2+((j>=a[i])?dp[i-1][j-a[i]]:0))%mod;
		}
	}
	printf("%lld\n",dp[n][s]%mod);
	return 0;
}

Measured memory_bytes: 74112
M, K = map(int, input().split())

if K==0:
    l = []
    for i in range(2**M):
        l += [i, i]
    print(*l)
elif M==0 or M==1:
    print(-1)
elif 1<=K<2**M:
    l = []    
    for i in range(2**M):
        if i!=K:
            l += [i]
    l += [K]
    for i in range(2**M)[::-1]:
        if i!=K:
            l += [i]
    l += [K]
    print(*l)
else:
    print(-1)

Measured memory_bytes: 20340
# python 3.8.2用
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
from math import gcd
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def lcm(a,b):return (a*b) // gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def lprint(l): print(*l, sep='\n')
def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
R = iin()
 
print(2*R*math.pi)

Measured memory_bytes: 10644
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

 
int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    long h[105]={0};
    long i,j;
    for(i=0; i<n; i++) {
        scanf("%ld", &(h[i]));
    }

    long count = 0;
    for(i=1; i<=100; i++) {        
        for(j=0; j<n; j++) {
            if(h[j]>=i) {
                long k=j;
                while(k<n && h[k]>=i) {
                    k++;
                }
                j=k-1;
                count ++;
            }
        }
    }
    printf("%ld\n", count);
 
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s;
    string ans="No";
    cin >> s;
    if(s[0]==s[2]){
        ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int n,k,q;
	cin >> n >> k >> q;
	vector<int> a(n,k);
	for(int i = 0;i<n;i++)
	{
		a[i] -= q;
	}
	for(int i = 0;i<q;i++)
	{
		int x;
		cin >> x;
		x--;
		a[x]++;
	}
	for(int i = 0;i<n;i++)
	{
		//cout<<a[i]<<endl;
		if(a[i]>0)
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}		
	}
	return 0;
}

Measured memory_bytes: 1024
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

int n,m,k;

int32_t main(){_
    //freopen("input","r",stdin);
    cin >> n >> m >> k; 
    if(k % n == 0 || k % m == 0) rc("Yes");
    for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) if(i * m + j * n - 2 * i * j == k) rc("Yes");
    rc("No");
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int n;
    cin>>n;
    vector<int> c(n-1),s(n-1),f(n-1);
    rep(i,0,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }

    rep(i,0,n){
        if(i==n-1){ cout<<0<<endl;break;}
        ll arrival=0;
        rep(j,i,n-1){
            if(arrival<s[j]) arrival=s[j];
            else{
                if(arrival%f[j]){
                    ll div=(arrival-s[j])/f[j];
                    //arrival=s[j]+div*f[j]+f[j];
                    arrival=arrival+f[j]-(arrival%f[j]);
                }
            }
            arrival+=c[j];
        }
        cout<<arrival<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}

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

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long
#define lson node<<1
#define rson (node<<1)+1

const int maxn=2e5+10;
const int mod=998244353;
const double pi=-acos(-1);

int main()
{
    ll a,b;
    sll2(a,b);
    printf("%lld\n",a*b);
    return 0;
}


Measured memory_bytes: 3828
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n, h = LI()
power = []
for a, b in LIR(n):
    power += [(a, 1)]
    power += [(b, 0)]


power.sort(reverse=True)
for i in range(2 * n):
    p, flag = power[i]
    h -= p
    if h <= 0:
        print(i + 1)
        exit()
    elif flag:
        print(i + h // p + bool(h % p) + 1)
        exit()

Measured memory_bytes: 71516
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};

//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
//finvが階乗の逆元

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  ll cnt=0;
  for(ll i=1;i<=n;i++){
    string s=to_string(i);
    if(s.size()%2==1)cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3748
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int n;
double v[55],list[55];
double ans;

int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	sort(v, v + n);

	for (int i = 0; i < n - 1; i++){
		v[i + 1] = (v[i] + v[i + 1]) / 2;
		ans = v[i + 1];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b < c)cout << a+b+1+b;
  else cout << c+b;
  return 0;
}


Measured memory_bytes: 256
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 1e6 + 111;
        
using namespace std;          

int n, k, ans, kk;
             	
void solve(){
	cin >> n;

	set <int> s;

	for (int i = 2; i * i <= n; i++){
		int x = n;
		while (x % i == 0)
			x /= i;
		x %= i;
		ans += (x == 1);
		if (x == 1)
			s.insert(i);
	}
	n--;

	for (int i = 1; i * i <= n; i++){
		int x = n;
		if (x % i == 0){
			s.insert(x / i);
			s.insert(i);
		}
	}

	cout << sz(s);
}                              
      
main(){
    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
changeLR = []
changeRL = []
happy = 0
for i in range(N):
    if i == 0:
        before = S[0]
    else:
        tmp = S[i]
        if tmp == 'L' and before == 'R':
            changeLR.append(i)
        elif tmp == 'R' and before == 'L':
            changeRL.append(i)
        else:
            happy += 1
        before = tmp
koukan = min(len(changeLR), len(changeRL))
if K <= koukan:
    happy += 2 * K
elif K > koukan:
    if len(changeLR) != len(changeRL):
        happy += 2 * koukan + 1
    else:
        happy += 2 * koukan
print(happy)

Measured memory_bytes: 7148
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll> ar[2001];
ll dep[2001];
bool vis[2001];
ll dp[2001]={0};
void bfs(ll s)
{   memset(vis,false,sizeof(vis));
     memset(dep,0,sizeof(dep));
    queue<ll> ae;
    ae.push(s);
    vis[s]=true;
    dep[s]=0;
    while(!ae.empty())
    {
        ll e=ae.front();
        ae.pop();
        for(auto it : ar[e])
        {
            if(!vis[it])
            {   dep[it]=dep[e]+1;
                 ++dp[dep[it]];
                vis[it]=true;
                ae.push(it);
            }
        }
    }
}
void solve()
{
   ll n,a,b;
   cin>>n>>a>>b;
   for(ll x=1;x<n;x++)
   {
       ar[x].push_back(x+1);
       ar[x+1].push_back(x);
   }
   ar[a].push_back(b);
   ar[b].push_back(a);
   for(ll x=1;x<=n;x++)
   {
       bfs(x);
   }
   for(int x=1;x<=n-1;x++)
   {
       cout<<dp[x]/2<<"\n";
   }
}
int main()
{
  ll t=1;
 // cin>>t;
  while(t--)
  {
    solve();
  }
}


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

int main() {
    int n ; scanf("%d" , &n ) ;
    int x = n , sum = 0 ;
    while( x ) {
        sum += ( x % 10 ) ;
        x /= 10 ;
    }
    printf("%s\n" , (n % sum == 0 ) ? "Yes" : "No" ) ;
    return 0;
}


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

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

    int n;
    cin >> n;
    vector<int> V(n);
    REP(i, n) cin >> V[i];

    unordered_map<int, int> mp[2];
    REP(i, n) mp[i%2][V[i]]++;
    
    vector<pair<int, int>> P[2];
    REP(i, 2){
        mp[i][0] = 0;
        for(auto x : mp[i]){
            P[i].push_back({x.second, x.first});
        }
        sort(P[i].rbegin(), P[i].rend());
    }
    
    int ans = 0;
    if(P[0][0].second != P[1][0].second){
        ans = (n/2 - P[0][0].first) + (n/2 - P[1][0].first);
    }else{
        if(P[0][1].first >= P[1][1].first){
            ans = (n/2 - P[0][1].first) + (n/2 - P[1][0].first);
        }else{
            ans = (n/2 - P[0][0].first) + (n/2 - P[1][1].first);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5908
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n,now=0;
    cin>>n;
    string s,t;
    cin>>s>>t;
    while(1){
        if(s.substr(now,n-now)==t.substr(0,n-now)){
            break;
        }
        now++;
    }
    cout<<n+now<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
  string A,B,C;
  cin>>A>>B>>C;
  if(A.at(A.size()-1)==B.at(0)&&B.at(B.size()-1)==C.at(0)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(0, A + B - N) << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
    using namespace std;
    #define ull unsigned long long
    #define ll long long
    #define pi  acos(-1)
    const int w=2e5+5;
    const ll mod=998244353;
    int main()
    {
        int i,j;
        ll x;
        cin>>x;
        ll ans=0;
        ans+=x/500*1000;
        x%=500;
        ans+=x/5*5;
        cout<<ans<<endl;
        return 0;
    }

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for B - ss
	var S string
	fmt.Scanf("%s", &S)

	for i := 1; i < len(S); i++ {
		if (len(S)-i)%2 != 0 {
			continue
		} else if S[0:((len(S)-i)/2)] == S[((len(S)-i)/2):len(S)-i] {
			fmt.Println(len(S) - i)
			break
		}
	}
}


Measured memory_bytes: 1836
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define ub upper_bound
#define lb lower_bound

int main(){
    fastio;
    int h1, s1, h2, s2;
    cin >> h1 >> s1 >> h2 >> s2;
    int attack  = 1;
    while(h1 >0  && h2 > 0){
        if(attack == 1){
            h2 -= s1;
            attack = 2;
        }
        else{
            h1 -= s2;
            attack = 1;
        }
    }

    if(h1 <= 0) cout << "No\n";
    else cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<cstring>
using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define fdj(a,b) for(int j=a-1;j>=b;--j)
#define fdo(a,b) for(int o=a-1;o>=b;--o)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
///////////////////////////

int const INF = 1e9 + 41;
int const N = 1e5 + 41;

int n, h, x[N], y[N];
vector<pii> a;
int ans = INF;

void solve(){
	fi(0, n) a.pb(mp(x[i], y[i]));
	vi c;
	sort(a.begin(), a.end());
	fi(0, n-1){
		c.pb(max(a[i].second, a.back().first));
	}
	
	int q = 0;
	int h0 = h;
	vi b;
	fi(0, n) b.pb(y[i]);
	sort(b.begin(), b.end());
	fdi(sz(b), 0){
		if(h0 > 0){
			++q;
			h0 -= b[i];
		}else break;
	}
	if(h0 <= 0) ans = q;

	q = 0;
	h0 = h;
	fi(0, n-1){
		if(h0 > a.back().second){
			h0 -= c[i];
			++q;
		}else break;
	}
	if(h0 > 0){
		h0 -= max(a.back().second, a.back().first);
		++q;
	}
	if(h0 > 0){
		int q0 = (h0 + a.back().first - 1) / a.back().first;
		q += q0;
		h0 -= q0 * a.back().first;
	}
	ans = min(ans, q);
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d %d",&n,&h);
	fi(0, n) scanf("%d %d",&x[i],&y[i]);

	solve();
	
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 3060
s = input()
s = s[::-1]
while len(s)>4:
	if s[:5]=="maerd" or s[:5]=="esare": s=s[5:]
	elif s[:6]=="resare": s=s[6:]
	elif s[:7]=="remaerd": s=s[7:]
	else: break
if s=="": print("YES")
else: print("NO")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main()
{
    ll n;
    cin>>n;
    vector<ll> arr(n);
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    ll sum,prev;
    vector<ll> ans(n);
    ans[0]=1;
    sum=arr[0];
    prev=1;
    for(ll i=1;i<n;i++)
    {
        ans[i]=((prev^sum)^arr[i]);
        prev^=ans[i];
        sum^=ans[i];
    }
    for(auto x:ans)
        cout << (sum^x) << ' ';
    cout << endl;
}

Measured memory_bytes: 6336
S = [i for i in input()]
T = [i for i in input()]

judge_s, judge_t = {}, {}

idx = 0
ct = 0
for i in S:
    if judge_s.get(i):
        S[idx] = judge_s[i]
    else:
        S[idx] = ct
        judge_s[i] = ct
        ct += 1
    idx += 1

idx = 0
ct = 0
for i in T:
    if judge_t.get(i):
        T[idx] = judge_t[i]
    else:
        T[idx] = ct
        judge_t[i] = ct
        ct += 1
    idx += 1

if S == T:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 7076