akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=[int(input()) for _ in range(n)]
mod=998244353
s=sum(a)

dp=[[0]*(s+1) for _ in range(n)]
dp[0][0],dp[0][a[0]]=2,1
for i in range(n-1):
    for j in range(s+1):
        dp[i+1][j]=(dp[i+1][j]+dp[i][j]*2)%mod
        if j+a[i+1]<=s: dp[i+1][j+a[i+1]]=(dp[i+1][j+a[i+1]]+dp[i][j])%mod

dp2=[[0]*(s+1) for _ in range(n)]
dp2[0][0]=1;dp2[0][a[0]]=1
for i in range(n-1):
    for j in range(s+1):
        dp2[i+1][j]=(dp2[i+1][j]+dp2[i][j])%mod
        if j+a[i+1]<=s: dp2[i+1][j+a[i+1]]=(dp2[i+1][j+a[i+1]]+dp2[i][j])%mod

if s%2==0:
    inable=( sum(dp[n-1][s//2:]) - dp2[n-1][s//2] )*3%mod
else:
    inable=( sum(dp[n-1][s//2+1:]) )*3 %mod

ans=1
for _ in range(n):
    ans=ans*3%mod
ans=(ans-inable)%mod
print(ans)


Measured memory_bytes: 457608
# coding: utf-8

def getint():
    return int(input().rstrip())

def main():
    n = getint()

    values = []
    for i in range(n):
        values.append(getint())

    maxv = values[1] - values[0]
    minv = values[0]
    for j in range(1,n):
        maxv = max(maxv, values[j]-minv)
        minv = min(minv, values[j])

    print(maxv)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 15592
n = int(raw_input())

occ = {}
for i in map(int, raw_input().split()):
    if not i in occ:
        occ[i] = 0

    occ[i] += 1

found = 0
rect = 1

for i in sorted(occ, reverse=True):
    if occ[i] >= 4 and found < 1:
        found += 2
        rect *= i*i
    elif occ[i] >= 2:
        found += 1
        rect *= i

    if found == 2:
        print rect
        break
    
if found < 2:
    print 0
        
    


Measured memory_bytes: 58092
n = input()
num = [int(n[0]), int(n[1]), int(n[2]), int(n[3])]
if sum(num) == 7:
    print(str(num[0]) + "+" + str(num[1]) + "+" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] + num[1] + num[2] - num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "+" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] + num[1] - num[2] + num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "-" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] + num[1] - num[2] - num[3] == 7:
    print(str(num[0]) + "+" + str(num[1]) + "-" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] - num[1] + num[2] + num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "+" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] - num[1] + num[2] - num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "+" + str(num[2]) + "-" + str(num[3]) + "=7")
elif num[0] - num[1] - num[2] + num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "-" + str(num[2]) + "+" + str(num[3]) + "=7")
elif num[0] - num[1] - num[2] - num[3] == 7:
    print(str(num[0]) + "-" + str(num[1]) + "-" + str(num[2]) + "-" + str(num[3]) + "=7")


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin>>p[i];
    }
    sort(p.begin(),p.end());
    for (int i = 100; i >= 0; --i) {
        int cnt=0;
        for(auto j:p)if(j>=i)++cnt;
        if(cnt>=i){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3156
<?php
fscanf(STDIN, "%s", $a);
 
if ($a == 'A') {
    echo 'T';
} else if ($a == 'C') {
    echo 'G';
} else if ($a == 'G') {
    echo 'C';
} else if ($a == 'T') {
    echo 'A';
}

Measured memory_bytes: 3576
#include <iostream>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main(void){
    int N;
    cin >> N;
    int A[N], B[N];
    rep(i, N+1) B[i] = 0;
    for (int i=2; i<=N; i++) {
        cin >> A[i];
        B[A[i]] ++;
    }
    for (int i=1; i<=N; i++) cout << B[i] << endl;
    return 0;
}


Measured memory_bytes: 5192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
	int n,m,tmp=1;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		tmp*=2;
	}
	cout<<(1900*m+100*(n-m))*tmp;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    char a[120],b[120];
    scanf ("%s%s",a,b);
    if (strlen(a)>strlen(b)){
        printf ("GREATER\n");
    } else if (strlen(a)<strlen(b)){
        printf ("LESS\n");
    } else {
        for (int i=0; i<strlen(a); i++)
            if (strncmp(&a[i],&b[i],1)<0){
                printf ("LESS\n") ;
                exit (0) ;
            } else if (strncmp(&a[i],&b[i],1)>0){
                printf ("GREATER\n") ;
                exit (0) ;
            } else {
            }
        printf ("EQUAL\n") ;
    }
    return 0 ;
}

Measured memory_bytes: 128
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const size_t SIZE = 1e6;
bool used[SIZE];

