akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n; 
    string s;
    cin >> n >> s;
    int ans = 0;

    for(int i = 1; i < n; i++) {
        int save = 0;
        for(char c = 'a'; c <= 'z'; c++) {
            bool left = false, right = false;
            for(int j = 0; j < i; j++) {
                if(s[j] == c) {
                    left = true;
                    break;
                }
            }
            for(int j = i; j < n; j++) {
                if(s[j] == c) {
                    right = true;
                    break;
                }
            }
            if(left && right) save++;
        }
        ans = max(ans, save);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        long[] a = new long[n];
        char[] c = new char[n];
        c[0] = '+';
        for (int i = 0; i < n; i++) {
            if (i > 0) {
                c[i] = next().charAt(0);
            }
            a[i] = nextInt();
        }
        long s = 0;
        long ss = 0;
        long ans = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (c[i] == '+') {
                s += a[i];
            } else {
                ans = Math.max(-a[i] + s + ans, -a[i] - s + ss);
                ss += s + a[i];
                s = 0;
            }
        }
        ans += s;
        out.println(ans);
    }




    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 31660
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, 0, h) cin >> s[i];

  rep(i, 0, w+2) cout << '#';
  cout << endl; 
  rep(i, 0, h){
    cout << '#' << s[i] << '#' << endl;
  }
  rep(i, 0, w+2) cout << '#';
  cout << endl; 

  return 0;
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.range;

  int n, m, t; rd(n, m, t);
  auto r=readln.split.to!(int[]);
  auto d=new long[][](n, n);
  const long inf=1_000_000_000_000_000_000;
  foreach(i; 0..n) fill(d[i], inf);
  foreach(i; 0..n) d[i][i]=0;
  foreach(_; 0..m){
    int a, b; long c; rd(a, b, c);
    a--; b--;
    d[a][b]=d[b][a]=c;
  }

  foreach(k; 0..n){
    foreach(i; 0..n){
      foreach(j; 0..n){
        d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
      }
    }
  }

  auto v=new int[](0);
  auto usd=new bool[](t);

  long f(int k){
    if(k==t){
      long ret=0;
      foreach(i; 1..v.length){
        ret+=d[v[i-1]][v[i]];
      }
      return ret;
    }else{
      long ret=inf;
      foreach(i; 0..t)if(!usd[i]){
        v~=(r[i]-1); usd[i]=true;
        ret=min(ret, f(k+1));
        v.popBack; usd[i]=false;
      }
      return ret;
    }
  }

  writeln(f(0));

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >>m;
  vector<string> N(n),M(m);
  for(int i = 0;i<n;i++){
    cin >> N.at(i);
  }
  for(int i = 0;i<m;i++){
    cin >>M.at(i);
  }
  vector<string> L(m);
  for(int i= 0;i+m<=n;i++){
    for(int j = 0;j+m<=n;j++){
      for(int k = 0;k<m;k++){
        L.at(k) = N.at(k+i).substr(j,m);
      }
      if(L == M){
      	cout << "Yes";
      	return 0;
      }
    }
  }
  cout<<"No";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
char C[2] = {'#', '.'};
map<char, int> mp;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int H, W;
char S[410][410];
int white, black;
vector<vector<bool>> used(410, vector<bool>(410, false));
void dfs(int x, int y, int color) {
    if (S[x][y] == '#') black++;
    else white++;
    used[x][y] = true;
    rep(i, 4) {
        int xx = x + dx[i];
        int yy = y + dy[i];
        //cout << xx << " " << yy << endl;
        if (xx < 0 || xx >= H) continue;
        else if (yy < 0 || yy >= W) continue;
        else if (used[xx][yy]) continue;
        else if (S[xx][yy] != C[(color + 1) % 2]) continue;
        //cout << "ok" << xx << " " << yy << " " << S[xx][yy] << endl;
        dfs(xx, yy, (color + 1) % 2);
    }
}


signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> S[i][j];
    int ans = 0;
    mp['#'] = 0;
    mp['.'] = 1;
    rep(i, H) {
        rep(j, W) {
            //cout << S[i][j] << endl;
            if (!used[i][j]) {
                dfs(i, j, mp[S[i][j]]);
                ans += white * black;
                //cout << "*" << white << " " << black << endl;
                white = 0;
                black = 0;
            }
        }
    }
    //rep(i, H) rep(j, W) cout << i << " " << j <<" " << S[i][j]  << endl;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e5;  
using  p = pair<int,int>;

