akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int dp[200005][2];
int main(){
    string s;
    int n;
    cin>>n>>s;
    if(s[0]=='.')
     dp[0][1]=1;
    else
     dp[0][0]=1;
    for(int i=1;i<n;i++){
      if(s[i]=='.'){
        dp[i][0]=dp[i-1][0];
        dp[i][1]=min(dp[i-1][1],dp[i-1][0])+1;
      }
      else{
        dp[i][0]=dp[i-1][0]+1;
         dp[i][1]=min(dp[i-1][1],dp[i-1][0]);
      }
    }
    cout<<min(dp[n-1][0],dp[n-1][1])<<"\n";
}


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

int main() {
    string S;
    cin >> S;
    int N = (int)S.size();
    int num1 = 0, num2 = 0;

    // 0101...01
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0 && (S[i] - '0') != 0) num1++;
        else if (i % 2 != 0 && (S[i] - '0') != 1) num1++;
    }
    // 1010...10
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0 && (S[i] - '0') != 1) num2++;
        else if (i % 2 != 0 && (S[i] - '0') != 0) num2++;
    }

    cout << min(num1, num2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int calc(int x){
    if(x == 0)return 0;
    return x%10 + calc(x/10);
}
int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        int sum = calc(i);
        if(sum >= a && sum <= b)ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
A=[int(x) for x in input().split()]
lower=A[0]//100
upper=A[1]//100
count=upper-lower+1
if A[0]>lower*100+int(str(lower)[0])+int(str(lower)[1])*10:
  count-=1
if A[1]<upper*100+int(str(upper)[0])+int(str(upper)[1])*10:
  count-=1
print(count)

Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
int main(){
 
string S;
cin>>S;


for(int tmp=0;tmp<(1<<3);tmp++){
  string s;
  s+=S.at(0);
  int sum=S.at(0)-'0';
  for(int i=0;i<3;i++){
    if((tmp>>i)&1){//trueの時+
     s+="+";
     sum +=S.at(i+1)-'0';
     
     }else{
       s+="-";
       sum-=S.at(i+1)-'0';
       
    }s+=S.at(i+1);
  }
  if(sum==7){cout<<s<<"=7"<<endl;
             return 0;
            }
  
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x, k, d, ans;
int main()
{
	cin >> x >> k >> d;
	ll a = abs(x) / d;
	if (a == k)
	{
		ans = abs(x) - d * a;
	}
	else if (a < k)
	{
		ll c = k - a;
		if (c & 1)
		{
			ans = d * (a + 1) - abs(x);
		}
		else
		{
			ans = abs(x) - d * a;
		}
	}
	else
	{
		ans = abs(x) - d * k;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;



int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::unordered_set<int> node[10001];
  for(int i=0;i<2*n*n-2*n;i++){
    int a,b;
    cin>>a>>b;
    node[a].insert(b);
    node[b].insert(a);
  }

  int result[101][101]={};


  for(int i=1;i<=n*n;i++){
    if(node[i].size() == 2){
      result[1][1]=i;
      int down=*(node[i].begin()),right=*(++node[i].begin());
      result[2][1]=down;
      result[1][2]=right;
      for(auto x:node[down]){
        for(auto y:node[right]){
          if(x==y&&x!=result[1][1]){
            result[2][2]=x;
          }
        }
      }
      break;
    }
  }

  for(int layer=3;layer<=n;layer++){
    //下側を詰める
    for(auto x:node[result[layer-1][1]]){
      if(x!=result[layer-2][1]&&x!=result[layer-1][2]){
        result[layer][1]=x;
        break;
      }
    }
    for(int c=2;c<=layer-1;c++){
      int left=result[layer][c-1],up=result[layer-1][c];
      for(auto x:node[left]){
        for(auto y:node[up]){
          if(x==y&&result[layer-1][c-1]!=x){
            result[layer][c]=x;
          }
        }
      }

    }


    //右側とラストを詰める
    for(auto x:node[result[1][layer-1]]){
      if(x!=result[1][layer-2]&&x!=result[2][layer-1]){
        result[1][layer]=x;
        break;
      }
    }
    for(int r=2;r<=layer;r++){
      int left=result[r][layer-1],up=result[r-1][layer];
      for(auto x:node[left]){
        for(auto y:node[up]){
          if(x==y&&result[r-1][layer-1]!=x){
            result[r][layer]=x;
          }
        }
      }
    }
  }

  for(int i=1;i<=n;i++){
    for(int j=1;j<n;j++){
      cout<<result[i][j]<<" ";
    }
    cout<<result[i][n]<<endl;
  }



  return 0;
}



Measured memory_bytes: 5468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef ONLINE_JUDGE
#define debug(x) {}
#else
#define debug(x) { cerr << #x << " = " << x << endl; }
#endif
const int MAXN = 100005;
bitset<MAXN> bt;
int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  int times = max(x/30,1000);
  bt[0] = 1;
  for(int i=0; i<times; ++i){
    for(int j=100; j<=105; ++j){
      bt |= bt<<j;
    }
  }
  cout<<bt[x]<<'\n';
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String S = sc.next();
        String ans = "No";
        if(S.substring(S.length() / 2).equals(S.substring(0, S.length() / 2))) ans = "Yes";
        System.out.println(ans);
    }
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;
typedef long long ll;
typedef pair<int, int> P;
vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

template <class T>
inline bool chmin(T& a, T b)
{
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b)
{
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank;

    UnionFind(int n = 1)
    {
        init(n);
    }

    void init(int n = 1)
    {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            int r = root(par[x]);
            return par[x] = r; // 辺の縮約（一度根をたどったら辺を直接根に向かって貼り直す）
        }
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y);
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x; // xよりyのほうが高さが小さい木
        return true;
    }
};

// 最大公約数
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

// 最小公倍数
int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y)
{
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

// 負の数にも対応した % 演算
long long mod(long long val, long long m)
{
    long long res = val % m;
    if (res < 0)
        res += m;
    return res;
}

// a^n modを計算する
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    // nを2進数表示して1が埋まっている桁に関してはa^mをかけていく
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod)
{
    return modpow(a, mod - 2, mod);
}

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    rep(i, N)
    {
        cin >> H.at(i);
    }

    sort(H.begin(), H.end(), greater<int>());

    ll sum = 0;
    for (int i = K; i < N; i++) {
        sum += H.at(i);
    }

    cout << sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int INF = 1<<30;
 