int main() {
    V<ll> ps;
    for(ll i = 2; i < SIZE; i++) {
        if(used[i]) continue;
        ps.push_back(i);
        for(ll j = 1; i * j < SIZE; j++) used[i * j] = true;
    }

    ll x;
    cin >> x;
    cout << *lower_bound(ALL(ps), x) << endl;
    return 0;
}


Measured memory_bytes: 2424
#include<stdio.h>

int main()
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);

if(a>=b && b>=c)
 printf("%d %d %d\n",c, b, a);
else if (a>=c && c>=b)
 printf("%d %d %d\n",b, c, a);
else if (c>=a && a>=b)
 printf("%d %d %d\n",b, a, c);
else if (b>=a && a>=c)
 printf("%d %d %d\n",c, a, b);
else if (c>=b && b>=a)
 printf("%d %d %d\n",a, b, c);
else
 printf("%d %d %d\n",a, c, b);

return 0;
}


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

int main() {
  int n;
  std::cin >> n;

  uint64_t max = 0;
  uint64_t sum = 0;
  for (int i = 0; i < n; i++) {
    uint64_t tmp;
    std::cin >> tmp;
    max = std::max(tmp, max);
    sum += tmp;
  }
  std::cout << sum - max / 2 << std::endl;
  return 0;
}


Measured memory_bytes: 256
// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define int long long
#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e4 + 69 , MOD = 1e9 + 7 ;

int n , m , dp[MAXN][MAXN] ;
char arr[MAXN][MAXN] ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n >> m ;
	for ( int i = 1 ; i <= n ; i ++ )
		for ( int j = 1 ; j <= m ; j ++ )
			cin >> arr[i][j] ;
	dp[1][1] = 1 ;
	for ( int i = 1 ; i <= n ; i ++ )
		for ( int j = 1 ; j <= m ; j ++ ) {
			if ( arr[i - 1][j] == '.' )
				dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD ;
			if ( arr[i][j - 1] == '.' )
				dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD ;
		}
	cout << dp[n][m] << "\n" ;
}


Measured memory_bytes: 89344
using System;

public class hello
{
    public static void Main()
    {
        var s = "";
        string[] line = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < 3; i++)
            s += line[i];
        if (s == "110" | s == "001") Console.WriteLine("Open");
        else Console.WriteLine("Close");
    }
}

Measured memory_bytes: 8876
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int N = ReadInt();
            int X = (int)Math.Floor(N / 1.08);
            int Y = (int)Math.Ceiling(N / 1.08);
            if ((int)Math.Floor(X * 1.08) == N) { Console.WriteLine(X); }
            else if ((int)Math.Floor(Y * 1.08) == N) { Console.WriteLine(Y); }
            else { Console.WriteLine(":("); }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
//=============================
void input()
{
    cin>>N;
    A.resize(N);
    rep(i,0,N-1){
        cin>>A[i];
    }
}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    map<int,int> mp;
    for(auto x : A){
        mp[x]++;
    }
    int ans=0;
    for (auto x : mp){
        if (x.first > x.second){
            ans += (x.second);
        }
        else {
            ans +=x.second-x.first;
        }
    }

    cout<<ans<<endl;

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 7040
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

val = abs(a - t + h[0] * 0.006)
ans = 1

for i in range(1, n):
    avg = abs(a - t + h[i] * 0.006)
    if avg < val:
        val = avg
        ans = i + 1
print(ans)

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

int main() {
  string A;
  cin>>A;
  vector<int>a(4);
  for(int i=0;i<4;i++){
    a.at(i)=A.at(i)-'0';
  }
  for(int i=0;i<8;i++){
    int sum =a.at(0);
    string s;
    s+=(char)('0'+a.at(0));
    for(int j=0;j<3;j++){
      if(i>>j&1){
        sum+=a.at(j+1);
        s+='+';
        s+=(char)('0'+a.at(j+1));
      }
      else{
        sum-=a.at(j+1);
        s+='-';
        s+=(char)('0'+a.at(j+1));
      }
    }
    if(sum==7){
      cout<<s<<"=7"<< endl;
      return 0;
    }
  }
}
    


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