int main(){
 int n;
 cin >> n;
 auto a = vector<int>(n,0);
 for (int i = 0; i < n; i++)
 {
   cin >> a[i];
 }

  auto sum = 0;
 for (int i = 0; i < n; i++)
 {
    sum += a[i]-1;
 }
 
 cout << sum;

}
  
  

Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    cini(T);
    vector<pii> ab(n);
    for(int i=0; i<n; i++)
        cin>>ab[i].first>>ab[i].second;

    sort(ab.begin(), ab.end());

/* We want to find max(sum(b[i])) while having sum(a[i])<T .
 * So among all set<i> with sum(a[i])<T
 * we want to find the one with max(sum(b[i]))
 *
 * knapsack max sum(B).
 **/

    vvll memo(n, vll(T+1, -1));
    function<ll(int,int)> knapp=[&](int idx, int t) {
        if(t<=0 || idx>=n)
            return 0LL;

        if(memo[idx][t]>=0)
            return memo[idx][t];

        ll val=max(knapp(idx+1, t), 
            ab[idx].second+knapp(idx+1, t-ab[idx].first));

        memo[idx][t]=val;
        return val;
    };

    ll ans=knapp(0, T);
    cout<<ans<<endl;
}



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

int main(){
    int N, M;
    cin >> N >> M;
    bitset<100001> AC;
    vector<int> num(N+1);
    int pen = 0;
    for(int i=0; i<M; i++){
        int p;
        string S;
        cin >> p >> S;
        if(S == "AC"){
            if(!AC[p]){
                AC[p] = 1;
                pen += num[p];
            }
        }else{
            num[p]++;
        }
    }
    cout << AC.count() << " " << pen << endl;
    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;
    vector<ll> A(5);

    ll minA = LINF;
    REP(i, 5){
        cin >> A[i];
        if(A[i] < minA){
            minA = A[i];
        }
    }

    cout << 5 + (N-1)/minA << endl;
    
    return 0;
}

Measured memory_bytes: 256
// base on tourist's code

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 50500;
const int MAXMOD = 1000100;

int MOD;
int phi;
int add(int x, int y) { return ((x += y) >= MOD) ? x - MOD : x; }
int sub(int x, int y) { return ((x -= y) < 0) ? x + MOD : x; }
int mult(int x, int y) { return (long long) x * y % MOD; }
int pw(int x, int y) {
   int ans = 1;
   for (; y > 0; y >>= 1, x = mult(x, x)) if (y & 1) ans = mult(ans, x);
   return ans;
}

#define div __div
int div(int x, int y) { return mult(x, pw(y, phi - 1)); }

int N, M, Q;
vector<pair<int, int>> adj[MAXN];
int coeff[MAXN];
int upVal[MAXN];
int downVal[MAXN];
int par[MAXMOD];

int getPar(int v) {
   if (par[v] != v) {
      par[v] = getPar(par[v]);
   }
   return par[v];
}

int merge(int v, int u) {
   par[getPar(u)] = getPar(v);
}

int main() {
   ios_base::sync_with_stdio(false);
   cin >> N >> M >> Q >> MOD;
   phi = MOD;
   int __MOD = MOD;
   for (int z = 2; z * z <= __MOD; ++z) {
      if (__MOD % z == 0) {
         phi -= phi / z;
         while (__MOD % z == 0) __MOD /= z;
      }
   }
   if (__MOD > 1) phi -= phi / __MOD;
   for (int i = 0; i < M; ++i) {
      int v, u, z;
      cin >> v >> u >> z;
      --v, --u;
      adj[v].emplace_back(u, z);
      adj[u].emplace_back(v, z);
   }
   queue<int> q;
   coeff[0] = 1;
   q.emplace(0);
   while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto e : adj[v]) {
         int u, z;
         tie(u, z) = e;
         if (!coeff[u]) {
            coeff[u] = mult(coeff[v], 2);
            upVal[u] = add(upVal[v], mult(coeff[v], z));
            downVal[u] = add(mult(downVal[v], 2), z);
            q.emplace(u);
         }
      }
   }
   vector<pair<int, int>> edges;
   for (int v = 0; v < N; ++v) {
      for (auto e : adj[v]) {
         int u, z;
         tie(u, z) = e;
         int a = div(mult(2, coeff[v]), coeff[u]);
         int b = div(sub(add(mult(2, downVal[v]), z), downVal[u]), coeff[u]);
         edges.emplace_back(a, b);
      }
   }
   sort(edges.begin(), edges.end());
   edges.resize(unique(edges.begin(), edges.end()) - edges.begin());
   iota(par, par + MOD, 0);
   int delta = MOD;
   for (int i = 0; i < int(edges.size()); ++i) {
      if (i > 0 && edges[i].first == edges[i - 1].first) {
         delta = __gcd(delta, edges[i].second - edges[i - 1].second);
      } else {
         for (int z = 0; z < MOD; ++z) {
            merge(z, add(mult(z, edges[i].first), edges[i].second));
         }
      }
   }
   for (int z = 0; z < MOD; ++z) merge(z, add(z, delta));
   while (Q--) {
      int v, u, val;
      cin >> u >> v >> val;
      --v, --u;
      val = div(sub(val, downVal[u]), coeff[u]);
      cout << ((getPar(upVal[v]) == getPar(val)) ? "YES" : "NO") << "\n";
   }
}


