akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        int s = Integer.parseInt(sc.next());
        int p = Integer.parseInt(sc.next());
        char[] t = sc.next().toCharArray();

        // 主処理
        int result = 0;
        for (int i = 0; i < t.length; i++) {
            if (k <= i && t[i - k] == t[i]) {
                t[i] = 'o';
                continue;
            }
            if (t[i] == 'r') {
                result += p;
            } else if (t[i] == 's') {
                result += r;
            } else {
                result += s;
            }
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 26776
<?php
fscanf(STDIN, "%d %d", $n, $m);
$d = $n - $m + 1;
for ($i = 0; $i < $n; $i++) {
	fscanf(STDIN, "%s", $a[]);
}
for ($i = 0; $i < $m; $i++) {
	fscanf(STDIN, "%s", $s);
	$b[] = str_replace('.', '\.', $s);
}
$a = implode('/', $a);
$b = implode('.{' . $d. '}', $b);
echo preg_match("/$b/", $a) ? 'Yes' : 'No';

Measured memory_bytes: 3960
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>
#include <iomanip>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(ll i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vc = vector<char>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
const ll MOD = 1e9 + 7;
set<char> alphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z' };

int main() {
    int N;
    cin >> N;
    vi ans;
    vvvi xy(N, vvi(17));
    vi Aa(N);
    rep(i, N) {
        int A;
        cin >> A;
        Aa[i] = A;
        rep(j, A) {
            int x, y;
            cin >> x >> y;
            x--;
            xy[i][j].push_back(x);
            xy[i][j].push_back(y);
        }
    }
    for (int bit = 0; bit < (1 << N); ++bit) {
        int counter = 0;
        bool frag = true;
        for (int i = 0; i < N; ++i) {
            if (bit & (1 << i)) {
                counter++;
                rep(j, Aa[i]) {
                    if (xy[i][j][1] == 1) {
                        if (!(bit & (1 << (xy[i][j][0])))) frag = false;
                    }
                    else {
                        if (bit & (1 << (xy[i][j][0]))) frag = false;
                    }
                }
            }
        }
        if (frag) {
            ans.push_back(counter);
        }
    }
    ans.push_back(0);
    sort(ans);
    riverse(ans);
    cout << ans[0] << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int days = 0;
  for (int i = 0; i < m; i++){
    int a;
    cin >> a;
    days = days+a;
  }
  if (days <= n){
    cout << n - days << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3604
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cstdlib>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/

int d[410][410];

int main()
{
	int n, ma, mb, x, y, z;
		
	scanf("%d%d%d", &n, &ma, &mb);
	memset(d, 0x3f, sizeof d);
	d[0][0] = 0;
	for (int i = 0; i < n; i++){
		scanf("%d%d%d", &x, &y, &z);
		for (int j = 408; j >= x; j--){
			for (int k = 408; k >= y; k--){
				d[j][k] = min(d[j - x][k - y] + z, d[j][k]);
			}
		}
	}
	int ans = 0x3f3f3f3f;
	for (int i = mb; i <= 400; i += mb){
		if (i % ma == 0){
			ans = min(ans, d[i / mb][i / ma]);
		}
	}
	if (ans == 0x3f3f3f3f){
		puts("-1");
	} else {
		printf("%d\n", ans);
	}
}

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

int main(){
    int h,w,k; cin >> h >> w>> k;
    string c[h]; rep(i,h) cin >> c[i];

    int ans = 0;
    rep(mask_h,1<<h) rep(mask_w, 1<<w){
        int ctr = 0;
        rep(i, h) rep(j,w){
            if ((mask_h&(1<<i)) && ((mask_w>>j) & 1) && c[i][j]=='#')ctr++;
        }
        if (ctr == k) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, vector<T> const& v) {
  os << "[";
  for (size_t i = 0; i < v.size(); i++) {
    os << (i == 0 ? "" : ",") << v[i];
  }
  return os << "]";
}
template<typename S, typename T>
ostream& operator<<(ostream& os, pair<S, T> const& v) {
  return os << "<" << v.first << "," << v.second << ">";
}

typedef int64_t I;
typedef vector<I> vI;
typedef vector<vI> vvI;
typedef pair<int, int> II;
typedef vector<II> vII;

vI colw(vvI const& s, I x, vII const& segs) {
  vI r(segs.size());
  for (size_t i = 0; i < segs.size(); i++) {
    I y0 = segs[i].first, y1 = segs[i].second;
    for (I y = y0; y < y1; y++) {
      r[i] += s[y][x];
    }
  }
  return r;
}

bool add_check(vI &sums, vI const& col, I k) {
  for (size_t i = 0; i < sums.size(); i++) {
    sums[i] += col[i];
    if (sums[i] > k) return false;
  }
  return true;
}

I sub(vvI s, I w, I k, vII const& segs) {
  I l = segs.size();
  I r = 0;
  vI sums(l, 0);
  for (I x = 0; x < w; x++) {
    vI col = colw(s, x, segs);
//    cerr << "x=" << x << ",col=" << col << ",sum=" << sums << endl;
    if (!add_check(sums, col, k)) {
      for (size_t i = 0; i < col.size(); i++)
        if (col[i] > k) return w + 1000;
      r++;
      sums.swap(col);
    }
  }
  return r + segs.size() - 1;
}

I solve(vvI const& s, I h, I w, I k) {
  if (h == 0) {
    vII segs(1, II(0, 1));
    return sub(s, w, k, segs);
  }
  I m = h + w;
  for (I v = 0; v < (1 << (h - 1)); v++) {
    vII segs;
    I y0 = 0, y = 1;
    while (y < h) {
      if ((v & (1 << (y - 1))) != 0) {
        segs.push_back(II(y0, y));
        y0 = y;
      }
      y++;
    }
    if (y0 != y) {
      segs.push_back(II(y0, y));
    }
//    cerr << "v=" << v << ",segs=" << segs << endl;
    m = min(m, sub(s, w, k, segs));
  }
  return m;
}

int main() {
  I h, w, k; cin >> h >> w >> k;
  vvI s(h, vI(w));
  for (I y = 0; y < h; y++) {
    string str; cin >> str;
    for (I x = 0; x < w; x++) {
      s[y][x] = str[x] - '0';
    }
  }
  cout << solve(s, h, w, k) << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,k,x,ans=0;scanf("%d%d%d%d",&a,&b,&c,&k);
	x=min(a,k),k-=x,ans+=x;
	x=min(b,k),k-=x;
	ans-=k;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3812
"use strict";
function main(input) {
  const args = input.split('\n');
  const size = input.split(' ');
  const h = parseInt(size[0], 10);
  const w = parseInt(size[1], 10);
  const s = [];

  for (let i = 0; i < h; i += 1) {
    s[i] = [];
    let input = args[i];
    for (let j = 0; j < w; j += 1) {
      s[i][j] = input[j];
    }
  }
  s[-1] = [];
  s[h] = [];

  for (let i = 0; i < h; i += 1) {
    for (let j = 0; j < w; j += 1) {
      if (s[i][j] === '#') {
        if (s[i-1][j] !== '#' && s[i+1][j] !== '#' &&
            s[i][j-1] !== '#' && s[i][j+1] !== '#') {
          console.log('No');
          return;
        }
      }
    }
  }
  console.log('Yes');
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 105
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int cnt[maxn][35];
int n;
string a,b,c;
int main(){
	cin >> n;
	cin >> a >> b >> c;
	for(int i=0;i<n;i++){
		cnt[i][a[i] - 'a']++;
		cnt[i][b[i] - 'a']++;
		cnt[i][c[i] - 'a']++;
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		int res = 0;
		for(int j=0;j<26;j++){
			res = max(res,cnt[i][j]);
		}
		ans += 3 - res;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input};

use std::cmp::Reverse;

#[fastout]
fn main() {
    input!(n: usize, mut l: [isize; n]);
    let mut count = 0;
    l.sort_unstable_by_key(|&x| Reverse(x));

    for i in 0..n {
        for j in i + 1..n {
            let a1 = l[i] - l[j];
            let a2 = l[j] - l[i];
            let a3 = l[i] + l[j];
            for k in j + 1..n {
                if !(l[k] < a3) {
                    break;
                }
                if a1 < l[k] && a2 < l[k] {
                    count += 1;
                }
            }
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int ans=0;
  int mi=10;
  for(int i=0;i<5;i++){
    int a;
    cin>>a;
    if(a%10==0){
	 ans+=a;
	 continue;
    }
    mi=min(a%10,mi);
    a+=10-a%10;
    ans+=a;
  }
  cout<<ans-10+mi<<endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]

res=any([r[j:j+m] for r in a[i:i+m]]==b for i in range(n-m+1) for j in range(n-m+1))
print('Yes' if res else 'No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (i%d == 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#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) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

int n, m; // number of nodes, edges

vvi edge;
vvi g;
vi prenum;
vi lowest;
vi parent;
int timer;

void lowlink_dfs(int u, int prev) {
  prenum[u] = timer;
  lowest[u] = timer;
  timer += 1;

  for (auto v : g[u]) {
    if (prenum[v] < 0) {
      parent[v] = u;
      lowlink_dfs(v, u);
      lowest[u] = min(lowest[u], lowest[v]);
    } else if (v != prev) {
      lowest[u] = min(lowest[u], prenum[v]);
    }
  }
}

void lowlink() {
  prenum.assign(n, -1);
  lowest.assign(n, 0);
  parent.assign(n, 0);
  timer = 0;
  lowlink_dfs(0, -1);
}

// call after lowlink()
set<pii> bridge() {
  set<pii> ret;
  FOR(i, 1, n) {
    if (prenum[parent[i]] < lowest[i]) {
      int mi = min(parent[i], i);
      int ma = max(parent[i], i);
      ret.insert(make_pair(mi, ma));
    }
  }
  return ret;
}


int main() {
  scanf("%d %d", &n, &m);
  edge.assign(m, vi(2, 0));
  g.resize(n);
  rep (i, m) {
    int s, t;
    scanf("%d %d", &s, &t);
    if (s > t) {
      swap(s, t);
    }
    edge[i][0] = s;
    edge[i][1] = t;
    g[s].push_back(t);
    g[t].push_back(s);
  }
  sort(all(edge));
  lowlink();
  auto ans = bridge();
  for (auto p : ans) {
    printf("%d %d\n", p.first, p.second);
  }

  return 0;
}

Measured memory_bytes: 7420
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(LL N) {
    double ans = log10(N) / log10(3);
    if ((double)(int)ans != ans) 
        cout << (int)ans + 1 << endl;
    else
        cout << (int)ans << endl;
    return;
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        return 0;
    }
}

Measured memory_bytes: 3380
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

int ans;

class EAntennasOnTree {
public:

    vector<int> graph[100005];
    vector<int> used;
    vector<int> mi, ma;

    void dfs(int p) {
      used[p] = true;
      int cnt = 0;
      int masum = 0;
      int madiff = 0;
      for(auto q: graph[p]) {
        if (used[q]) continue;
        dfs(q);
        cnt++;
        masum += ma[q];
        chmax(madiff, ma[q]-mi[q]);
      }
      if (cnt==0) {
        mi[p] = 0;
        ma[p] = 1;
        return;
      }
      if (cnt==1) {
        mi[p] = masum-madiff;
        ma[p] = masum;
        return;
      }
      mi[p] = masum - madiff;
      ma[p] = masum - madiff;
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      used.resize(n);
      mi.resize(n); ma.resize(n);
      vector<int> deg(n);
      rep(i, n-1) {
        int a, b; cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
        deg[a]++; deg[b]++;
      }
      rep(i, n) {
        if (deg[i] >= 3) {
          dfs(i);
          cout << ma[i] << endl;
          return;
        }
      }
      cout << 1 << endl;
    }
};

signed main() {
  EAntennasOnTree solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main()
{
    string S;
    cin >> S;
    int sum=0;
    long int N=0;
    for(auto i=0; i<S.length(); i++){
        sum += S[i] - '0';
        N += (S[i] - '0') * pow(10, S.length()-(i+1));
    }
    if(N%sum==0) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
template<class T>inline bool chmax(T& a, T b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T& a, T b){if(a > b){a = b; return 1;}return 0;}
const ll INF = 1LL<<60;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


ll GCD(ll a, ll b){
    if(a < 0) a = -a;
    if(b < 0) b = -b;
    if(b == 0) return a;
    else return GCD(b, a%b);
}
void solve(){
    ll n, x; cin >> n >> x;
    ll res;
    vector<ll> v(n);
    REP(i, n){
        ll xin; cin >> xin;
        v[i] = abs(x - xin);
    }
    res = v[0];
    REP(i, n){
        res = GCD(v[i], res);
    }
    cout << res << endl;
}

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

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

int main(){
  int i,j,cnt=0;
  int n,m;
  cin>>n>>m;
  int a[m],b[m];
  for(i=0;i<m;i++)cin>>a[i]>>b[i];
  int c[m],d[m];
  for(i=0;i<m;i++){
    if(a[i]==1){
      c[cnt]=b[i];
      cnt++;
    }
  }
  if(cnt==0){
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }
  int p=cnt;cnt=0;
  for(i=0;i<m;i++){
    if(b[i]==n){
      d[cnt]=a[i];
      cnt++;
    }
  }
  if(cnt==0){
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }
  int q=cnt;cnt=1;
  sort(c,c+p);
  sort(d,d+q);
  int e[p],f[q];
  e[0]=c[0];
  for(i=1;i<p;i++)if(c[i]!=c[i-1])e[cnt++]=c[i];
  p=cnt;cnt=1;
  f[0]=d[0];
  for(i=1;i<q;i++)if(d[i]!=d[i-1])f[cnt++]=d[i];
  q=cnt;cnt=0;
  int g[200001];
  for(i=0;i<=200000;i++)g[i]=0;
  for(i=0;i<p;i++)g[e[i]]++;
  for(i=0;i<q;i++)g[f[i]]++;
  for(i=0;i<=200000;i++){
    if(g[i]==2){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
int main()
{
    ll n,res=0,x=1,y=1,z=1;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        x*=10;
        x%=mod;
        y*=9;
        y%=mod;
        z*=8;
        z%=mod;
    }
    res=x-2*y+z;
    res%=mod;
    if(res<0)
    res+=mod;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3632
def solve(N, x, As):
    ans = max(0, As[0] - x)
    As[0] -= ans
    for i in range(0, N - 1):
        d = As[i] + As[i + 1]
        ans += max(0, d - x)
        As[i + 1] -= max(0, d - x)
    return ans


if __name__ == "__main__":
    N, x = map(int, input().split(" "))
    As = list(map(int, input().split(" ")))
    print(solve(N, x, As))


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

int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;

	int ans = gcd(a[0], a[1]);
	for (int i = 2; i < n; i++) {
		ans = gcd(ans, a[i]);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int d[n];
  for(int i(0);i<n;i++){
    cin>>d[i];
  }
  int f[n]={0};
  int cnt(0);
  for(int i(0);i<n;i++){
    if(f[i]==0){
      cnt++;
      for(int j(i);j<n;j++){
        if(d[i]==d[j])f[j]++;
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int n, in, ans = 0;
	cin >> n;
	vs vv(n);
	rep(i, n) {
		cin >> vv[i];
	}
	rep(k, n) {
		bool s = true;
		//cout << endl << k << endl;
		rep(i, n) {
			rep(j, n) {
				int x, y;
				x = (j + k) % n;
				y = i%n;
				//if (i != j)cout << vv[i][(j + k) % n] << " " << vv[j][(i+k)%n] << endl;
				if (i != j&&vv[i][(j + k) % n] != vv[j][(i + k) % n])s = false;
			}
		}
		if (s) ans++;
	}
	cout << ans*n << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main( int argc, char **argv )
{
    int ibuf1=0, ibuf2=0;
    const int n = scanf( "%d %d", &ibuf1, &ibuf2 );
    if ( n != 2 )
    {
        printf("Error: Wrong number of arguments\n");
    }

    if ( ( ibuf1 % 2 ) != ( ibuf2 % 2 ) )
    {
        printf("IMPOSSIBLE\n");
    } else {
        printf(" %d\n", (ibuf1+ibuf2)/2 );
    }

    exit(0);
}

Measured memory_bytes: 128
N=int(input())
txy = [list(map(int,input().split())) for _ in range(N)]

txy.insert(0,[0,0,0])

flag = 0

for n in range(1,N+1):
  if txy[n][0] % 2 != (txy[n][1] + txy[n][2])%2 or \
  abs(txy[n][0] - txy[n-1][0]) < abs(txy[n][1] - txy[n-1][1]) + abs(txy[n][2] - txy[n-1][2]):
    flag = 1
    break

if flag == 0:
  print("Yes")
else:
  print("No")

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

const int N = (int) 1e5 + 5;

int n;
int a[N], b[N];

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + 1 + n);
	long long ans = 0, res = 0;
	int i;
	if (n & 1) {
		// case1:
		int posOne, posTwo, negOne, negTwo;
		posOne = 2, posTwo = (n - 2) / 2, negTwo = n - posTwo - posOne;
		i = n; res = 0;
		for (; i >= (n - posTwo + 1); i--) res += 2 * a[i];
		res += a[i]; i--; res += a[i]; i--;
		for (; i >= 1; i--) res -= 2 * a[i];
		ans = max(ans, res);
		// case2:
		negOne = 2, negTwo = (n - 2) / 2, posTwo = n - negOne - negTwo;
		i = n; res = 0;
		for (; i >= (n - posTwo + 1); i--) res += 2 * a[i];
		res -= a[i]; i--; res -= a[i]; i--;
		for (; i >= 1; i--) res -= 2 * a[i];
		ans = max(ans, res);
		cout << ans << "\n";
	} else {
		int negOne = 1, posOne = 1, negTwo = (n - 2) / 2, posTwo = (n - 2) / 2;
		i = n; res = 0;
		for (; i >= (n - posTwo + 1); i--) res += 2 * a[i];
		res += a[i]; i--; res -= a[i]; i--;
		for (; i >= 1; i--) res -= 2 * a[i];
		ans = max(ans, res);
		cout << ans << "\n";
	}
	return 0;
}

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

using namespace std;

using ll = long long;
const int N = 101;
int b[N];

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
        cin >> b[i];
    }
    ll ans = 0;
    b[n] = 1e9;
    for (int i = n - 1; i >= 1; i--) {
        ans += min(b[i], b[i + 1]);
    }
    ans += b[1];
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
const int MAX = 1000000;
const int MOD = 1000000007;
 
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
 
int main(){
 int n, k;
 cin >> n >> k;
 vector<ll>h(n);
 if(n<k)k=n;
 rep(i, 0, n)cin >> h[i];
 sort(h.begin(),h.end(),greater<ll>());
 ll ans = 0;
 rep(i, 0, n){
   if(k>0){
     k--;
   }else{
     ans += h[i];
   }
 }
 cout << ans << endl;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  for (int i=0;i<=b;i++) {
    if((a*i)%b == c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;

}


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

int main() {
    int x, y;
    cin >> x >> y;

    if (x == y) {
        cout << -1 << endl;
    } else if (x > y) {
        if (x % y == 0) {
            cout << -1 << endl;
        } else {
            for (int i = 2; i < 100; i++) {
                if ((x * i) % y != 0) {
                    cout << (x * i) << endl;
                    break;
                }
            }
        }
    } else {
            for (int i = 2; i < 100; i++) {
                if ((x * i) % y != 0) {
                    cout << (x * i) << endl;
                    break;
                }
            }
    }

}

Measured memory_bytes: 256
fun main() {
    val s = readLine()!!.toInt()
    val mod = 1_000_000_000 + 7
    val dp = Array(2001) { 0 }
    dp[3] = 1
    for (i in 4..s) {
        dp[i] = (dp[i-3] + dp[i-1]) % mod
    }
    println(dp[s])
}

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

def selectionSort(A, N):
    cnt = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if A[i] != A[minj]:
            A[i], A[minj] = A[minj], A[i]
            cnt += 1
    return A, cnt

result = selectionSort(a, n)
print(' '.join(map(str, result[0])))
print(result[1])


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

int main() {
  int N;
  cin >> N;
  int cnt_max = 1000000000;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    int cnt = 0;
    while (a % 2 == 0){
      cnt++;
      a /= 2;
    }
    if (cnt_max > cnt) cnt_max = cnt;
  }
  cout << cnt_max << endl;
}


Measured memory_bytes: 256
def solve():
    N,M,X = map(int,input().split())
    C = []
    A = []
    for i in range(N):
        val = list(map(int,input().split()))
        C.append(val[0])
        A.append(val[1:])
    
    ans = float('inf')
    for i in range(1 << N):
        money = 0
        points = [0] * M
        for j in range(N):
            if (i >> j) & 1:
                money += C[j]
                for k in range(M):
                    points[k] += A[j][k]
        
        for j in range(M):
            if points[j] < X:
                break
        else:
            ans = min(ans,money)

    print(ans if ans != float('inf') else -1)


                
if __name__ == '__main__':
    solve()

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

static const int MMAX=20;
static const int NMAX=50000;
static const int INFTY=(1<<29);

main(){
	int n,m;
	int C[21];
	int T[NMAX+1];
	
	cin>>n>>m;
	
	for(int i=1;i<=m;i++){
		cin>>C[i];
	}
	for(int i=0;i<=NMAX;i++)T[i]=INFTY;
	T[0]=0;
	for(int i=1;i<=m;i++){
		for(int j=0;j+C[i]<=n;j++){
			T[j+C[i]]=min(T[j+C[i]],T[j]+1);
		}
	}
	
	cout<<T[n]<<endl;
	
	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, t[1000], a[1000];
ll x, y;

int main() {
	cin >> n;
	rep(i,n) cin >> t[i] >> a[i];
	
	x = t[0], y = a[0];
	reps(i,1,n) {
		ll n = max((x+t[i]-1)/t[i], (y+a[i]-1)/a[i]);
		x = n*t[i], y = n*a[i];
	}
	cout << x+y << ln;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int gotiusa_is_god;
    while (cin>>gotiusa_is_god,gotiusa_is_god) {
        int w,h; cin>>w>>h;
        vector<vector<int>>v(h,vi(w,0));
        rep(_,gotiusa_is_god){
            pii tiya; cin>>tiya.first>>tiya.second;
            v[--tiya.second][--tiya.first]=1;
        }
        int range_x,range_y;
        cin>>range_x>>range_y;
        int ans=-INF;
        rep(i,h){
            rep(j,w){
                if(i+range_y>h||j+range_x>w)continue;
                int gotiusa=0;
                for(int k=i; k<i+range_y;k++)
                    for(int l=j; l<j+range_x;l++)
                        if(v[k][l])gotiusa++;
                cmax(ans,gotiusa);
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define ms(arr , val) memset(arr , val , sizeof(arr))
#define siz(temp) temp.size()
#define len(temp) temp.length()
#define timepass 1073741824
#define int ll

bool myfunc(pair<int , int> a , pair<int , int> b)
{
    return (a.s < b.s);
}
signed main()
{
    FAST;
    int n;
    cin >> n;
    vector<pair<int , int > > x(100001),y(100001);
    for (int i = 0 ; i < 100001 ; i++)
        x[i].s = y[i].s = i;
    rep(i , 0 , n)
    {
        int a;
        cin >> a;
        //cout << a << endl;
        if (i % 2 == 0)
            x[a].f++;
        else
            y[a].f++;
    }
    // for (int i = 1 ; i <= 10 ; i++)
    //     cout << x[i].f << " " << x[i].s << endl;
    // for (int i = 1 ; i <= 10 ; i++)
    //     cout << y[i].f << " " << y[i].s << endl;
    sort(all(x));
    reverse(all(x));
    sort(all(y));
    reverse(all(y));
    // for (int i = 1 ; i <= 10 ; i++)
    //     cout << x[i].f << " " << x[i].s << endl;
    // for (int i = 1 ; i <= 10 ; i++)
    //     cout << y[i].f << " " << y[i].s << endl;
    // cout << x[0].f << " " << x[0].s << endl;
    // cout << x[1].f << " " << x[1].s << endl;
    // cout << y[0].f << " " << y[0].s << endl;
    // cout << y[1].f << " " << y[1].s << endl;
    if (x[0].s != y[0].s)
    {
        cout << n - x[0].f - y[0].f << endl;
    }
    else
    {
        if (x[1].f == 0 && y[1].f == 0)
            cout << n / 2 << endl;
        else if (x[1].f == 0)
            cout << n - x[0].f - y[1].f << endl;
        else if (y[1].f == 0)
            cout << n - y[0].f - x[1].f << endl;
        else
            cout << min(n - x[0].f - y[1].f , n - y[0].f - x[1].f) << endl;
    }
    return 0;
}


Measured memory_bytes: 3456
x,y=map(int,input().split())
c1=[]
c2=[]
for i in range(y):
    c1.append(x)
for i in range(x):
    c2.append(y) 
ans=[]       

for i in range(min(x,y)):
    if c1[i]<c2[i]:
        ans=c1
        break    
    elif c1[i]>c2[i]:
        ans=c2
        break

if ans==[]:
    if x<y:
        for i in range(len(c1)):
            print(c1[i],end="")    
    else:
          for i in range(len(c2)):
            print(c2[i],end="")  
else:
       for i in range(len(ans)):
            print(ans[i],end="")            

Measured memory_bytes: 3064
// Vicfred
// https://atcoder.jp/contests/abc129/tasks/abc129_b
// brute force
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    const long n = readln.chomp.to!long;
    const long[] ws = readln.split.map!(to!long).array;

    long[] sum = new long[n];
    sum[0] = ws[0];
    foreach(i; 1..n)
        sum[i] += sum[i - 1] + ws[i];

    long minima = long.max;
    for(int i = 1; i < n; i++) {
        const long left = sum[i - 1];
        const long right = sum[n-1] - sum[i - 1];
        minima = min(minima, abs(left - right));
    }

    minima.writeln;
}



Measured memory_bytes: 2736
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class ATakahashiCalendar {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int M, D;
	    in >> M >> D;
	    int answer = 0;
	    REP(i,1,M+1) {
	        REP(j,1,D+1) {
	            int d10 = j / 10;
	            int d1 = j % 10;
	            if (d10 > 1 && d1 > 1 && d10*d1 == i) answer++;
	        }
	    }
	    out << answer << "\n";
	}
};


signed main() {
	ATakahashiCalendar solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import sys

# お約束
INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(args, *params):
    return tuple(p(v) for p, v in zip(params, next(args).split()))
def debug(*v):
    if __debug__:
        print(*v, file=sys.stderr)

# エントリーポイント
def main(args):
    N, M = parse(args, int, int)
    X = tuple(map(int, next(args).split()))

    x = sorted(X)
    offset_x = [x[n] - x[n - 1] for n in range(1, M)]
    offset_x.sort(reverse=True)

    debug(offset_x)
    print(sum(offset_x[N - 1:]))

if __name__ == '__main__':
    main(iter(sys.stdin.read().split("\n")))


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

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

int popcnt(int x) {
    int result = 0;
    while (x > 0) {
        if (x & 1) {
            result++;
        }
        x >>= 1;
    }
    return result;
}

int main(void)
{
    constexpr int N_MAX = 21;
    int N;
    int a[N_MAX][N_MAX];
    cin >> N;
    REP(i, N) REP(j, N) cin >> a[i][j];
    int dp[1 << N];
    dp[(1 << N) - 1] = 1;
    RREP(bit, (1 << N) - 1) {
        int man = popcnt(bit);
        int result = 0;
        REP(woman, N) {
            if (a[man][woman] && (bit & (1 << woman)) == 0) {
                result = (result + dp[bit | (1 << woman)]) % MOD;
            }
        }
        dp[bit] = result;
    }
    cout << dp[0] << endl;
    return 0;
}



Measured memory_bytes: 8704
//(・ω・)
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
using namespace std;

int main(){
  int n;
  long long sum=0;
  cin >> n;
  for(int i=1; i<=n; i++){
     if(i%3!=0 && i%5!=0) sum+=i;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int max(int a,int b){
if(b>a)return b;
 return a;
}

int p[10][10];
int cp[10][10];
int flag[10][10];
int h,w,c;

struct data{
  int x,y;
};

struct data que[5000000];
int f,t;
void push(int xx,int yy){
  que[t].x=xx;
  que[t].y=yy;
  t++;
}

struct data pop(){
  return que[f++];
}

int sx[4]={0,1,0,-1};
int sy[4]={1,0,-1,0};
int col[7],res;

int bfs(int cc){
  memset(flag,0,sizeof(flag));
  f=0,t=0;
  push(1,1);
  flag[1][1]=1;
  while(f!=t){
    struct data q=pop();
    int i;
    for(i=0;i<4;i++){
      int nx=sx[i]+q.x,ny=sy[i]+q.y;
      if(flag[nx][ny]==0){
	if(cp[q.x][q.y]==cp[nx][ny]){
	  flag[nx][ny]=1;
push(nx,ny);
	}
      }
    }
  }
  int cnt=0;
  int i,j;
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      if(flag[j][i]==1)cp[j][i]=cc;
      cnt+=flag[j][i];
    }
  }
  return cnt;
}
int d[6];
void dfs(int x){
  if(x<4){
    for(d[x]=1;d[x]<=6;d[x]++){
      col[x]=d[x];
      dfs(x+1);
    }
  }else{
    col[4]=c;
    int i,j;
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	cp[j][i]=p[j][i];
      }
    }
    for(i=0;i<5;i++){
      bfs(col[i]);
 }
    res=max(res,bfs(7));
  }
}

int main(void){
  while(1){
    scanf("%d %d %d",&h,&w,&c);
    if(h+w+c==0)break;
    res=0;
    memset(p,0,sizeof(p));
    int a,b;
    for(a=1;a<=h;a++){
      for(b=1;b<=w;b++){
	scanf("%d",&p[b][a]);
      }
    }
    dfs(0);
    printf("%d\n",res);
  }
  return 0;
}

Measured memory_bytes: 608
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    map<char, int> m;
    map<char, int> ans;
    rep(i, 26) ans['a' + i] = 100;
    string s;
    rep(i, n) {
        cin >> s;
        rep(j, int(s.size())) m[s[j]]++;
        rep(j, 26) chmin(ans['a' + j], m['a' + j]);
        m.clear();
    }
    string res = "";
    rep(i, 26) {
        if (ans['a' + i] == 100)
            continue;
        else {
            while (ans['a' + i]--)
                res.push_back('a' + i);
        }
    }
    cout << res << endl;
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

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

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b;

int main() {
	cin >> a >> b;
	int ans = a+b;
	if (ans>=24) ans -= 24;
	cout << ans << ln;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0){
		return 1;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

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

int main(void){
	int n;
	cin>>n;
	if(n==3){
		cout<<"2 5 63"<<endl;
		return 0;
	}
	ll memo = 0;
	vector<int> ans;
	rep(i,n/4){
		ans.push_back(6*i+2);
		ans.push_back(6*i+3);
		ans.push_back(6*i+4);
		ans.push_back(6*i+6);
		memo += 1;
	}
	int base = 6*(n/4);
	if(n%4==1){
		if(memo%2 == 0){
			ans.push_back(base + 6);
		}else{
			ans.push_back(base + 3);
		}
	}else if(n%4==2){
		if(memo%2==0){
			ans.push_back(base + 2);
			ans.push_back(base + 4);			
		}else{
			ans.push_back(base + 3);
			ans.push_back(base + 6);
		}

	}else if(n%4==3){
		ans.push_back(base + 2);
		ans.push_back(base + 4);
		if(memo%2==0){
			ans.push_back(base + 6);
		}else{
			ans.push_back(base + 3);
		}
	}else{
		if(memo%2==0){

		}else{
			ans[ans.size()-1] = base + 3;
		}
	}
	rep(i,ans.size()){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 512