long long a, b, g, i, fl, ans;
int main() {
	cin >> a >> b;
	g = __gcd(a, b);
	for(i=2; i*i<=g; i++) {
		fl = 0;
		while(g % i == 0) g /= i, fl = 1;
		ans += fl;
	}
	if(g > 1) ans++;
	cout << ans + 1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <complex>

using namespace std;

int main()
{
  string a, b;
  cin >> a >> b;
  int num = stoi(a+b);
  double sq = sqrt(num);
//  cerr << "num: " << num << endl;
//  cerr << "sqr: " << sq << endl;

  cout << (    ((sq - int(sq)) >= 0.01) ? "No" : "Yes"   ) << endl;
// cout << ( ((num / sq) == sq) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int pow4(int n) {
  if (n == 0) {
    return 1;
  } else {
    return 4 * pow4(n-1);
  }
}

int main()
{
  int n;
  int a, b, c;
  int l[10] = {};
  int i,j,k;
  int sel;
  int ans[4] = {};
  int cnt[4] = {};
  int mp = 10000000;
  int kouho;

  scanf("%d %d %d %d", &n, &a, &b, &c);

  for (i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }

  for (i = 0; i < pow4(n); i++) {
    ans[0] = 0;
    ans[1] = 0;
    ans[2] = 0;
    ans[3] = 0;
    cnt[0] = 0;
    cnt[1] = 0;
    cnt[2] = 0;
    cnt[3] = 0;
    j = i;
    for (k = 0; k < n; k++) {
    sel = j % 4;
    j = j / 4;
    ans[sel] += l[k];
    cnt[sel]++;
    //printf("%d -> %d\n", k, sel);
    }

    if (cnt[0] == 0 || cnt[1] == 0 || cnt[2] == 0) {
      continue;
    }

    kouho = abs(ans[0] - a) + abs(ans[1] - b) + abs(ans[2] - c)
      + 10 * (cnt[0] + cnt[1] + cnt[2] - 3);
    if (mp > kouho ) {
      mp = kouho;
      //printf("%d %d %d %d\n",ans[0], ans[1], ans[2], mp);
    }
  }
  
  printf("%d\n", mp);
  return 0;
}


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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  string S;
  cin >> S;

  if(sz(S)!=26){
    vector<bool> used(26,false);
    rep(i,sz(S))  used.at(S.at(i)-'a')=true;
    rep(i,26){
      if(used.at(i))  continue;
      S+=char(i+'a');
      break;
    }
    cout << S << endl;
    return 0;
  }
  bool flag=true;
  rep(i,26) if(S.at(i)!='z'-i)  flag=false;
  if(flag){
    cout << -1 << endl;
    return 0;
  }

  vector<bool> used(26,false);
  for(int i=26-1;i>=0;i--){
    int now=S.at(i)-'a';
    used.at(now)=true;
    if(i==25) continue;
    if(S.at(i)<S.at(i+1)){
      string ans="";
      rep(j,i)  ans+=S.at(j);
      REP(j,now+1,26){
        if(used.at(j)){
          ans+=char(j+'a');
          break;
        }
      }
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3596
def main():
    a = ['A', 'T', 'G', 'C']
    S = input()
    l = 0
    L = 0
    for s in S:
        if s in a:
            l += 1
        else:
            if l > L:
                L = l
            l = 0
    if l > L:
        L = l
    print(L)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <stack>
using namespace std;
int N;

void dfs(int v,vector <vector <int> > graph, map<pair<int,int>,int> length);
int main()
{
    cin >> N;
    vector <vector <int> > graph1(N);
    map<pair<int,int>,int> length1;
    
    int u,v,w;
    for (int i=0;i<N-1;i++)
    {
        cin >> u >> v >> w;
        u=u-1;
        v=v-1;
        length1.insert(make_pair(make_pair(u,v),w));
        length1.insert(make_pair(make_pair(v,u),w));
        graph1[u].push_back(v);
        graph1[v].push_back(u);
        
    }        
    dfs(0,graph1,length1);
return 0;
}

void dfs(int v, vector <vector <int> > graph, map<pair<int,int>,int> length)
{
    vector<bool> visit(N);
    vector<int> dis(N);
    for (int i=0;i<N;i++)
    {
        visit[i]=false;
        dis[i]=0;
    }
    int w,k;
    stack<int> sta;
    sta.push(v);
    visit[v]=true;
    while (!sta.empty())
    {
        w=sta.top();
        sta.pop();
        for (int i=0;i<graph[w].size();i++)
        {
            k=graph[w][i];
            if (visit[k]==false)
            {
                visit[k]=true;
                dis[k]=dis[w]+length[make_pair(w,k)];
                sta.push(k);
            }
        }
    }
    for (int i=0;i<N;i++) 
    {
        if (dis[i]%2==0) cout << 0 << endl;
        else cout << 1 << endl;
    }
return ;
}


Measured memory_bytes: 36864
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>	
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn

int main()
{
	IO;
	int n{}, prev{};
	cin>>n;
	set<int>s;
	s.insert(n);
	while(true)
	{
    	 prev = s.size();
		if(n&1)s.insert(3*n+1),n=3*n+1;
		else s.insert(n/2),n/=2;
		if(prev == s.size()){cout<<s.size()+1<<'\n';break;}
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
template<typename T>
inline void read(T&x){
    x=0;int f=1;char ch = getchar();
    while(ch<'0' ||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); }
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
    x*=f;
}
 
void solve() {
	int a, b;
	cin >> a >> b;
	cout << a * 1ll * b / __gcd(a, b);
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    for(int i = 1; i <= t; i++) {
        solve();
    }
    return 0;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	int a = 0, b = 0, c = 0;
	for(int i = 0; i < N; i++) {
		int h;
		cin >> h;
		if(h == 3) a++;
		if(h == 2) b++;
		if(h == 1) c++;
	}

	vector<vector<vector<double> > > dp(N + 1, vector<vector<double> >(N + 1, vector<double>(N + 1, 0.0)));

	for(int i = 0; i <= N; i++) {
		for(int j = 0; j <= N - i; j++) {
			for(int k = 0; k <= N - j - i; k++) {
				double h = i + j + k;
				double out = h > 0 ? N / h : 0;
				if(k > 0) out += k / h * dp[i][j][k - 1];
				if(j > 0) out += j / h * dp[i][j - 1][k + 1];
				if(i > 0) out += i / h * dp[i - 1][j + 1][k];
				dp[i][j][k] = out;
			}
		}
	}
	cout << fixed << setprecision(9) << dp[a][b][c] << endl;
}


Measured memory_bytes: 216832
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n,memo[5050][5050];
bool done[5050][5050];
string s;

int solve(int i, int j){
	if(!(i<n && j<n)){
		return 0;
	}
	if(done[i][j]){
		return memo[i][j];
	}
	done[i][j] = true;
	if(s[i]!=s[j]){
		return memo[i][j] = 0;
	}
	return memo[i][j] = solve(i+1,j+1)+1;
}

int main(void){
	int i,j,ans=0;
	cin >> n;
	cin >> s;
	for(i=0; i<n; ++i){
		for(j=0; j<i; ++j){
			ans = max(ans,min({solve(j,i),i-j,n-i}));
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U> void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

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

   int maxh = 0, ans = 0;
   for (int i = 0; i < n; ++i) {
      if (maxh <= h[i]) {
         ++ans;
      }
      chmax(maxh, h[i]);
   }
   cout << ans << endl;

   return 0;
}


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

using namespace std;

int main()
{
	int V, E;

	scanf("%d %d", &V, &E);

	int *box, *pos;
	box = (int*)malloc(sizeof(int) * V);
	pos = (int*)malloc(sizeof(int) * V);
	for(int i = 0; i < V; i++){
		box[i] = i;
		pos[i] = i;
	}

	int from, to;
	for(int i = 0; i < E; i++){
		scanf("%d %d", &from, &to);

		int k = pos[to];
		while(pos[to] < pos[from]){
			int tmp = box[k];
			int tmp2 = pos[box[k]];

			pos[box[k]] = pos[box[k + 1]];
			box[k] = box[k + 1];

			pos[box[k + 1]] = tmp2;
			box[k + 1] = tmp;
			k++;
		}
	}

	for(int i = 0; i < V; i++){
		if(i)
			printf(" ");
		printf("%d", box[i]);
	}

	return 0;
}


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

int main(){
	int A,B;
	
	cin>>A>>B;
	
	if(A==B)cout<<"Draw";
	else{
		if(A==1)cout<<"Alice";
		else if(B==1)cout<<"Bob";
		else if(A>B)cout<<"Alice";
		else cout<<"Bob";
		
	}
	
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        HashSet<Integer> set = new HashSet<>();
        for(int i = 0; i < n; i++) {
            int a = in.nextInt();
            if(set.contains(a)) set.remove(new Integer(a));
            else set.add(a);
            
        }
        System.out.println(set.size());
    }
}


Measured memory_bytes: 63220
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author GYSHGX868
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      char a = in.nextChar();
      char b = in.nextChar();
      if (a == 'H') {
        out.printLine(b);
      } else {
        out.printLine(b == 'H' ? 'D' : 'H');
      }
    }

  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public char nextChar() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      return (char) c;
    }

    public interface SpaceCharFilter {
      boolean isSpaceChar(int ch);

    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void printLine(char i) {
      writer.println(i);
    }

    public void close() {
      writer.close();
    }

  }
}



Measured memory_bytes: 21588
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<bitset>
#include<deque>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 200050
#define maxm 100010
#define mod 1000000007
#define inf 1000000007
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int quick_pow(int x,int p)
{
    int an=1,po=x;
    while(p)
    {
        if(p&1)  an=1ll*an*po%mod;
        po=1ll*po*po%mod;
        p>>=1;
    }
    return an;
}
int fac[maxn*2],inv[maxn*2];
int C(int x,int y)
{
    if(x<y)  return 0;
    return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
    fac[0]=1;
    for(int i=1;i<=400000;i++)  fac[i]=1ll*fac[i-1]*i%mod;
    inv[400000]=quick_pow(fac[400000],mod-2);
    for(int i=399999;i>=0;i--)  inv[i]=1ll*inv[i+1]*(i+1)%mod;
    int n=read(),k=read();
    int ans=0;
    for(int i=0;i<=min(n,k);i++) ans=(ans+1ll*C(n-1,i)*C(n,i)%mod)%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
typedef long long lint;
const int mod=1000000007;
int k,n=-1,cnt=13;
char c[15];
lint fact[2000010],inv[2000010];
int main(){
	while(1){
		*c=getchar_unlocked();
		if(*c=='\n')break;
		k*=10;
		k+=*c-'0';
	}
	while(getchar_unlocked()!=-1)n++;
	fact[0]=1;
	for(int i=1;i<=n+k;i++)fact[i]=fact[i-1]*i%mod;
	inv[n+k]=1;
	lint now=fact[n+k];
	int b=mod-2;
	while(b){
		if(b&1){
			inv[n+k]*=now;
			inv[n+k]%=mod;
		}
		b>>=1;
		now*=now;
		now%=mod;
	}
	for(int i=n+k-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	lint ans=1;now=1;
	for(int i=1;i<=k;i++){
		now*=25;
		now%=mod;
		ans+=fact[n+k]*inv[n+k-i]%mod*inv[i]%mod*now;
		ans%=mod;
	}
	*(c+14)='\n';
	while(ans){
		*(c+cnt)=ans%10+'0';
		ans/=10;
		cnt--;
	}
	fwrite(c+cnt+1,1,14-cnt,stdout);
	return 0;
}


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

const int INF=10000002ll;

int n,m[100][100];

void dijkstra();

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      m[i][j]=INF;
    }
  }
  
  int k,c,u,v;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      m[u][v]=c;
    }
  }

  dijkstra();

  return(0);
}