int main() {
  int n, m;
  string s;
  cin >> n >> m >> s;
  vector<int> dp(n+1,INF);
  dp[n] = 0;
  queue<int> q;
  q.push(0);
  for (int i = n-1; i >= 0; --i) {
    while (1) {
      if (q.size() == 0) {
        puts("-1");
        return 0;
      }
      if (q.front() != INF && q.size() <= m) break;
      q.pop();
    }
    if (s[i] == '0') dp[i] = q.front()+1;
    q.push(dp[i]);
  }
 
  vector<int> ans;
  int x = 0;
  int rest = dp[0];
  while (x < n) {
    --rest;
    int i = 1;
    while (dp[x+i] != rest) ++i;
    ans.push_back(i);
    x += i;
  }
  rep(i,ans.size()) {
    printf("%d%c", ans[i], i==int(ans.size())-1?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 4412
n = gets.chomp.to_i
ss = n.times.map { gets.chomp }

count = {}
ss.each { |s| count[s] = (count[s] || 0) + 1 }

most = count.values.max

words = count.map { |k, v| [k, v] }
             .select { |kv| kv[1] == most }
             .map { |kv| kv[0] }
             .sort

words.each do |word|
  puts word
end


Measured memory_bytes: 58460
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

void dfs(const vector<vector<int>>& graph, const vector<ll>& c, vector<ll>& ans, int node, int parent, int& idx) {
    for (auto& next_node : graph[node]) {
        if (next_node == parent) {
            continue;
        }
        dfs(graph, c, ans, next_node, node, idx);
    }
    ans[node] = c[idx++];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> graph(N);
    int a, b;
    rep(i, 0, N - 1) {
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<ll> C(N);
    for (auto& c : C) {
        cin >> c;
    }
    sort(all(C));
    ll sum = 0;
    rep(i, 0, N - 1) {
        sum += C[i];
    }
    cout << sum << endl;
    vector<ll> ans(N);
    int idx = 0;
    dfs(graph, C, ans, 0, -1, idx);
    rep(i, 0, N) {
        cout << ans[i] << " \n"[i + 1 == N];
    }
    return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::vector<ll> vll;
typedef std::vector<vll> vvll;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int main() {
  ll n, m;
  scan(n, m);
  vll x(m);
  scan(x);
  sort(all(x));
  ll sum = x[m-1] - x[0];
  vll diffs(m-1);
  rep (i, m-1) {
    diffs[i] = x[i+1] - x[i];
  }
  sort(all(diffs));
  reverse(all(diffs));
  rep (i, min(m-1, n-1)) {
    sum -= diffs[i];
  }
  print(sum);
  return 0;
}


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

vector<int>E[S];
int u[2 * S], v[2 * S], r[2 * S], ans[2 * S], d[S], cnt = 1, b[2 * S], ok[S]{ 1 };
queue<int>que;
void bfs(int u) {
	que.push(u);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int v : E[p]) {
			if (d[v] == d[p] + 1 && !ok[v]) {
				ok[v] = true; cnt++; que.push(v);
			}
		}
	}
}
int main() {
	int n, m, q; scanf("%d%d%d", &n, &m, &q);
	rep(i, m) {
		scanf("%d%d", &u[i], &v[i]);
		u[i]--; v[i]--;
		E[u[i]].push_back(v[i]); E[v[i]].push_back(u[i]);
	}
	memset(d, -1, sizeof(d));
	d[0] = 0; que.push(0);
	while (!que.empty()) {
		int p = que.front(); que.pop();
		for (int i : E[p]) {
			if (d[i] == -1) {
				d[i] = d[p] + 1; que.push(i);
			}
		}
	}
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		scanf("%d", &r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] - d[u[i]] == 1) {
				E[u[i]].push_back(v[i]);
			}
		}
	}
	bfs(0);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] - d[u[r[i]]] == 1 && !ok[v[r[i]]]) {
			E[u[r[i]]].push_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]]);
			}
		}
	}
	rep(i, q)printf("%d\n", ans[i]);
}