Measured memory_bytes: 8840
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 4007;
int cnt[N][3];
char s[N];
int main() 
{
   	int n;scanf("%d%s",&n,s+1);
   	for(int i = 1;i <= n;++i)
   	{
   		for(int j = 0;j < 3;++j)
   			cnt[i][j] = cnt[i - 1][j];
   		if(s[i] == 'R')	s[i] = 'A';
   		if(s[i] == 'G')	s[i] = 'C';
  		++cnt[i][s[i] - 'A'];
   	}
   	ll res = 0;
   	for(int i = 1;i <= n;++i)
   		for(int k = i + 1;k <= n;++k)
   		{
   			if(s[i] == s[k])	continue;
   			int need = 3 - (s[i] - 'A') - (s[k] - 'A');
   			res += cnt[k][need] - cnt[i][need];
   			int j = (i + k) / 2;
   			if(j * 2 == i + k && s[j] - 'A' == need)
   				--res;
   		}
   	printf("%lld",res);
}

Measured memory_bytes: 3192
#include<cstdio>
int n, ans = 0, f = 1;
int main(){
	scanf("%d", &n);
	int x = 1;
	for(int i = 1; i <= n; i++){
		if(i / x >= 10) x *= 10, f = f ^ 1;
		ans += f;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string a,b;
  cin>>a>>b;
  int asi=a.size();
  int bsi=b.size();
  if(asi>bsi){
    cout<<"GREATER"<<'\n';
  }
  else if(asi<bsi){
    cout<<"LESS"<<'\n';
  }
  else{
    rep(i,asi){
      if((a[i]-'0')>(b[i]-'0')){
        cout<<"GREATER"<<'\n';
        return(0);
      }
      else if((a[i]-'0')<(b[i]-'0')){
        cout<<"LESS"<<'\n';
        return(0);
      }
    }
    cout<<"EQUAL"<<'\n';
  }
  return(0);
}


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


template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};


using pint = pair<int,int>;
int N, M;
vector<pint> inter;

int main() {
    cin >> N >> M;
    inter.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> inter[i].first >> inter[i].second, ++inter[i].second;
    sort(inter.begin(), inter.end(), [&](pint i, pint j) {
            return i.second - i.first < j.second - j.first;});

    //for (int i = 0; i < N; ++i) cout << inter[i].first << ", " << inter[i].second << endl;

    vector<int> res(M);
    BIT<int> bit(M + 10);
    int pos = 0;
    for (int d = 1; d <= M; ++d) {
        while (pos < N && inter[pos].second - inter[pos].first <= d-1) {
            bit.add(inter[pos].first, inter[pos].second, 1);
            ++pos;
        }
        for (int i = d; i <= M; i += d) {
            res[d-1] += bit.sum(i, i+1);
        }
        res[d-1] += (N - pos);
    }

    for (int d = 0; d < M; ++d) cout << res[d] << endl;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  rep(i,0,N) cin >> A[i];
  i64 now = 0;
  i64 r = 0;
  i64 ans = 0;
  rep(i,0,N) {
    while(r < N && (A[r] & now) == 0) {
      now |= A[r];
      r++;
    }
    ans += r - i;
    if(i == r) {
      r++;
    }
    else {
      now &= (~A[i]);
    }
  }
  cout << ans << endl;
}


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


int main (){
   string x;
   int counter=1,n;
   cin>>n>>x;
   for(int i=1;i<x.size();i++)
    if(x[i-1]!=x[i])
        counter++;


   cout<<counter<<endl;
	return 0;
}











Measured memory_bytes: 512
tmp = input()
q = tmp.split(" ")
a = int(q[0]) - 1
b = int(q[1])

l = 0
if(b == 1):
    print(0)
else:
    c = a + 1
    l += 1
    while(c < b):
        c += a
        l+=1
    print(l)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int INF = 1e9;

inline int divceil(int x,int y){
	return (y > 0 ? (x + y - 1) / y : INF);
}