void dijkstra(){
  int mn,d[100],sn[100];
  
  for(int i=0;i<n;i++){
    d[i]=INF;
    sn[i]=0;
  }

  d[0]=0;
  while(1){
    mn=INF;
    int u=-1;
    for(int i=0;i<n;i++){
      if(mn>d[i] && sn[i]==0){
	u=i;
	mn=d[i];
      }
    }
    if(u==-1)break;
    sn[u]=1;
    for(int i=0;i<n;i++){
      if(sn[i]==0 && m[u][i]!=INF){
	if(d[i]>d[u]+m[u][i]){
	  d[i]=d[u]+m[u][i];
	}
      }
    }
  }

  int ans;
  for(int i=0;i<n;i++){
    cout<<i<<" ";
    if(d[i]==INF)cout<<"-1"<<endl;
    else cout<<d[i]<<endl;
  }
}

Measured memory_bytes: 1200
#include <cstdio>
typedef long long LL;
const int N=200005,mo=1000000007;
int fst[N],v[N],pre[N],sz[N],tot=1,cntv,cnte,ed,t,n;
LL fac[N],inv[N];
bool vis[N];
struct Edge{
	int to,nxt;
}e[N*2];
void addedge(int x,int y){
	e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;
}
void dfs(int x,int fa){
	vis[x]=1;cntv++;
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;cnte++;
		if (y!=fa){
			if (vis[y]) ed=i;
				else dfs(y,x);
		}
	}
}
void dfs2(int x,int fa){
	pre[x]=fa;
	for (int i=fst[x];i;i=e[i].nxt)
		if (i/2!=ed/2 && e[i].to!=fa) dfs2(e[i].to,x);
	if (pre[pre[x]]<x) v[++t]=x;
}
LL C(int n,int m){
	return fac[n]*inv[m]%mo*inv[n-m]%mo;
}
int dfs3(int x){
	LL cnt=1;sz[x]=0;
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;
		if (y<pre[x]){
			int z=dfs3(y);
			sz[x]+=sz[y];
			cnt=cnt*z%mo*C(sz[x],sz[y])%mo;
		}
	}
	sz[x]++;
	return cnt;
}
int solve(){
	t=0;dfs2(e[ed^1].to,e[ed].to);
	LL cnt=1;
	for (int i=1,x=0;i<=t;i++){
		int y=dfs3(v[i]);
		x+=sz[v[i]];
		cnt=cnt*y%mo*C(x,sz[v[i]])%mo;
	}
	return cnt;
}
LL ksm(LL x,int y){
	LL i=1;
	for (;y;y>>=1,x=x*x%mo)
		if (y&1) i=i*x%mo;
	return i;
}
void Pre(){
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mo;
	inv[n]=ksm(fac[n],mo-2);
	for (int i=n;i>=1;i--) inv[i-1]=inv[i]*i%mo;
}
int main(){
	scanf("%d\n",&n);
	for (int i=0;i<n*2;i++){
		int x,y;
		scanf("%d%d\n",&x,&y);
		addedge(x,y+n);
		addedge(y+n,x);
	}
	n*=2;Pre();
	LL ans=1;
	for (int i=1,x=0;i<=n;i++)
	if (!vis[i]){
		cntv=cnte=0;
		dfs(i,0);
		if (cntv*2!=cnte){
			printf("0\n");
			return 0;
		}
		int cnt=solve();
		ed^=1;
		cnt+=solve();
		x+=cntv;
		ans=ans*cnt%mo*C(x,cntv)%mo;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long A, N;
    long long B;
    cin >> A >> B>> N;
    long long t = N / B;
    long long t2 = t*B - 1;
    long long x;
    if(t == 0) x = N;
    else x = t2;
    long long s =  A*x / B;
    long long s2 = (x / B)*A;
    cout << s - s2 << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

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

int n;


int gcd(int a, int b) {
	if (a < b) gcd(b, a);
	int r;
	while (r = a % b) {
		a = b;
		b = r;
	}
	return b;
}

int main() {

	int x;
	cin >> n >> x;
	vector<int> w;
	FOR(i, n) {
		int a;
		cin >> a;
		w.push_back(abs(x - a));
	}

	int a = w[0];
	FOR(i, n-1) {
		a = gcd(a, w[i + 1]);
	}
	cout << a << endl;

	return 0;
}

Measured memory_bytes: 892
s = input()
if s[0] == s[1] == s[2] == s[3]:
    print("No")
elif s[0] == s[1]:
    if s[2] == s[3]:
        print("Yes")
    else:
        print("No")
elif s[0] == s[2]:
    if s[1] == s[3]:
        print("Yes")
    else:
        print("No")
elif s[0] == s[3]:
    if s[1] == s[2]:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<int>B(N);
  for(int i=0;i<N;i++)
    B.at(i)=i-A.at(i);
  sort(B.begin(),B.end());
  int64_t ans=0;
  for(int i=0;i<N-1;i++){
   auto itr=lower_bound(B.begin(),B.end(),i+A.at(i));
    auto itr1=upper_bound(B.begin(),B.end(),i+A.at(i));
    int64_t k=distance(itr,itr1);
    ans+=k;
  }cout<<ans<<endl;
   return 0;
}

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

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

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


int main() {
    int N;
    cin >> N;
    int ans = 0;
    vector<int> V(N), C(N);
    REP(i, N) cin >> V[i];
    REP(i, N) cin >> C[i];
    REP(i, N) if (V[i] > C[i]) ans += V[i] - C[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      String a = sc.next();

      char b = a.charAt(0);
      char c = a.charAt(1);

      if(b=='9'||c=='9'){
        System.out.println("Yes");
      }else{
          System.out.println("No");
      }
  }
}

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

int main()
{
  int a,b,c,d,e,f;
  cin >> a;
  cin >> b;
  c=(a+b);
  d=((c+1)/2);
  e=(c%2);
  f=(c/2);
  if (e==0)
  {
    cout << f<< endl;
  }
  else 
  {
    cout << d<< endl;
  }
  return 0;
 }

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int H1, M1, H2, M2, K; 
	cin >> H1 >> M1 >> H2 >> M2 >> K; 
	int a = H1 * 60 + M1; 
	int b = H2 * 60 + M2; 
	cout << b - a - K << endl; 
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    double R;
    cin >> R;
    cout << R * M_PI * 2 << '\n';

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3800
n = input()
if n[0]==n[1] and n[2]==n[3] and n[0]!=n[2]:
    print('Yes')
elif n[0]==n[2] and n[1]==n[3] and n[0]!=n[1]:
    print('Yes')
elif n[0]==n[3] and n[1]==n[2] and n[0]!=n[1]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,k = inm()
h = inl()
if n<=k:
    print(0)
    exit()
h.sort()
print(sum(h[:(n-k)]))


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

int main() {
  int mod=1000000007;
  long n,k;
  cin >> n>>k;
  vector<int>a(n);
  rep(i,n){
    cin>>a.at(i);
  }
  long ans=0;
  long u=0;
  rep(i,n){
    rep2(j,i+1,n){
      if(a.at(i)>a.at(j)){
        ans++;
      }
      if(a.at(i)<a.at(j)){
        u++;
      }
    }
  }
  long an=k*(k+1)/2%mod;
  long bn=k*(k-1)/2%mod;
  u=u*bn%mod;
  ans=ans*an%mod;
  ans=(ans+u)%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main (){
  ll A, B, K;
  cin >> A >> B >> K;
  if(K>=(A + B)){
    cout << 0 <<" "<< 0 << endl;
    return 0;
  }
  else if(A >= K){
    cout << A - K <<" "<< B << endl;
    return 0;
  }
  else {
  	cout << 0 << " "<< B + A -K << endl;
    return 0;
  }
	
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    private static final Scanner scan = new Scanner(System.in);
    static boolean flag = false;

    public static void main(String[] args){

        int n = scan.nextInt();
        Integer[] d = new Integer[6];
        Dice[] dices = new Dice[n];


        for(int i = 0; i < n ; i++){
            for(int j = 0; j < 6; j++){
                d[j] = scan.nextInt();
            }
            Object[] objs = (Object[]) d;
            dices[i] = new Dice((Object[]) objs);
        }

        boolean ans = true;
        for(int i = 0; ans && i < n; i++){
            for(int j = i + 1; j < n; j++){
                if(dices[i].equals(dices[j])){
                    ans = false;
                    break;
                }
            }
        }
        System.out.println(ans? "Yes" : "No");
    }
}

class Dice{

    int[] _d = new int[6];
    public static final int
        TOP = 0, SOUTH = 1, EAST = 2,
        WEST = 3, NORTH = 4, BOTTOM = 5; // ?????°

    public Dice(Object... obj){ // ?????????????????????
Integer c[]=new Integer[6];
        for(int i = 0; i < 6; i++){

// System.out.println(obj.getClass());
            if(obj instanceof Integer[]){
// System.out.println("qwe");
                Integer[] d = (Integer[])obj;
                _d[i] = d[i];
            }
        }
    }

    public int[] showAll(){
        return _d;
    }

    @Override
    public boolean equals(Object obj){
        boolean result = false;
        Dice dice = (Dice) obj;
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                if(Arrays.equals(showAll(), dice.showAll())){
                    result = true;
                    break;
                }
                dice.rollEast();
            }
            for(int j = 0; j < 4; j++){
                if(Arrays.equals(showAll(), dice.showAll())){
                    result = true;
                    break;
                }
                dice.rollNorth();
            }
            if(Arrays.equals(showAll(), dice.showAll())){
                result = true;
                break;
            }
            dice.rollRight();
        }
        return result;
    }

    public void rollSouth(){
        int tmp = _d[TOP];
        _d[TOP] = _d[NORTH];
        _d[NORTH] = _d[BOTTOM];
        _d[BOTTOM] = _d[SOUTH];
        _d[SOUTH] = tmp;
    }

    public void rollNorth(){
        int tmp = _d[TOP];
        _d[TOP] = _d[SOUTH];
        _d[SOUTH] = _d[BOTTOM];
        _d[BOTTOM] = _d[NORTH];
        _d[NORTH] = tmp;
    }

    public void rollEast(){
        int tmp = _d[TOP];
        _d[TOP] = _d[WEST];
        _d[WEST] = _d[BOTTOM];
        _d[BOTTOM] = _d[EAST];
        _d[EAST] = tmp;
    }

    public void rollWest(){
        int tmp = _d[TOP];
        _d[TOP] = _d[EAST];
        _d[EAST] = _d[BOTTOM];
        _d[BOTTOM] = _d[WEST];
        _d[WEST] = tmp;
    }

    public void rollRight(){
        int tmp = _d[SOUTH];
        _d[SOUTH] = _d[WEST];
        _d[WEST] = _d[NORTH];
        _d[NORTH] = _d[EAST];
        _d[EAST] = tmp;
    }
}