Measured memory_bytes: 14592
N,M = map(int,input().split())
A = list(map(int,input().split()))
s = set()
B = []
for a in A:
    t = a & -a
    s.add(t)
    if len(s) > 1:
        print(0)
        exit()
    B.append(a // t)

from fractions import gcd
l = 1
for b in B:
    l = b*l // gcd(b,l)

x = l*t // 2
ans = M//x - M//(2*x)
print(ans)

Measured memory_bytes: 15060
#include <bits/stdc++.h>
#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 irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n)    for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n)   for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v)  for (auto &&V : v)
#define all(x)        (x).begin(), (x).end()
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = 1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;

class UnionFind {
  std::vector<int> parent_;

  public:
  UnionFind(int size_num) : parent_(size_num, -1) {}
  int find(int x) {
    if (parent_[x] < 0) return x;
    return parent_[x] = find(parent_[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (parent_[x] > parent_[y]) std::swap(x, y);
    parent_[x] += parent_[y];
    parent_[y]  = x;
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int size(int x) {
    return -parent_[find(x)];
  }
};

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep (i, n) cin >> x[i] >> y[i];
  UnionFind uf(100001);
  unordered_map<int, int> firstx;
  rep (i, n) {
    if (firstx.find(y[i]) == firstx.end()) {
      firstx[y[i]] = x[i];
    }
    uf.unite(firstx[y[i]], x[i]);
  }
  unordered_set<lint> checkedy;
  lint cnt = 0;
  rep (i, n) {
    if (checkedy.find(y[i]) == checkedy.end()) {
      cnt += uf.size(x[i]) - 1;
      checkedy.insert(y[i]);
    } else {
      --cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 5516
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
vector<int> easy(vector<int> abc, vector<int>& input) {
    vector<int> ans(input.size());
    for (int i = 0; i < input.size(); i++) {
        int in = input[i];
        if (abc[in] >= abc[(in+1)%3]) {
            abc[in]--, abc[(in+1)%3]++;
            ans[i] = (in+1)%3;
        } else {
            abc[in]++, abc[(in+1)%3]--;
            ans[i] = in;
        }
    }
    return ans;
}
bool moveable(vector<int> abc, int in) {
    return (abc[in] != 0) || (abc[(in+1)%3] != 0);
}
vector<int> solve(vector<int> abc, vector<int>& input) {
    int sum = abc[0] + abc[1] + abc[2];
    if (!moveable(abc, input[0])) {
        return {};
    } else if (sum >= 3) {
        return easy(abc, input);
    }
    vector<array<int, 27>> dp(input.size() + 1);
    dp[0][abc[0] * 9 + abc[1] * 3 + abc[2]] = 1;
    for (int i = 0; i < input.size(); i++) {
        for (int t = 0; t < 27; t++) {
            if (dp[i][t] == 0) continue;
            int a[3] = { t / 9, t / 3 % 3, t % 3 };
            int in = input[i];
            if (a[in] > 0) {
                a[in]--, a[(in+1)%3]++;
                dp[i + 1][a[0] * 9 + a[1] * 3 + a[2]] = 2;
                a[in]++, a[(in+1)%3]--;
            }
            if (a[(in+1)%3] > 0) {
                a[in]++, a[(in+1)%3]--;
                dp[i + 1][a[0] * 9 + a[1] * 3 + a[2]] = 1;
                a[in]--, a[(in+1)%3]++;
            }
        }
    }
    int tsave = -1;
    for (int t = 0; t < 27; t++) {
        if (dp[input.size()][t] != 0) {
            tsave = t;
            break;
        }
    }
    if (tsave == -1) return {};
    vector<int> ans(input.size());
    int a[3] = { tsave / 9, tsave / 3 % 3, tsave % 3 };
    for (int i = input.size(); i > 0; i--) {
        assert(dp[i][tsave] != 0);
        int in = input[i - 1];
        if (dp[i][tsave] == 1) {
            a[in]--, a[(in+1)%3]++;
            ans[i - 1] = in;
        } else {
            a[in]++, a[(in+1)%3]--;
            ans[i - 1] = (in+1)%3;
        }
        tsave = a[0] * 9 + a[1] * 3 + a[2];
    }
    return ans;
}
int main() {
    int N; cin >> N;
    vector<int> abc(3); for (auto &x : abc) cin >> x;
    vector<int> input(N);
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        if (s == "AB") input[i] = 0;
        if (s == "BC") input[i] = 1;
        if (s == "AC") input[i] = 2;
    }
    auto ans = solve(abc, input);
    if (ans.empty()) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        for (int a : ans) cout << "ABC"[a] << '\n';
    }
    return 0;
}


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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    for (int i = 0; i < S.size(); i++) {
        int val = S[i] + N;
        if (val > 90) val -= 26;
        S[i] = val;
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import *

N,W=map(int,input().split())
d=defaultdict(int)
d[0]=0
for i in range(N):
    w,v=map(int,input().split())
    for p,q in d.copy().items():
        if p+w<=W:
            d[p+w]=max(d[p+w],q+v)
print(max(d.values()))

Measured memory_bytes: 4016
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
    ll n;
    cin>>n;
    vector<ll>a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    ll cnt=0;
    for(int i=n-1;i>=0;--i){
        if(i!=n-1)a[i]+=cnt;
        int x=a[i]%b[i];
        if(x)cnt+=b[i]-x;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1792
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll N;
    cin >> N;

    ll ans = 0;
    ll min_c = 2;
    for(ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        if(i == 0) {
            ans += a - 1;
            continue;
        }
        if(a == min_c) {
            min_c++;
            continue;
        }
        if(a % min_c == 0) {
            a -= min_c + 1;
            ans++;
        }
        ans += a / min_c;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// ITP1_2_C Sorting Three Numbers

#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  // 初期値
  vector<int> numbers(3);
  for (int i = 0; i < 3; i++){
    cin >> numbers.at(i); 
  }
  sort(numbers.begin(), numbers.end());
  
  // Main loop
  cout << numbers.at(0) << " " << numbers.at(1) << " " << numbers.at(2) << endl;
  return 0;
}


Measured memory_bytes: 3060
void main() {
	auto S = readln.split;
	int[] stack;
	foreach(i; S) {
		int num;
		try {
			num = i.to!int;
			stack ~= num;
		} catch(Exception e) {
			auto a = stack.back;
			stack.popBack;
			auto b = stack.back;
			stack.popBack;
			stack ~= i.predSwitch("+", b+a, "-", b-a, "*", b*a);
		}
	}
	stack.back.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}



Measured memory_bytes: 2604
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static int n,count;
    public static String s,w;
    public static int[] a;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        count=0;
        s=sc.next();
        s=s.toUpperCase();
        while(true){
            w=sc.next();
            if(w.equals("END_OF_TEXT")){
                System.out.printf("%d\n",count);
                sc.close();
                return;
            }
            w=w.toUpperCase();
            if(w.equals(s)) count++;
        }
    }
}


Measured memory_bytes: 26280
x = int(input())
n = x // 100
x %= 100

for i in range(n):
    if x - 5 >= 0:
        x -= 5
    elif x - 4 >= 0:
        x -= 4
    elif x - 3 >= 0:
        x -= 3
    elif x - 2 >= 0:
        x -= 2
    elif x - 1 >= 0:
        x -= 1
    else:
        break

if x == 0:
    print(1)
else:
    print(0)

Measured memory_bytes: 9188
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main()
{
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2-(y2 - y1)<< " " <<y2 + (x2 - x1) << " " << x1 - (y2 - y1 ) << " " << y1 + (x2 - x1 )<< " "  << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
#require 'pp'

n = gets.chomp!.to_i
b_n = gets.chomp!.split(" ").map(&:to_i)

sum = b_n[0]
before = b_n[0]

b_n.each_cons(2) do |i, j|
    x = [i, j].min
    sum += x
end

puts sum + b_n[-1]


Measured memory_bytes: 1788
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll target;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string str,str1,str2;
    ll i,h,w;
    ll n,x,m;
    ll a,b,d,c;
    set<string> s;
    cin>>a>>b>>x;
    for(i=a;i<=b;i++){
        if(a+x>i||b-x<i) cout<<i<<endl;
    }   


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}, M{}; std::cin >> N >> M;
  vector<ui> res(M, 0);

  rep(0, N)
  {
    ui k{}; cin >> k;
    rep_uj(0, k)
    {
      ui A{}; cin >> A;
      ++res[A - 1];
    }
  }

  auto ans = boost::accumulate(res, (ull)0, [&N](auto ans, auto res){
    return res == N ? ans + 1 : ans;
  });

  cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int a =scan.nextInt();
		int b = scan.nextInt();
		
		System.out.println(a*b);
		
	}	
	
	//�ŏ�����
	/*
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	*/
	
	//����ւ�
	/*
	static int swap (int a, int b) {
		int swap_arr[] = new int[2];
		
		swap[0] = b;
		swap[1] = a;
		
		return swap_arr;
	}
	*/
	
}

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

using namespace std;



int main() {

  int N ;cin >> N;
  long int A[N+1],B[N];
  long int ans = 0;
  for (int i = 0;i<=N;i++){
    cin >> A[i];
  }
  for (int i = 0;i<N;i++){
    cin >> B[i];
  }
               
  for (int i=0;i<N;i++){
    if (A[i]-B[i]>0){
      ans += B[i];
      A[i] = A[i] - B[i];
      B[i] = 0;
    }else{
      
      ans += A[i];
      
      B[i] = B[i] -A[i];
      A[i] = 0;
    }
    
    if(A[i+1]-B[i]>0){
      ans += B[i];
      A[i+1] = A[i+1] - B[i];
      B[i] = 0;
    }else{
      ans += A[i+1];
      
      B[i] = B[i] -A[i+1];
      A[i+1] = 0;
    }
    
    
  }
  cout << ans;
}






Measured memory_bytes: 1792
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10**9+7
X,Y = map(int,readline().split())
if X > Y:
    X,Y = Y,X
Z = X+Y
if Z % 3 == 0 and X <= Y <= 2*X:
    N = Z//3
    r = (N-(Y-X)) // 2
else:
    print(0)
    sys.exit()
f = [1]*(N+1)
for i in range(1,N+1):
    f[i] = i * f[i-1] % mod
a = pow(f[r],mod-2,mod)
b = pow(f[N-r],mod-2,mod)
ans = f[N] * a * b % mod
print(ans)
    
    

Measured memory_bytes: 29300
#include <stdio.h>

int main(){
	int S;     //秒単位の時間
	int h,m,s; //h=時間,m=分,s=秒
	scanf("%d",&S);
	h = S / 3600;  
    m = (S - h * 3600) / 60;
    s = S - (h * 3600 + m * 60);
	
	printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 2100
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
const long long mod = 1000000007;
//const long long mod = 998244353;

long long modpow(long long a, long long n) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
long long modinv(long long a) {
	return modpow(a, mod - 2);
}
int combination(int n, int k) {
	long long res = 1;
	for (int i = 0; i < k; i++) {
		res = (res*(n - i)) % mod;
		res = (res*modinv(i + 1)) % mod;
	}
	return (int)res;
}

int main() {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	long long int res = modpow(2, n) - 1;
	res = (res + 2 * mod - combination(n, a) - combination(n, b)) % mod;
	//printf("%d\n", combination(n, a));
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>
#include <memory>
#include <cassert>

#include <map>
#include <vector>
#include <queue>


using namespace std;

typedef long long LL;

struct A {
    int num, yr;
    A(int _num, int _yr){num=_num;yr=_yr;}
};

inline bool cmp(const A &x, const A &y) {
    return x.yr < y.yr;
}

int pos[100010], belong[100010];

vector<A> a[100010];

int n, m;

int main() {
    cin >> n >> m;

    for (int i = 1, p, k; i <= m; ++i) {
        scanf("%d%d", &p, &k);
        belong[i] = p;
        a[p].push_back(A(i,k));

    }
    for (int i = 1; i <= n; ++i) {
        sort(a[i].begin(), a[i].end(), cmp);
        int l = a[i].size();
        for (int j = 0; j < l; ++j) {
            pos[a[i][j].num] = j + 1;
        }
    }
    for (int i = 1; i <= m; ++i) {
        printf("%06d%06d\n", belong[i], pos[i]);
    }
}

Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  int n, k;
  cin >> n >> k;
  int cs[100101] = {};
  int h[100101] = {};
  rep(i, 1, n) cs[i] = 1145141919;
  rep(i, 0, n) cin >> h[i];

  rep(i, 0, n) {
    rep(j, 1, k + 1) {
      cs[i + j] = min(cs[i + j], cs[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << cs[n - 1] << endl;
}


Measured memory_bytes: 1792
ABC = [list(input()) for i in range(3)]
turn = 0
while True:
#    print(ABC)
    if len(ABC[turn])==0:
        break
    Aturn = ABC[turn].pop(0)
    if Aturn == "a":
        turn = 0
    elif Aturn == "b":
        turn = 1
    else: turn = 2
if turn == 0:
    print("A")
elif turn == 1:
    print("B")
else: print("C")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	string a,b;
	cin >> a >> b;
	if(a[0]==b[0]){
		cout << "H" << endl;
	}
	else{
		cout << "D" << endl;
	}
}

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

int main(){
  int N, T, L, B;
  while(cin >> N >> T >> L >> B && N>0){
    bool lose[100], back[100];
    for(int i=0;i<100;i++) lose[i]=back[i]=false;
    
    int index;
    
    for(int i=0;i<L;i++){
      cin >> index;
      lose[index]=true;
    }
    for(int i=0;i<B;i++){
      cin >> index;
      back[index]=true;
    }

    double p[101][101];
    for(int i=1;i<=N;i++){
      p[i][0]=0.0;
      p[i][1]=(i<=6)?(1.0/6.0):0.0;
    }

    for(int tn=2;tn<=T;tn++){
      for(int lg=1;lg<=N;lg++){
	double pr=0.0;
	for(int i=1;i<=6;i++){
	  int to=abs(lg-i);
	  if(to==0)
	    pr+=1.0;
	  else if(back[N-to])
	    pr+=p[N][tn-1];
	  else if(lose[N-to])
	    pr+=p[to][tn-2];
	  else
	    pr+=p[to][tn-1];
	}
	p[lg][tn]=pr/6.0;
      }
    }
    cout << fixed << p[N][T] << endl;
  }

  return 0;
}

Measured memory_bytes: 3268
#include <iostream>
#include <unordered_map>
#include <utility>
using namespace std;

int main() {
	int N;
	cin >> N;
	unordered_map<int, long> a;
	for (int i = 1; i <= N; i++) {
		int b = i;
		for (int j = 2; j * j <= b; j++) {
			while (b % j == 0) {
				a[j]++;
				b /= j;
			}
		}
		if (b != 1) a[b]++;
	}
	long ans = 1;
	for (pair<const int, long>& i : a) {
		ans *= i.second + 1;
		ans %= 1000000007;
	}
	cout << ans;
}

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

int main() {
	int n;
	std::cin >> n;
	std::vector<int> c(n - 1), s(n - 1), f(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		std::cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 0; i < n - 1; ++i) {
		int now = 0;
		for (int j = i; j < n - 1; ++j) {
			if (now < s[j]) now = s[j];
			if (now%f[j] != 0) {
				int t = now / f[j];
				now = (t + 1) * f[j];
			}
			now += c[j];
		}
		std::cout << now << std::endl;
	}
	std::cout << 0 << std::endl;
	return 0;
}

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

int main(){
  while(1){
  int h,w;
  cin >> h >> w;
  if(h == 0 && w ==0) break;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cout << "#";
    }
    cout << endl;
  }
  cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string a, b; cin >> a >> b;
  string ab = a + b;
  int x = stoi(ab);
  
  vi check;
  repi(i,1,400) check.push_back(i*i);
  
  cout << (count(all(check),x) ? "Yes" : "No") << endl; 
}

Measured memory_bytes: 256
s = input()

keta = []
for i in range(len(s)):
    keta.append(int(s[-(i+1)]))

ans = 0
for j in range(len(s)):
    ans += (10**j)*(keta[0]*(2**(len(s)-j-1))+(sum(keta)-keta[0])*(2**(len(s)-j-2)))
    keta = keta[1:]

print(int(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 250;
int n, p;
int a[N], b[2 * N], x[2 * N], dp[2][N + 1];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> p;
    for (int i = 0, j = n - 1; i < n; ++i) {
        while (i * i + j * j >= n * n)
            --j;
        a[i] = j + 1;
    }
    for (int i = 0, j = 2 * n - 1; i < 2 * n; ++i) {
        while (i * i + j * j > 4 * n * n)
            --j;
        b[i] = j + 1;
    }
    int ans = 0;
    iota(x, x + 2 * n, 0);
    reverse(x, x + 2 * n);
    stable_sort(x, x + 2 * n, [&](int i, int j) {return (i < n ? a[i] : b[i]) < (j < n ? a[j] : b[j]);});
    for (int k = 0; k <= n; ++k) {
        int cur = 0;
        memset(dp[0], 0, (k + 1) * sizeof(int));
        dp[0][0] = 1;
        int cnt = 0;
        for (int i = 0; i < 2 * n; ++i) {
            if (x[i] < n) {
                cur ^= 1;
                memset(dp[cur], 0, (k + 1) * sizeof(int));
                for (int j = 0; j <= k; ++j) {
                    dp[cur][j] = (dp[cur][j] + 1LL * dp[cur ^ 1][j] * (b[x[i]] - (n + cnt + k - j))) % p;
                    if (j < k)
                        dp[cur][j + 1] = (dp[cur][j + 1] + 1LL * dp[cur ^ 1][j] * (a[x[i]] - (i - cnt + j))) % p;
                }
                ++cnt;
            } else {
                for (int j = 0; j <= k; ++j)
                    dp[cur][j] = 1LL * dp[cur][j] * (b[x[i]] - (i - (cnt - j))) % p;
            }
        }
        ans = (ans + (k % 2 == 0 ? 1 : -1) * dp[cur][k]) % p;
    }
    ans = (ans + p) % p;
    cout << ans << endl;
    return 0;
}

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

object Main extends App {
  val Array(r, g, b, n) = in.readLine.split(" ").map(_.toInt)

  var cnt = 0
  for {
    i <- 0 to n/r
    j <- 0 to n/g
    k = n - r*i - g*j
    if 0 <= k
  } {
    if(k == 0 && r*i + g*j == n) {
      cnt += 1
      debug(i,j,k)
    }
    else if(k%b == 0 && (r*i + g*j + k) == n) {
      cnt += 1
      debug(i,j,k)
    }
  }

  val ans = cnt
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString != "class Main$")
      println(any.mkString(" "))
  }
}

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

using namespace std;

int main(){
    int n,flag=0;
    cin>>n;
char s[n];
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<n;i++){
    flag=0;
if(s[i]=='Y'){
    flag=1;
    break;
}}
if (flag==1)
    cout<<"Four";
else
    cout<<"Three";
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
#include "math.h"
using namespace std;
    
int main(){
    int n, i, sum = 0, ans=INT_MAX, l, r;
    vector<int> x;
    cin >> n;
    for(i=0;i<n;i++) {
        int num;
        cin >> num;
        x.push_back(num);
    }
    sort(x.begin(), x.end());
    l=*x.begin();
    r=*(--x.end());
    for(int i=l;i<=r;i++){
        for(int j=0;j<x.size();j++) sum += pow(x[j]-i, 2);
        if(ans>sum) ans = sum;
        sum=0;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

int const MaxSize = 3e5 + 10;
int N, M, K;

int main() {
	ios_base::sync_with_stdio(false);
//	freopen("/Users/george/A_1.in", "r", stdin);
	cin >> N >> M >> K;

	LPE(r, 0, N)
	{
		LPE(c, 0, M)
		{
			int fullRows = r * M;
			int fullCols = c * N;

			int overlaps = r * c;

			int patch = fullRows + fullCols - 2 * overlaps;
			//cout << r << " " << c << " " << patch << endl;

			if (patch == K || (N * M - patch) == K) {
				cout << "Yes";
				return 0;
			}

		}
	}

	cout << "No";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << "\n";
    return 0;
}

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

#define                      ff                                          first
#define                      ss                                          second
#define                      pai                                         acos(-1)
#define                      ll                                          long long
#define                      pb                                          push_back
#define                      mp                                          make_pair
#define                      pll                                         pair<ll,ll>
#define                      sz(a)                                       (ll)a.size()


double dis(double x,double y)
{
    return sqrt((x*x)+(y*y));
}
int  main(int argc, char const *argv[])
{
    ll i,j,k,a,b,c,d,n,m,t,h,u,v,x,y,z;
    cin>>n;
    cout<<(n%1000?(1000-(n%1000)):0)<<endl;

    return 0;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int N, M;
int d, p, L, s, c;
pair<int, int> x[10000];
int main()
{
	while(cin >> N >> M && N!=0)
	{
		L=0;
		for(int i=0; i<N; i++)
		{
			cin >> d >> p;
			x[i]=make_pair(p, d);
			L+=d;
		}
		sort(x, x+N);
		s=0;
		if(M<L)
		{
			c=0;
			for(int i=0; i<N; i++)
			{
				if(c+(x[i].second)>=L-M)
				{
					s+=(L-M-c)*(x[i].first);
					c+=x[i].second;
					break;
				}
				else
				{
					s+=(x[i].second)*(x[i].first);
					c+=x[i].second;
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

bool cmp(int x,int y) {
	return x>y;
}

int a[101];

int main() {
	int n;
	cin>>n;
	int ans1=0,ans2=0;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) {
		if(i%2!=0) ans1+=a[i];
		if(i%2==0) ans2+=a[i];
	}
	cout<<ans1-ans2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int ng[16][16];

int rec(int x, int y){
    if(ng[x][y]) return 0; //工事中なら0
    if(x == 0 && y == 0) return 1; //スタート地点なら1
    if(x == 0) return rec(0, y-1);
    if(y == 0) return rec(x-1, 0);
    return rec(x-1, y) + rec(x, y-1);
}

int main(void){
    int h, w, n, x, y, a, b;
    // && は and, || は or
    while(scanf("%d%d", &h, &w) && (h||w)){ // h, wがともに0なら終了
        h--; w--; // デクリメント(1減らす)
        // 配列を初期化
        for(x = 0; x <= h; x++){
            for(y = 0; y <= w; y++){
                ng[x][y] = 0;
            }
        }
        scanf("%d", &n);
        // 工事中の場所の入力をとり、そこを記録する
        for(x = 0; x < n; x++){
            scanf("%d%d", &a, &b);
            ng[a-1][b-1] = 1;
        }
        printf("%d\n", rec(h, w));
    }
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001
//0=48,A=65,a=97
 
int main(){
  int n;cin >> n;
  vector<int> a(3*n);for(int i=0;i<3*n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  ll ans=0;
  for(int i=n;i<3*n;i+=2) ans+=a[i];
  
  cout << ans;
}

Measured memory_bytes: 4264
#include "bits/stdc++.h"
using namespace std;
using ll = long long;


int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	vector<ll> sum(n + 1);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		sum[a[i]]++;
	}
	vector<ll> ans1(n + 1);
	vector<ll> ans2(n + 1);
	for (ll i = 1; i < n+1; i++) {
		ans1[i] = sum[i] * (sum[i] - 1) / 2;
		if (sum[i] != 0) {
			ans2[i] = (sum[i] - 1) * (sum[i] - 2) / 2;
		}
		else {
			ans2[i] = 0;
		}
	}
	
	ll s = 0;
	for (ll i = 0; i < n+1; i++) {
		s += ans1[i];
	}
	for (ll i = 0; i < n; i++) {
		cout << s - ans1[a[i]] + ans2[a[i]] << endl;
	}
	return 0;
}


Measured memory_bytes: 9600
H,W=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
A=[list(map(int,input().split())) for _ in range(H)]

from itertools import product

for k,i,j in product(range(10),repeat=3):
    if c[i][j] > c[i][k]+c[k][j]:
        c[i][j] = c[i][k]+c[k][j]
ans=0

for i,j in product(range(H),range(W)):
    if A[i][j]!=-1:
        ans+=c[A[i][j]][1]
print(ans)


Measured memory_bytes: 40668