signed main(){
	int n,h[40010],a[40010],d[40010],s[40010];
	cin >> n;
	for(int i = 0;i <= n;i++){
		cin >> h[i] >> a[i] >> d[i] >> s[i];
	}
	int ans = 0,sum = 0;
	for(int i = 1;i <= n;i++){
		if(s[0] > s[i]) ans -= max(0ll,a[i] - d[0]);
		sum += max(0ll,a[i] - d[0]);
	}
	vector<int> vec(n);
	iota(vec.begin(),vec.end(),1);
	sort(vec.begin(),vec.end(),[&](int i,int j){
		return divceil(h[i],a[0] - d[i]) * max(0ll,a[j] - d[0])
		< divceil(h[j],a[0] - d[j]) * max(0ll,a[i] - d[0]);
	});
	for(int v : vec){
		ans += sum * divceil(h[v],a[0] - d[v]);
		if(ans >= h[0]){
			cout << -1 << endl;
			return 0;
		}
		sum -= max(0ll,a[v] - d[0]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  ll l, g;
  vector<ll> a(n);
  int co = 0;
  rep(i, n){
    ll in;
    cin >> in;
    in /= 2;
    if(i == 0){
      a.at(0) = l = g = in;
      while(in % 2 == 0){
        co++;
        in /= 2;
      }
    }else{
      a.at(i) = in;
      g = __gcd(l, in);
      l = l/g*in;
      int tst = 0;
      while(in % 2 == 0){
        tst++;
        in /= 2;
      }
      if(tst != co){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  // cerr << l << endl;
  ll lim = m/l;
  lim++;
  ll ans = lim/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3988
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A = get_int
B = get_int
C = get_int
D = get_int

puts [A, B].min + [C, D].min



Measured memory_bytes: 14500
#include<iostream>
#include<deque>
#include<string>
using namespace std;

int main()
{
    deque<char> a,b;
    string n,m;
    cin >> n;
    for(int p=0;p<2;p++){
        for(int i=0;i<(int)n.size();i++){
            char t=n[i];
            a.push_back(t);
        }
    }

    cin >> m;
    for(int i=0;i<(int)m.size();i++){
        char t=m[i];
        b.push_back(t);
    }
    int z=(int)a.size()/2;
    for(int y=0;y<z;y++){
        int x=0;
        for(int c=0;c<(int)b.size();c++){
            if(a[c]==b[c]) x++;
        }
        if(x==(int)m.size()){
            cout << "Yes" << endl;
            return 0;
        }
        a.pop_front();
    }
    cout << "No" << endl;

}



Measured memory_bytes: 3212
#include<stdio.h>
#define ll long long
ll a[5],n,i,m;
int main()
{
	for (i=1;i<=4;++i) scanf("%lld",&a[i]);
	n=a[3]/a[2];
	if (a[3]%a[2]!=0) ++n;
	m=a[1]/a[4];
	if (a[1]%a[4]!=0) ++m;
	if (m>=n) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 1736
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

#ifdef DEBUG
int __cnt = 0;
#define msg(x) cout << ++__cnt << '\t' << __FUNCTION__ << "(" << __LINE__ << "): " << x << endl
#else
#define msg(x)
#endif

typedef long long ll;
typedef unsigned long long ull;

template<typename T>
T _scan() {
  T ch; bool seg = false;
  while (!isdigit(ch = getchar())) {
    seg |= (ch == '-');
  }
  T x = ch - '0';
  while (isdigit(ch = getchar())) {
    x = x * 10 + ch - '0';
  }
  if (seg) {
    x = -x;
  }

  return x;
}

auto const scan = &_scan<int>;
auto const scan_ll = &_scan<ll>;

template<typename T>
T maximize(T& a, const T b) {
  if (b > a) {
    a = b;
  }
  return a;
}

template<typename T>
T minimize(T& a, const T b) {
  if (b < a) {
    a = b;
  }
  return a;
}



int main() {
  int n = scan();
  ll ans = 0; int limit = 0;
  while (n--) {
    int x = scan();
    if (x <= limit) {
      continue;
    }
    if (x == limit + 1) {
      limit = x;
      continue;
    }
    ans += (x - 1) / (limit + 1);
    if (limit == 0) {
      limit = 1;
    }
  }
  cout << ans;
}



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

int main(){
  int N,sum = 0;
  cin >> N;
  vector<int> a(N);
  
  for(int i = 0;i < N;i++){
    cin >> a.at(i);
  }
  for(int i = 0;i < N;i++){
    for(int j = i + 1;j < N;j++){
      if(a.at(i) < a.at(j)){
        int tmp= a.at(i);
        a.at(i) = a.at(j);
        a.at(j) = tmp;
      }
    }
    if(i % 2 == 0){
      sum += a.at(i);
    }
    else if(i % 2 == 1){
      sum -= a.at(i);
    }
  
 }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
S = list(map(str, input()))
flg = 1

if S[0] != "A":
	flg = 0

ctr = 0
for i in range(2, len(S) - 1):
	if S[i] == "C":
		ctr += 1
if ctr != 1:
	flg = 0

ctr = 0	
for s in S:
	if ord(s) <= 90:
		ctr += 1
if ctr != 2:
	flg = 0
	
	
if flg:
	print("AC")
else:
	print("WA")

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n;
    cin>>n;
    int x=0;
    while (x<n) x+=1000;
    cout<<x-n<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3608
LI = lambda: list(map(int, input().split()))

N = int(input())
A = LI()


def main():
    ans = 1000
    k = 0
    for i in range(N - 1):
        if A[i] == A[i + 1]:
            continue
        if A[i] > A[i + 1]:
            ans += k * A[i]
            k = 0
        else:
            x = ans // A[i]
            ans -= x * A[i]
            k += x
    ans += k * A[-1]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
#include <stdio.h>
int main(void){
  int h=0, m=0, s=0;
  int S,i;

  scanf("%d", &S);
  if(S>=0 && S<=86400){
    s = S%60;
    m = S/60;
    h = m/60;
    m = m%60;

    printf("%d:%d:%d\n", h, m, s);
    }
  else{
    return 1;
  }
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod  = 1e9+7;
const db eps  = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf = LLONG_MAX;

#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cout << #x << " " << x << endl

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

        db pi = 3.1415926;
        db r;
        cin >> r;   
        cout << setprecision(5) << fixed <<(db)2*pi*r;

    return 0;
} 

Measured memory_bytes: 3816
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<math.h>
#include<x86intrin.h>


int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nDigit,int N){      //nDigitは想定される最大桁数
    char *buf,*ptr;

    buf=(char*)malloc( (N*(nDigit+2)) * sizeof(char) );
    my_gets(buf,N*(nDigit+2),stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}

int CmpInt(const void *a, const void *b){        //b-aを返す(qsortなら降順)
    return *((int*)b)- *((int*)a);
}

#define MAX_N (1000000007ull)

int main(){
    uint64_t cnt[13]={1,0,0,0,0,0,0,0,0,0,0,0,0};
    uint64_t table[12]={1, 10, 9, 12, 3, 4, 1, 10, 9, 12, 3, 4};
    char S[100001];
    int len;

    my_gets(S, sizeof(S)/sizeof(char), stdin);
    len = strlen(S);

    for(int i=0; i<len ; i++){
        uint64_t tmp[13]={0};
        if(S[len-i-1] != '?'){
            //puts(" num");
            for(int j=0;j<13;j++){
                tmp[ ((S[len-i-1]-'0')*table[i%12] + j)%13 ] += cnt[j];
            }
            for(int j=0;j<13;j++){
                cnt[j] = tmp[j];
            }
        }
        else{
            //puts(" nonnum");
            for(int k=0;k<10;k++){
                for(int j=0; j<13; j++){
                    tmp[ ((k*table[i%12])+j)%13 ] += cnt[j];
                    tmp[ ((k*table[i%12])+j)%13 ] %= MAX_N;
                }
            }
            for(int j=0;j<13;j++){
                cnt[j] = tmp[j];
            }
        }
        //for(int j=0;j<13;j++)
            //printf("%llu ",cnt[j]);
        //puts("");
    }

    printf("%llu\n",cnt[5]);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
    int n;scanf("%d",&n);
    int a[1005];
    for(int i = 0 ; i <n; i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    printf("%d\n",a[n-1]-a[0]);


    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int N, M; cin >> N >> M;
    ll res = 0;
    rep (i, M) {
        int tmp; cin >> tmp;
        res += tmp;
    }
    if (N < res) cout << -1 << endl;

    else cout << N - res << endl;
    
    return 0;
}

Measured memory_bytes: 3640
use std::cmp;

fn main(){
  let mn: Vec<usize> = read_vec();
  let m = mn[0];
  let n = mn[1];

  let mut flg: Vec<Vec<char>> = Vec::new();
  
  for _ in 0 .. m {
   let s: String = read();
   flg.push(s.chars().collect());
  }

  let mut emb: Vec<Vec<char>> = Vec::new();
  
  for _ in 0 .. 2 {
   let s: String = read();
   emb.push(s.chars().collect());
  }

  let mut ct: i32 = 0;

  let mut cv: Vec<(usize, usize, char)> = Vec::new();
  
  for i in 0 .. m-1 {
    for j in 0 .. n-1 {
      match (flg[i][j] == emb[0][0],
             flg[i][j+1] == emb[0][1],
             flg[i+1][j] == emb[1][0],
             flg[i+1][j+1] == emb[1][1]) {
             (true, true, true, true) => { ct += 1; },
             (false, true, true, true) => { cv.push((i, j, emb[0][0])); },
             (true, false, true, true) => { cv.push((i, j+1, emb[0][1])); },
             (true, true, false, true) => { cv.push((i+1, j, emb[1][0])); },
             (true, true, true, false) => { cv.push((i+1, j+1, emb[1][1])); },
             _ => {},
      }
    }
  }

  let mut df: i32 = 0;
  
  for &(i, j, c) in &cv {
    let cc = flg[i][j];
    let x = cnt(&flg, &emb, i, j);
    flg[i][j] = c;
    let y = cnt(&flg, &emb, i, j);
    flg[i][j] = cc;
    df = cmp::max(df, y - x);
  }
  
  println!("{}", ct + df);
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}

fn cnt(v: &Vec<Vec<char>>, e: &Vec<Vec<char>>, i: usize, j: usize) -> i32 {
  let m = v.len();
  let n = v[0].len();
  let mut ct: i32 = 0;

  if i > 0 && j > 0 &&
     v[i-1][j-1] == e[0][0] &&
     v[i-1][j] == e[0][1] &&
     v[i][j-1] == e[1][0] &&
     v[i][j] == e[1][1] {
       ct += 1;
     }
  if i > 0 && j < n - 1 &&
     v[i-1][j] == e[0][0] &&
     v[i-1][j+1] == e[0][1] &&
     v[i][j] == e[1][0] &&
     v[i][j+1] == e[1][1] {
       ct += 1;
     }
  if i < m - 1 && j > 0 &&
     v[i][j-1] == e[0][0] &&
     v[i][j] == e[0][1] &&
     v[i+1][j-1] == e[1][0] &&
     v[i+1][j] == e[1][1] {
       ct += 1;
     }
  if i < m - 1 && j < n - 1 &&
     v[i][j] == e[0][0] &&
     v[i][j+1] == e[0][1] &&
     v[i+1][j] == e[1][0] &&
     v[i+1][j+1] == e[1][1] {
       ct += 1;
     }
     
   ct
}



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

public class Main{
	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] line2 = (br.readLine()).split(" ");
		int[] a = new int[n];
		for(int i = 0; i<n ; i++){
			a[i] = Integer.parseInt(line2[i]);
		}
		int q = Integer.parseInt(br.readLine());		
		String[] line4 = (br.readLine()).split(" ");
		int[] m = new int[q];
		for(int i = 0; i<q ; i++){
			m[i] = Integer.parseInt(line4[i]);
		}
		for(int i = 0; i<q ; i++){
			boolean res = isSum(n,a,0,m[i]);
			if(res){
				System.out.println("yes");
			}else{
				System.out.println("no");
			}
		}
	}
	public static boolean isSum(int n,int[] a,int k,int b){	
		if(b==0){
			return true;
		}else if(k==n || b < 0){
			return false;
		}

		boolean judge = (isSum(n,a,k+1,b) || isSum(n,a,k+1,b-a[k]));
		return judge;
	}
}

Measured memory_bytes: 24868
buff = input()
N, M, L = map(int, buff.split())

A=[]
for n in range(N):
    buff = input()
    A.append( [int(x) for x in buff.split()] )

B=[]
for m in range(M):
    buff = input()
    B.append( [int(x) for x in buff.split()] )
    

for n in range(N):
    for l in range(L):
        c = 0
        for m in range(M):
            c += A[n][m] * B[m][l]
        print(c, end="")
        if l < L-1:
            print(end=" ")
    print()
        


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

int main() {
  ll N;
  cin >> N;
  vector<ll> delt(N);
  ll c = 0;
  ll dec = 0; 
  
  for (ll &e : delt) cin >> e;
  for (ll i = 0; i < N; i++) {
    ll x;
    cin >> x;
    delt[i] -= x;
    if (delt[i] < 0) {
      dec += delt[i];
      c += 1;
    }
  }
  
  sort(delt.begin(), delt.end(), greater<ll>());
  for (int i = 0; i < N; i++) {
    if (delt[i] <= 0) {
      cout << -1 << endl;
      return 0;
    }
    c += 1;
    dec += delt[i];
    if (dec >= 0) {
      if (c == 1) c--;
      cout << c << endl;
      return 0;
    }
  }
}

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

int main() {
  int n;cin>>n;
  vector<int> a(n);
  int cnt=0;
  rep(i,n){
    cin>>a[i];
    if(a[i]%2==1)cnt++;
  }
  if(cnt%2==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 3692
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>

using ll = long long;

using namespace std;

struct grid{ int x, y, d; };

int h, w;
int board[101][101];
bool visited[101][101];

int main() {
    cin >> h >> w;
    for (int i=0; i<h; i++) {
        string s; cin >> s;
        for (int j=0; j<w; j++) {
            board[i][j] = (s[j] == '#');
        }
    }
    fill(visited[0], visited[h], false);

    deque<grid> q;
    q.push_front({0, 0, board[0][0] + board[h-1][w-1]});
    while (true) {
        grid f = q.front(); q.pop_front();

        if (f.x == h-1 && f.y == w-1) {
            cout << f.d / 2 << '\n';
            return 0;
        }
        if (f.x < h-1 && !visited[f.x+1][f.y]) {
            visited[f.x+1][f.y] = true;
            if (board[f.x+1][f.y] == board[f.x][f.y])
                q.push_front({f.x+1, f.y, f.d});
            else 
                q.push_back({f.x+1, f.y, f.d+1});
        }
        if (f.y < w-1 && !visited[f.x][f.y+1]) {
            visited[f.x+1][f.y] = true;
            if (board[f.x][f.y+1] == board[f.x][f.y])
                q.push_front({f.x, f.y+1, f.d});
            else 
                q.push_back({f.x, f.y+1, f.d+1});
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[100][100],color[100],d[100],f[100],t;
void depthA(int);
void depthB(void);

int main(){
    int i,j,a,b,c;
    
    scanf("%d",&n);
    
    for(i = 0;i < n;i++){
        for(j = 0;j < n;j++){
            M[i][j] = 0;
        }
    }
    for(i = 0;i < n;i++){
        scanf("%d%d",&a,&b);
        a--;
        for(j = 0;j < b;j++){
            scanf("%d",&c);
            c--;
            M[a][c] = 1;
        }
    }
    depthB();
    return 0;
}

void depthA(int u){
    int i;
    
    color[u] = GRAY;
    d[u] =++t;
    
    for(i = 0;i < n;i++){
        if(M[u][i] == 0) continue;
        if(color[i] == WHITE){
            depthA(i);
        }
    }
    color[u] = BLACK;
    f[u] =++t;
}

void depthB(){
    int i;
    
    for(i = 0;i < n;i++) color[i] = WHITE;
    t = 0;
    for(i = 0;i < n;i++){
        if(color[i] == WHITE) depthA(i);
    }
    for(i = 0;i < n;i++){
        printf("%d %d %d\n",i + 1,d[i],f[i]);
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

int K;
char d[10];

bool check(string s){
    for(int i=0; i<s.size(); i++){
        for(int j=0; j<K; j++){
            if(s[i] == d[j]) return false;
        }
    }

    return true;
}

int main(){
    int N; cin >> N >> K;
    for(int i=0; i<K; i++) cin >> d[i];

    for(int i=N; ; i++){
        string s = to_string(i);
        if(check(s)){
            cout << s << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int k, x;
    cin >> k >> x;
    if (500*k>=x) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner scanner = new Scanner(System.in);
		Sub sub = new Sub();
	}

	static class Sub
	{
		public Sub()
		{
			Scanner scanner = new Scanner(System.in);
			int i = scanner.nextInt();
			System.out.println(i*i*i);
		}
	}
}



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int val[400][400];
int h[400][400];

int N;

int r[4][4]={{0,1,5,3},{0,2,5,4},{0,3,5,1},{0,4,5,2}};
int dy[4]={-1,0,1,0},dx[4]={0,1,0,-1};

void solve(){
    memset(val,-1,sizeof(val));
    memset(h,0,sizeof(h));
    while(N--){
        int t,f;
        cin>>t>>f;
        int d[6];
        d[0]=t;
        d[1]=f;
        d[3]=7-f;
        d[5]=7-t;
        int cnt=0;
        if(t<4)t=7-t,cnt++;
        if(f<4)f=7-f,cnt++;
        if(t==6&&f==4)d[2]=5;
        if(t==4&&f==6)d[2]=2;
        if(t==6&&f==5)d[2]=3;
        if(t==5&&f==6)d[2]=4;
        if(t==5&&f==4)d[2]=1;
        if(t==4&&f==5)d[2]=6;
        d[4]=7-d[2];
        if(cnt&1)swap(d[2],d[4]);

        int x=200,y=200;
        while(true){
            bool ok=false;
            for(int i=6;i>=4;i--){
                int k;
                rep(j,6)if(d[j]==i)k=j;
                if(k==0||k==5)continue;
                k--;
                int ny=y+dy[k],nx=x+dx[k];
                if(h[y][x]<=h[ny][nx])continue;
                y=ny;x=nx;
                ok=true;
                int tmp=d[r[k][3]];
                for(int j=3;j>0;j--)d[r[k][j]]=d[r[k][j-1]];
                d[r[k][0]]=tmp;
                break;
            }
            if(!ok)break;
        }
        h[y][x]++;
        val[y][x]=d[0];
    }

    int cnt[6]={};
    rep(i,400)rep(j,400)if(val[i][j]>0)cnt[val[i][j]-1]++;
    rep(i,6){
        if(i)cout<<" ";
        cout<<cnt[i];
    }cout<<endl;
}

signed main(){
    while(cin>>N,N)solve();
    return 0;
}

Measured memory_bytes: 5552
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    vector<bool> info(100001,1);
    info[0]=info[1]=0;
    repl(i,2,100001){
        if(info[i]){
            for(int j=2*i;j<100001;j+=i)info[j]=0;
        }
    }
    vl count(100001);
    repl(i,1,100001){
        count[i]=count[i-1];
        if(i%2 and info[i] and info[(i+1)/2])count[i]++;
    }
    int Q;cin>>Q;
    while(Q--){
        int l,r;cin>>l>>r;
        cout<<count[r]-count[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
num = gets().to_i

judges = Array.new
num.times do
  sides = gets().split().map{|x| x.to_i}
  sides.sort!

  if (sides[0]*sides[0] + sides[1] * sides[1] == sides[2] * sides [2]) then
    judges.push("YES")
  else
    judges.push("NO")
  end
end

num.times do |n|
  puts judges[n]
end

Measured memory_bytes: 6104
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VII;
#define PB push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

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

  VII dp; // dp[i][j] = [a,b,c][i]をj日目に選んだときの最大値
  REP(i,3) {
    VI v(N + 1, 0);
    dp.PB(v);
  }
  dp[0][0] = dp[1][0] = dp[2][0] = 0;
  for (int i = 0; i < N; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    dp[0][i+1] = max(dp[1][i] + a, dp[2][i] + a);
    dp[1][i+1] = max(dp[0][i] + b, dp[2][i] + b);
    dp[2][i+1] = max(dp[0][i] + c, dp[1][i] + c);
  }
  cout << max(max(dp[0][N], dp[1][N]), dp[2][N]) << endl;
  return 0;
}


Measured memory_bytes: 1788
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a, b;
		a = sc.nextInt();
		b = sc.nextInt();
		System.out.print((a * b) + " " + (a + a + b + b));
		System.out.println("");
		sc.close();
	}
}


Measured memory_bytes: 26120
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <string>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, K;
    string S;
    cin >> N >> K;
    cin >> S;
    //
    S[K - 1] = std::tolower(S[K-1]);
    cout << S;

    return 0;
}

Measured memory_bytes: 3120
X, K, D = map(int, input().split())


def f(C):
    NX = float("inf")
    if C > K:
        return NX

    if K % 2 == 0:
        if C % 2 == 0:
            NX = abs(abs(X) - C * D)
        else:
            NX = abs(abs(X) - (C + 1) * D)
            if C > 0:
                NX = min(NX, abs(abs(X) - (C - 1) * D))
    else:
        if C % 2 == 0:
            NX = abs(abs(X) - (C + 1) * D)
            if C > 0:
                NX = min(NX, abs(abs(X) - (C - 1) * D))
        else:
            NX = abs(abs(X) - C * D)

    return NX


C = min(abs(X) // D, K)

print(min(f(C), f(C + 1)))


Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> c(n);
    rep(i,n) {
        cin>>c[i];
    }
    sort(begin(c),end(c));
    vector<ll> mp4(200101,0);
    mp4[0] = 1; 
    ll res = 0;
    rep(i,200100) {
        mp4[i+1] = mp4[i] * 4;
        mp4[i+1] %=MOD;
    }
    rep(i,n) {
        ll tmp = mp4[n-1] * (n-i-1) % MOD;
        res = (res + (tmp + 2 * mp4[n-1]) % MOD *c[i]) % MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;


int main(){
    int s;
    cin >> s;
    for(int i = 1; ;i++){
        if(s == 2 || s == 1 || s == 4) {
            cout << i + 3 << endl;
            return 0;
        }
        if(s % 2 == 0) s = s/2;
        else s = s * 3 + 1;
    }
}

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

int main()
{
  int n;
  cin >> n;
  
  int left, right, count = 0;
  // 1 <= a * b < n - 1 これを満たすa, bを求める
  int product = n - 1;
  while (product > 0) {
    for (int i = 1; i * i <= product; i++) {
      if (product % i == 0) {
        if (i * i == product) {
          // a = b
          count++;
        } else {
          // a ≠ b
          count += 2;
        }
      }
    }
    product--;
  }
  
  cout << count  << endl;
}

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


int main() {
int x,y;
cin >> x >> y;
for (int i = 0;i <=x;i++) {
    if ((2*i)+4*(x-i) == y) {
        cout << "Yes" << endl;
        return 0;
    }
}
cout << "No" << endl;


return 0;
}


Measured memory_bytes: 3624