Measured memory_bytes: 29608
#include<iostream>
using namespace std;
int main()
{
    long long a,b=1,t,q=1e18;
    double d=1;
    cin>>t;
    while(t--)
    {
        cin>>a;
        d*=a;
        b*=a;
    }
    if(d>q||b>q)
        cout<<"-1"<<endl;
    else
        cout<<(long long)b<<endl;
}

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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> grid(h);
	rep (i, h)
		cin >> grid[i];

	for (int i = h - 1; i >= 0; i--) {
		auto res = find_if(all(grid[i]), [](char c) { return c == '#'; });
		if (res == grid[i].end()) {
			grid.erase(grid.begin() + i);
			h--;
		}
	}

	for (int i = w - 1; i >= 0; i--) {
		bool flag = true;
		rep (j, h) {
			if (grid[j][i] == '#') {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			rep (j, h)
				grid[j].erase(grid[j].begin() + i);
		}
	}

	rep (i, h)
		cout << grid[i] << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

int a,b;
vector<int> That;
vector<int> This;

vector<char> word;
vector<int> iword;

void init(){
	That.push_back(19);
	That.push_back(7);
	That.push_back(0);
	That.push_back(19);
	This.push_back(19);
	This.push_back(7);
	This.push_back(8);
	This.push_back(18);
}

bool ab(){
	for(int i=2; i<=26; i++){
		if(26%i==0){
			if(a%i==0)return false;
		}
	}
	return true;
}

int f(int c){
	return (a*c+b)%26;
}

int change(char c){
	if(c>='a'&&c<='z')return c-'a';
	return -1;
}
void getWord(string s,int *n){
	word.clear();
	for(; *n<s.size(); *n+=1){
		// cout<<"s:"<<s<<endl;
		// cout<<"j:"<<*n<<" "<<s.at(*n)<<endl;
		if(s.at(*n)==' '||s.at(*n)=='\0'){
			*n+=1;
			return;
		}
		//cout<<"j:"<<*n<<endl;
		word.push_back(s.at(*n));
	}
}

void getIword(){
	iword.clear();
	for(int i=0; i<word.size(); i++){
		iword.push_back(f(change(word.at(i))));
	}
}


char changeC(int i){
	return i+'a';
}

int main(){
	int n;
	string s;
	init();
	cin>>n;
	cin.ignore();
	//cout<<n<<endl;
	for(int i=0; i<n; i++){
		getline(cin,s);
		//cout<<s<<endl;
		bool flag=false;
		for(a=0; a<26; a++){
			for(b=0; b<26; b++){
				if(ab()){
					int j=0;
					while(j<s.size()){
						//<<j<<endl;
						getWord(s,&j);
						if(word.size()==4){
							getIword();
							if(iword==This||iword==That){
								// cout<<"a:"<<a<<" b:"<<b<<endl;
								// cout<<"iword:";
								// for(int i=0; i<iword.size(); i++){
								// 	cout<<changeC(iword.at(i));
								// }
								//cout<<endl;
								flag=true;
								break;
							}
						}
					}
				}
				if(flag)break;
			}
			if(flag)break;
		}
		for(int i=0; i<s.size(); i++){
			if(change(s.at(i))==-1)cout<<' ';
			else cout<<changeC(f(change(s.at(i))));
		}
		cout<<endl;
		//cout<<"a:"<<a<<" b:"<<b<<endl;
	}
	

}

Measured memory_bytes: 1228
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

void solve(void){
    int N;
    cin >> N;
    vector <ll> as(N), bs(N);
    repr(N, i) {
        cin >> as[i] >> bs[i];
    }
    ll ans = 0LL;
    rep(N, i) {
        as[i] += ans;
        if (as[i] % bs[i] == 0LL) continue;
        ll dif = bs[i] - (as[i] % bs[i]);
        ans += dif;
    }

    cout << ans << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for (; sc.hasNext();) {
			int sum = 0;
			char[] swap = sc.nextLine().toCharArray(); //char型の配列に格納する

			for (int i = 0; i < swap.length; i++) {
				sum = sum + Character.getNumericValue(swap[i]);
			}
			if (sum != 0) {
				System.out.println(sum);
			} else {
				break;
			}
		}

	}

}



Measured memory_bytes: 26656
#include <algorithm>
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

void printArray(int *A, int n) {
  rep(i, n) {
    std::cout << A[i];
    if (i == n - 1)
      std::cout << '\n';
    else
      std::cout << ' ';
  }
}

void countingSort(int *A, int *B, int n, int k) {
  int C[k + 1];
  rep(i, k + 1) C[i] = 0;

  rep(i, n) C[A[i]]++;
  for (int i = 1; i < k + 1; ++i)
    C[i] += C[i - 1];

  for (int i = n - 1; i >= 0; --i) {
    B[C[A[i]] - 1] = A[i];
    C[A[i]]--;
  }
}

int main() {
  int n;
  std::cin >> n;
  int A[n], B[n];
  rep(i, n) std::cin >> A[i];

  int max = *std::max_element(A, A + n);
  countingSort(A, B, n, max);

  printArray(B, n);

  return 0;
}



Measured memory_bytes: 18748
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[10010]; 
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	long long ans=0;
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			while(a[i]%2==0){
				a[i]/=2;
				ans++;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 384
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

bool ng[310];
int a[310][310];
signed main() {
    int N, M; cin >> N >> M;
    rep(i,0,N) rep(j,0,M) cin >> a[i][j], a[i][j]--;

    int ans = INF;
    rep(k,0,M) {
        vector<int> v(M);
        rep(i,0,N) {
            rep(j,0,M) {
                int sport = a[i][j];
                if(!ng[sport]) {
                    v[sport]++;
                    break;
                }
            }
        }
        int idx = max_element(v.begin(), v.end()) - v.begin();
        chmin(ans, v[idx]);
        ng[idx] = true;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024