akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

bool dp[82][82][14010];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;cin>>H>>W;
    vector<vector<int>> A(H+1,vector<int>(W+1)),B(H+1,vector<int>(W+1));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>A[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>B[i][j];
        }
    }
    
    dp[0][0][7000+A[0][0]-B[0][0]]=1;
    dp[0][0][7000+B[0][0]-A[0][0]]=1;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int t=100;t<13900;t++){
                if(dp[i][j][t]){
                    dp[i][j+1][t+A[i][j+1]-B[i][j+1]]=1;
                    dp[i][j+1][t+B[i][j+1]-A[i][j+1]]=1;
                    
                    dp[i+1][j][t+A[i+1][j]-B[i+1][j]]=1;
                    dp[i+1][j][t+B[i+1][j]-A[i+1][j]]=1;
                }
            }
        }
    }
    
    int ans=INF;
    
    for(int t=0;t<14000;t++){
        if(dp[H-1][W-1][t]) ans=min(ans,abs(t-7000));
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 90624
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<queue>
using namespace std;

int k[10];
string s[30];
signed main(){
	int a;
	while (cin >> a, a) {
		for (int i = 0; i < a; i++)k[i] = i;
		int b, c, d; cin >> b >> c >> d;
		for (int e = 0; e < d; e++) {
			string f; cin >> f;
			s[e] = "0" + f + "0";
			for (int g = 0; g < a - 1; g++) {
				if (f[g] == '1') {
					swap(k[g], k[g + 1]);
				}
			}
		}
		b--; c--;
		int atari = k[c];
		if (b == atari) { puts("0"); continue; }
		for (int i = 0; i < a; i++)k[i] = i;
		for (int i = 0; i < d; i++) {
			for (int j = 1; j < a; j++) {
				if (s[i][j] == '1') {
					swap(k[j - 1], k[j]);
				}
				else {
					if (s[i][j - 1] == '0'&&s[i][j + 1] == '0') {
						if ((k[j - 1] == atari&&k[j] == b) || (k[j] == atari&&k[j - 1] == b)) {
							cout << i + 1 << " " << j << endl;
							goto l;
						}
					}
				}
			}
		}
		puts("1");
	l:;
	}
}

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

int main() {
  int n;
  cin >> n;
  
  set<int> a;
  for(int i = 0; i < n; i++){
    int j;
    cin >> j;
    a.insert(j);
  }
  
  if(a.size() == n){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
    
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    string s;
    cin>>s;
    VV dig(10);

    rep(i,n){
        dig[s[i]-'0'].pb(i);
    }

    ll ans=0;

    //dbg(dig);
    
    rep(i,10){
        Vec &xind = dig[i];
        if(xind.size()==0LL){
            continue;
        }
        ll x = dig[i][0];
        
        rep(j,10){
            Vec &yind = dig[j];
            if(yind.size()==0LL){
                continue;
            }
            auto yitr = upper_bound(ALL(yind),x);
            if(yitr==yind.end()){
                continue;
            }
            ll y = *yitr;
            rep(k,10){

                Vec &zind = dig[k];
                if(zind.size()==0LL){
                    continue;
                }
                auto zitr = upper_bound(ALL(zind),y);
                if(zitr==zind.end()){
                    continue;
                }
                ans++;
//                dbg(i);
//                dbg(j);
//                dbg(k);
            }
        }
    }
    
    cout<<ans<<endl;
    return  0;
}


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

using namespace std;

int cnt = 0;
int MOD = 1000000007;

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    int p[N];
    for(int i=0;i<N;i++){
        cin >> p[i];
    }
    
    int a=0,b=0,c=0;
    for(int i=0;i<N;i++){
        if(p[i]>B) c++;
        else if(p[i]>A) b++;
        else a++;
    }
    
    cout << min({a,b,c}) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdint>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>

using Item = uint64_t;
using ItemSet = std::vector<Item>;
using Average = double;

size_t choose(size_t n, size_t k) {
    if ((k == n) || (k == 0)) {
        return 1;
    }

    if (k == 1) {
        return n;
    }

    size_t v = n * choose(n - 1, k);
    return v / (n - k);
}

void searchPlateau(const ItemSet& items, size_t pos, size_t& fullWidth, size_t& leftWidth) {
    fullWidth = 1;
    leftWidth = 1;
    auto i = pos;
    const auto num = items[i];

    while(i > 0) {
        if (items[i - 1] != num) {
            break;
        }
        ++fullWidth;
        ++leftWidth;
        --i;
    }

    i = pos;
    while((i + 1) < items.size()) {
        if (items[i + 1] != num) {
            break;
        }
        ++fullWidth;
        ++i;
    }

    return;
}

void solve(size_t allSize, size_t minSize, size_t maxSize, ItemSet& items) {
    std::sort(items.begin(), items.end(), std::greater<ItemSet::value_type>());

    Average average = 0.0;
    for(size_t i=0; i<minSize; ++i) {
        average += static_cast<decltype(average)>(items[i]);
    }
    average /= static_cast<decltype(average)>(minSize);

    std::cout.setf(std::ios_base::fixed,std::ios_base::floatfield);
    std::cout << std::setprecision(6);
    std::cout << average << "\n";

    size_t pos = minSize - 1;  // to array index
    size_t fullWidth = 0;
    size_t leftWidth = 0;
    searchPlateau(items, pos, fullWidth, leftWidth);

    size_t comboSize = 0;
    if (items[0] == items[minSize-1]) {
        size_t size = std::min(fullWidth, maxSize);
        for(size_t i=minSize; i<=size; ++i) {
            comboSize += choose(fullWidth, i);
        }
    } else {
        comboSize = choose(fullWidth, leftWidth);
    }

    std::cout << comboSize << "\n";
    return;
}

int main(int argc, char* argv[]) {
    size_t allSize = 0;
    size_t minSize = 0;
    size_t maxSize = 0;

    std::string paramLine;
    std::getline(std::cin, paramLine);
    std::istringstream isp(paramLine);
    isp >> allSize >> minSize >> maxSize;

    std::string itemLine;
    std::getline(std::cin, itemLine);
    std::istringstream isi(itemLine);

    ItemSet items;
    for(size_t i=0; i<allSize; ++i) {
        Item item = 0;
        isi >> item;
        items.push_back(item);
    }

    solve(allSize, minSize, maxSize, items);
    return 0;
}


Measured memory_bytes: 256
N= int(input())
ls = []

for i in range(N+1):
  if i % 3 == 0 and i % 5 == 0:
    ls.append(0)
  elif i % 3 == 0:
    ls.append(0)
  elif i % 5 == 0:
    ls.append(0)
  else:
    ls.append(i)

print(sum(ls))


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

int main() {
  string S;
  cin >> S;
  if(S[0]==S[1] && S[2]==S[3] && S[0]!=S[2] || S[0]==S[2] && S[1]==S[3] && S[0]!=S[1] || S[0]==S[3] && S[1]==S[2] && S[0]!=S[1]){
    cout<< "Yes" <<endl;
  }
  else{
    cout<< "No" <<endl;
  }
}

Measured memory_bytes: 256
a, b = map(int, input().split())
L = [input() for _ in range(a)]
L1 = []
L3 = []
for i in range(a):
  if not L[i] == "."*b:
    L1.append(L[i])
L2 = list(map(list, zip(*L1)))
for k in range(len(L2)):
  if not "".join(L2[k]) == "."*len(L2[k]):
    L3.append("".join(L2[k]))
L4 = list(map(list, zip(*L3)))
for v in range(len(L4)):
  print("".join(L4[v]))

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    vector<ll> A;
    vector<ll> SUM, XOR;

    void input() {
        cin >> N;
        A.resize(N + 1);
        rep(i, 0, N) cin >> A[i + 1];
    }

    bool check(int s, int t) {
        //(s,t]
        return (XOR[t] ^ XOR[s]) == (SUM[t] - SUM[s]);
    }

    void solve() {
        input();
        SUM.resize(N + 1);
        XOR.resize(N + 1);
        for (int i = 1; i <= N; ++i) {
            SUM[i] = SUM[i - 1] + A[i];
            XOR[i] = XOR[i - 1] ^ A[i];
        }

        int pt = 1;
        ll ans = 0ll;
        for (int i = 0; i < N; ++i) {
            while (pt < N && check(i, pt + 1)) {
                pt++;
            }
            ans += (pt - i);
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,w,i,j;
    scanf("%lld %lld",&n,&w);
    long long int ar[n+6][5]={0},dp[n+6][w]={0};
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=2;j++)
        {
            scanf("%lld",&ar[i][j]);
        }
    }
    dp[1][ar[1][1]]=ar[1][2];
    for(i=2;i<=n;i++)
    {
        dp[i][ar[i][1]]=ar[i][2];
        for(j=1;j<=w;j++)
        {
            if(dp[i-1][j]!=0)
            {
                if(ar[i][1]==j)
                {
                    dp[i][j]=max(ar[i][2],dp[i-1][j]);\
                    if(j+ar[i][1]<=w)
                    {
                        dp[i][j+ar[i][1]]=max(dp[i-1][j]+ar[i][2],dp[i][j+ar[i][1]]);
                    }
                }
                else
                {
                    dp[i][j]=max(dp[i-1][j],dp[i][j]);
                    if(j+ar[i][1]<=w)
                    {
                        dp[i][j+ar[i][1]]=max(dp[i-1][j]+ar[i][2],dp[i][j+ar[i][1]]);
                    }
                }
            }
        }
    }
    long long int max1=0;
    for(j=1;j<=w;j++)
    {
        max1=max(max1,dp[n][j]);
    }
    printf("%lld\n",max1);
}


Measured memory_bytes: 82944
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

int main(void){
	int a , b;
	while(scanf("%d %d\n" , &a , &b)!=EOF)
		printf("%d\n" , (int)log10(a+b) + 1);
	return 0;
}

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int N = 110;
const ll V = 1000 * N + 10, inf = 1e18;
int n;
ll dp[N][V];
ll cost[N], profit[N], w;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> w;
    ll maxval = 1000 * n + 5;
    for (int i = 1; i <= n; i++) cin >> cost[i] >> profit[i];
    for (int i = 0; i <= maxval; i++) dp[1][i] = inf;
    dp[1][0] = 0;
    dp[1][profit[1]] = cost[1];
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= maxval; j++) {
            dp[i][j] = dp[i - 1][j];
            if (profit[i] > j) continue;
            dp[i][j] = min(dp[i][j], cost[i] + dp[i - 1][j - profit[i]]);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= maxval; i++) {
        if (dp[n][i] <= w) ans = i;
    }
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 87424
#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,x;
	scanf("%d%d",&m,&x);
	int n=2*m-1;
	if(x==1||x==n){
		puts("No");
		return 0;
	}
	puts("Yes");
	if(n==3){
		printf("1\n2\n3\n");
		return 0;
	}
	if(x==2){
		int cnt=4;
		for(int i=1;i<=m-2;++i)printf("%d\n",++cnt);
		printf("3\n2\n1\n4\n");
		for(int i=m+3;i<=n;++i)printf("%d\n",++cnt);
		return 0;
	}
	vector<int> tmp;
	for(int i=1;i<=n;++i)
		if(i!=x-1&&i!=x&&i!=x+1&&i!=x-2)
			tmp.push_back(i);
	int cnt=-1;
	for(int i=1;i<=m-2;++i)printf("%d\n",tmp[++cnt]);
	printf("%d\n%d\n%d\n%d\n",x-1,x,x+1,x-2);
	for(int i=m+3;i<=n;++i)printf("%d\n",tmp[++cnt]);
	return 0;
}

Measured memory_bytes: 2420
def operations():
    if op == '+':
        return a + b
    elif op == '-':
        return a - b
    elif op == '*':
        return a * b
    else:
        return a // b


while True:
    a, op, b = input().split()
    if op == '?':
        break
    a, b = int(a), int(b)
    r = operations()
    print(r)



Measured memory_bytes: 5600
// Author - Abhishek giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 100000000007
#define V(type) vector<type> 
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)

/*##################################################################################*/


/*
bitset<10000000> prime ;
void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 10000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*i ; j <= 10000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}
*/

bool isprime(long n)
{
    for(int i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}


/*
ll fib(int n) 
{ 
  ll a = 0, b = 1, c, i; 
  if( n == 0) 
    return a; 
  for (i = 2; i <= n; i++) 
  { 
    c = (a + b); 
    a = b; 
    b = c; 
  } 
  return b; 
}
*/


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


ll findgrouplcm(ll arr[], ll n) 
{ 
    ll ans = arr[0]; 
  
    for (ll i = 1; i < n; i++) 
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));
  
    return ans; 
}



ll powerwithmod(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}

ll setBitNumber(ll n) 
{ 
    n |= n >> 1; 
    n |= n >> 2; 
    n |= n >> 4; 
    n |= n >> 8; 
    n |= n >> 16; 
    n |= n >> 32;
    n = n + 1; 
  
    return (n >> 1); 
} 
void decToBinary(ll n,string &s) 
{ 
    for (int i = 63; i >= 0; i--) { 
        int k = n >> i; 
        if (k & 1) 
            s += "1"; 
        else
            s += "0"; 
    } 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        int n,k;
        in(n)>>k;
        vector<int> v(n);
        for(int i = 0 ; i < k ; i++){
            int type ;
            in(type);
            while(type--){
                int temp;
                in(temp);
                v[temp-1] += 1 ; 
            }
        }
        cout<<count(v.begin(),v.end(),0);
    }
    return 0;
}

Measured memory_bytes: 3556
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

public class Main {

	static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {

		// --- input ---
		int[] l1 = getNums(in.readLine().split(" "), 2);
		int[] vals = getNums(in.readLine().split(" "), l1[0]);
		in.close();

		// --- resolv ---
		HashMap<Integer, Integer> map = new HashMap<>();
		for(int v : vals) {
			if(map.containsKey(v)) {
				map.put(v, map.get(v) + 1);
			} else {
				map.put(v, 1);
			}
		}

		Integer[] ary = map.values().toArray(new Integer[map.size()]);
		Arrays.parallelSort(ary, (a,b)->b-a);

		int ans = 0;
		for(int i=0; i < ary.length; i++) {
			if(i < l1[1]) {
				continue;
			}
			ans += (int)ary[i];
		}

		System.out.println(ans);
	}

	public static int[] getNums(String[] vals, int num) {
		int[] vAry = new int[num];
		for(int i=0; i < num; i++) {
			vAry[i] = Integer.parseInt(vals[i]);
		}
		return vAry;
	}
}

Measured memory_bytes: 49884
#!/usr/bin/python
B=999999937
P=1000000007

def gen_hash(s,hash):
	c=0
	for i in range(len(s)):
		c=(c*B+s[i])%P
		hash[i]=c

import sys
s=[ord(e) for e in sys.stdin.readline().strip()]
ls=len(s)
v=[0]*ls
hsh=[0]*10001
gen_hash(s,v)
q=[ord(e) for e in sys.stdin.readline().strip()]
lq=len(q)
gen_hash(q,hsh)
hash=hsh[lq-1]
Brev=pow(B,lq,P)
r=[]
for i in range(lq-1,ls):
	if v[i]==((v[i-lq] if i>=lq else 0)*Brev+hash)%P:
		r.append(i-lq+1)
for e in r:print(e)

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

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

  int h, w, n;
  cin >> h >> w >> n;

  int x = max(h, w);
  cout << (n + x - 1) / x << endl;

  return (0);
}


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

#define vvi             vector<vector<int>>
#define ld              long double
#define mod             1000000007
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vpii            vector<pair<int,int>>
#define fr(i,a,b)       for(int i = a; i < b; i += 1)
#define all(x)          x.begin(),x.end()
#define sz(a)           (int)(a.size())
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define input(a)        for(auto it = a.begin(); it != a.end(); it++) { int value; cin >> value; *it = value;}
//#define print(a)        for(auto it = a.begin() ; it != a.end() ; it++){ cout << *it << " " ;}cout << '\n';
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

const int dirx[4] = {0, 0, -1, 1};
const int diry[4] = {-1, 1, 0, 0};

// 0 -> l, 1 - > r, 2 -> u , 3 -> down
void FASTIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mxN = 2e3 + 10;
int n;
int dp[mxN][mxN];

void test_case()
{
	vi a, b;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int x, y;
		cin >> x >> y;
		a.pb(x + y);
		b.pb(x - y);
	}
	sort(all(a));
	sort(all(b));

	cout << max(a.back() - a[0], b.back() - b[0]);
}   



int32_t main()
{
    FASTIO();

    int t;
    t = 1;
    //cin >> t;

    for(int i = 1; i <= t; i++)
    {
        //cout << "Case #" << i << ": ";
        test_case();
    }
    return 0;
} 


Measured memory_bytes: 6656
#include <iostream>
using namespace std;
int main(){
  long int a[10000],b[10000],i=1;
  while(1){
    cin>>a[i]>>b[i];
    if(a[i]==0&&b[i]==0){
      break;
    }
    if(a[i]-b[i]>=0){
      cout<<b[i]<<" "<<a[i]<<endl;
    }else{
      cout<<a[i]<<" "<<b[i]<<endl;
    }
    i++;
  }
  return 0;
}

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

const int N=2010,Mod=1e9+7;

int n,k,f[N][N];

void Init() {
	scanf("%d%d",&n,&k);
}

int pow(int x,int t) {
	int ret=1;
	while (t) {
		if (t&1) ret=1ll*ret*x%Mod;
		x=1ll*x*x%Mod;
		t>>=1; 
	}
	return ret;
}

int inv[N];
int Calc(int n,int m) {
	int fact=1;
	for (int i=1;i<=n;++i) fact=1ll*fact*i%Mod;
	inv[1]=inv[0]=1; for (int i=2;i<=n;++i) inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod; 
	for (int i=2;i<=n;++i) inv[i]=1ll*inv[i-1]*inv[i]%Mod;
	return 1ll*fact*inv[m]%Mod*inv[n-m]%Mod; 
}

void Solve() {
	int ans;
	if (n==k) ans=1;else ans=pow(2,n-k-1);
	f[0][n+1]=1;
	for (int i=1;i<=k;++i) {
		int sum=f[i-1][n+2-i];
		for (int j=n+1-i;j>=1;--j) {
			f[i][j]=(f[i-1][j]+sum)%Mod;
			sum=(sum+f[i-1][j])%Mod;
		}
	}
	printf("%lld\n",1ll*(f[k][1]-f[k-1][1]+Mod)*ans%Mod);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int G[10][10];
int a[10];

signed main()
{
    int N,M; cin>>N>>M;
    REP(i,M){
        int a,b; cin>>a>>b;
        a--; b--;
        G[a][b]=G[b][a]=1;
    }

    int ans=0;
    REP(i,N) a[i]=i;
    do{ 
        bool ok=true;
        REP(i,N-1) ok&=G[a[i]][a[i+1]];
        if(ok) ans++;
    }while(next_permutation(a+1,a+N));
    cout<<ans<<endl;

}

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

using namespace std;

int main(){
    long long int n,k,d=0;
    cin>>n>>k;
    vector<long long int>h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    /*for(int i=0;i<n;i++){
        cout<<h[i];
    }*/
    size_t size=h.size();

    if(size<=k)cout<<0;
    else{
        for(int i=0;i<n-k;i++){
            d+=h[i];
        }
        cout<<d;
    }

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

# define inOut(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
# define RESET(a) memset(a,0,sizeof(a))
# define MEMO(a) memset(a,-1,sizeof(a))
# define DEBUG puts("Debug-Has-Come-Until-Here")


typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	cin.tie(NULL);

	int T, arr[5];
	scanf("%d", &T);
	while(T--){
		scanf("%d %d %d", &arr[1], &arr[2], &arr[3]);
		sort(arr+1, arr+4);
		if (arr[1]*arr[1] + arr[2]*arr[2] == arr[3]*arr[3])
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
#include<string.h>

#define YES "Yes"
#define NO "No"
#define N_MAX 200000

int main()
{
    int n, k;
    unsigned int array[N_MAX];

    scanf("%d %d", &n, &k);

    for (int i=0; i<n; i++)
    {
        scanf("%u", &array[i]);
    }

    for (int i=k; i<n; i++)
    {
        if (array[i] > array[i-k])
        {
            printf("%s\n", YES);
        } else {
            printf("%s\n", NO);
        }
    }

    return 0;
}

Measured memory_bytes: 2424
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 3e5 + 10;
const int inf = 0x7ffffff;

int a[maxn];
void solve()
{
    int K, N;
    cin >> K >> N;
    int maxx = 0;
    for (int i = 1; i <= N;i++)
    {
        cin >> a[i];
        maxx = max(a[i] - a[i - 1], maxx);
    }
    maxx = max(maxx, K - a[N] + a[1]);
    cout << K-maxx << "\n";
}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 1024
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        sum +=s_dict[s[i]]
        s_dict[s[i]] += 1
    else:
        s_dict[s[i]] = 1
print(sum)


Measured memory_bytes: 19404
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  long n, i = 1, it = 0;
  cin >> n;
  char s[200] = {};
  do{
    if(n % (i * 2) != 0){
      n -= i;
      s[it++] = '1';
    }else{
      s[it++] = '0';
    }
    i *= (-2);
  }
  while(n != 0);
  while(it != 0) cout << s[--it]; 
  cout << endl;
  return 0;
}

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


int main(){
  int n;
  cin >> n;
  
  map<string,int>mp;
  rep(i,n){
    string s;
    cin >> s;
    mp[s]++;
  }
  
  int mx = 0;
  for(auto p : mp) mx = max(mx, p.second);
  for(auto p : mp) {
    if(p.second == mx) cout << p.first << endl;
  }
  
}

Measured memory_bytes: 25216
def main():
    N = float(input())
    nuki = int(N//1.08)
    if int(nuki*1.08)==N:
        print(nuki)
    elif int((nuki+1)*1.08)==N:
        print(nuki+1)
    else:
        print(":(")
        
if __name__=='__main__':
    main()


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

const int N = 5010 ;
const long long inf = 10000000000000000 ;
pair<int,int> zab [ N ] ;

bool cmp ( pair<int,int> A, pair<int,int> B ) {
    return A.first + A.second < B.first + B.second ;
}

long long dp [ N ][ 3 ];

int main() {
 //   freopen("input.txt", "r", stdin) ;
    int n ; cin >> n ;
    for ( int i = 0 ; i < n ; ++i )
        cin >> zab[i].first >> zab[i].second ;
    sort ( zab, zab+n, cmp ) ;
    int ans =0 ;
    for ( int i = 1 ; i <= n ; ++i ) {
        for ( int j = 0 ; j < n ; ++j ) {
            if ( i == 1 ) dp[j][i%2] = zab[j].first ;
            else if ( j + i <= n ) dp[j][i%2] = min ( 1ll*zab[j].first, dp[j+1][(i-1)%2] - zab[j].second );
            else dp[j][i%2] = -inf ;
        }
        bool kPosible = (dp[n-1][i%2] >= 0ll) ;
        for ( int j = n-2 ; j >= 0 ; --j ) {
            dp[j][i%2] = max ( dp[j][i%2], dp[j+1][i%2] ) ;
            kPosible |= (dp[j][i%2]>=0ll) ;
        }
        if ( kPosible ) ans = i ;
    }
    cout << ans << '\n' ;
}


Measured memory_bytes: 384
n = int(input())
s = input()
ans = 0
for i in range(len(s)-1):
	s1 = list(set(s[i+1:]))
	s2 = list(set(s[:i+1]))

	tog = 0
	for i in s1:
		if i in s2:
			tog += 1

	ans = max(tog,ans)
print(ans)

Measured memory_bytes: 39536
strings = list(input())
# strings = ['H', 'A', 'T', 'A', 'G', 'A', 'Y', 'A']
success_strings = ["A","G","T","C"]
"""
1文字目から取得していって、一致するものがあればカウントしていく
一致しなくなったらカウントをやめて、次の文字から探索する
"""

cnt = 0
for i in range(0, len(strings)):
    temp_cnt = 0

    for n in range(i, len(strings)):
        if strings[n] in success_strings:
            temp_cnt += 1
        else:
            break

        if temp_cnt > cnt:
            cnt = temp_cnt

print(cnt)

Measured memory_bytes: 3060
n, m = map(int, input().split())

parent = [i + 1 for i in range(n)]
rank = [0 for i in range(n)]
size = [1 for i in range(n)]

def find(x):
    if parent[x - 1] == x:
        return x
    else:
        parent[x - 1] = find(parent[x - 1])
        return parent[x - 1]

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if rank[x - 1] < rank[y - 1]:
        parent[x - 1] = y
        size[y - 1] += size[x - 1]
    else:
        parent[y - 1] = x
        size[x - 1] += size[y - 1]
        if rank[x - 1] == rank[y - 1]:
            rank[x - 1] += 1

def nc2(a):
    return a * (a - 1) // 2

ab = []
for i in range(m):
    ab.append(list(map(int, input().split())))
ab.reverse()
ans = [0]
for i in range(m):
    a, b = ab[i][0], ab[i][1]
    num_a = size[find(a) - 1]
    num_b = size[find(b) - 1]
    unite(a, b)
    num = size[find(a) - 1]
    if num_a != num:
        ans.append(ans[-1] + nc2(num) - nc2(num_a) - nc2(num_b))
    else:
        ans.append(ans[-1])
ans.reverse()
num = nc2(n)
for i in range(m):
    print(num - ans[i + 1])

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


int main() {
  
  int N,M;
  cin>>N>>M;
  
  int sw=0;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sw=sw+A.at(i);
  }
  
  int sw1=0;
  for (int i = 0; i < N; i++) {
    if(sw%(4*M)==0){
      if(A.at(i)>=sw/(4*M)){
        sw1++;
      }
    }else if(A.at(i)>=(sw/(4*M)+1)){
      sw1++;
    }
  }
  
  if(sw1>=M){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
    
  
  
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n;i>0;i--)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define DREP(i,b,n) for(int i=n;i>b;i--)

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

int n, a[100],res;

int main() {
  res = 0;
  cin >> n;
  rep(i,n) cin >> a[i];
  rep(i,n) DREP(j,i,n-1) {
    if(a[j]<a[j-1]) {
      int tmp = a[j];
      a[j] = a[j-1];
      a[j-1] = tmp;
      res++;
    }
  }
  rep(i,n){
    if(i == n-1)
      cout << a[i];
    else
    cout << a[i] << " ";
  }
  cout << endl;
  cout << res << endl;
    
  return 0;
}

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

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

    int len = s.length();
    int count = 0;
    int c_idx = 0;
    bool con = false;
    if (s[0] == 'A') {
        for (int i = 1; i < len; i++) {
            if (isupper(s[i])) {
                count++;
                if (s[i] == 'C' && 1 < i && i < len-1) {
                    con = true;
                }
            }
        }
    }
        
    if (count == 1 && con) cout << "AC" << endl;
    else cout << "WA" << endl;
}

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

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> b.at(i);
    }
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        int sum = 0;
        for (int j = 0; j < m; j++)
        {
            int a_ij;
            cin >> a_ij;
            sum += a_ij * b.at(j);
        }
        sum += c;
        if (sum > 0)
        {
            res++;
        }
    }
    cout << res << endl;
}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class DModSum {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int64_t n;
    cin >> n;
    cout << n * (n + 1) / 2 - n << endl;
}
};

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


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    // ABピザは高々max(2X, 2Y)<2e5なので全探索
    LLONG A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    LLONG ans = 1e12;
    for (int ab = 0; ab <= max(2 * X, 2 * Y); ab += 2)
    {
        LLONG remX = max(X - ab / 2, 0LL);
        LLONG remY = max(Y - ab / 2, 0LL);
        ans = min(ans, remX * A + remY * B + ab * C);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        if(s.charAt(0) == s.charAt(1) || s.charAt(1) == s.charAt(2) || s.charAt(2) == s.charAt(3)){
            System.out.println("Bad");
        }
        else{
            System.out.println("Good");
        }
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a, b; cin>>a>>b;
	cout<<(a+b)%24<<'\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Long> plus = new ArrayList<>();
		ArrayList<Long> minus = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			long x = sc.nextInt();
			if (x < 0) {
				minus.add(x);
			} else {
				plus.add(x);
			}
		}
		Collections.sort(plus);
		Collections.sort(minus);
		long w;
		if (minus.size() > 0) {
			w = minus.remove(0);
		} else {
			w = plus.remove(0);
		}
		StringBuilder sb = new StringBuilder();
		while (plus.size() > 1) {
			long x = plus.remove(0);
			sb.append(w).append(" ").append(x).append("\n");
			w -= x;
		}
		minus.add(w);
		Collections.sort(minus);
		long ans;
		if (plus.size() > 0) {
			ans = plus.remove(0);
		} else {
			ans = minus.remove(minus.size() - 1);
		}
		for (long x : minus) {
			sb.append(ans).append(" ").append(x).append("\n");
			ans -= x;
		}
		System.out.println(ans);
		System.out.print(sb);
	}
}


Measured memory_bytes: 65164
#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;
typedef vector<string> vstring;
#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);
  int n;
  cin>>n;
  set<string> S;
  string s;
  rep(i,n){
    cin>>s;
    S.insert(s);
  }
  int si=S.size();
  cout<<si<<'\n';
  return(0);
}


Measured memory_bytes: 19244
n,m,q=map(int,input().split())
cs=[]
for _ in range(q):
    cs.append(list(map(int,input().split())))

def dfs(pos,a,m,cs):
    if pos==len(a):
        s=0
        for i in cs:
            if a[i[1]-1]-a[i[0]-1]==i[2]:s+=i[3]
        return s

    ans=0
    if pos==0:low=1
    else:low=a[pos-1]
    for i in range(low,m+1):
        a[pos]=i
        ans=max(ans,dfs(pos+1,a,m,cs))  #pos+1 实现调用
    return ans





print(dfs(0,[0]*n,m,cs))

Measured memory_bytes: 72824
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int maxn=2e3+5,mo=1e9+7;
int i,j,n,k,f[maxn][maxn],ji[maxn*maxn],ni[maxn*maxn];
int qs(int x,int y){
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%mo) if(y&1) s=(ll)s*x%mo;
	return s; 
}
int calc(int n,int  m){
	return (ll)ji[n]*ni[m]%mo*ni[n-m]%mo;
}
void mod(int &x){
	x-=(x>=mo)?mo:0;
}
int main(){
	scanf("%d%d",&n,&k);
	if (k==1){
        printf("1\n");
        return 0;
    }
	ji[0]=1;
	fo(i,1,n*k) ji[i]=(ll)ji[i-1]*i%mo;
	ni[n*k]=qs(ji[n*k],mo-2);
	fd(i,n*k,1) ni[i-1]=(ll)ni[i]*i%mo;
	f[0][0]=1;
	fo(i,0,n){
		fd(j,i,0) if (f[i][j]){
			int s=f[i][j];
			if (j) mod(f[i][j-1]+=s);
			if (i<n) mod(f[i+1][j+1]+=(ll)s*calc(i*k-j+k-2,k-2)%mo);
		}
	}
	printf("%d\n",(ll)f[n][0]*ji[n]%mo);
}

Measured memory_bytes: 47360
using System;
using System.Collections.Generic;
using System.Linq;
namespace AOJ {
  public class AOJ {
    public static void Main(string[] args) {
      var n = Console.ReadLine().Split(' ').ToList().Select(x => int.Parse(x)).ToArray();
      Console.WriteLine((n[0] * n[1]).ToString() + " " + ((n[0] + n[1]) * 2).ToString());
    }
  }
}

Measured memory_bytes: 9508
#include<stdio.h>
int main()
{
	int N;
	int k;
	int p = 0;
	int maxp = 0;

	scanf("%d", &N);

	int H[N];

	for(k=0; k<N; k++){
		scanf("%d", &H[k]);
	}
	
	for(k=0; k<N-1; k++){
		if(H[k] >= H[k+1]){
			p = p + 1;
			if(maxp < p) maxp = p;
		}
		
		else{
          p = 0;
        }
	}
	
	printf("%d", maxp);
	
	return 0;
}


Measured memory_bytes: 512
"""
Writer:SPD_9X2
https://atcoder.jp/contests/tenka1-2019-beginner/tasks/tenka1_2019_d

愚直全探索は 0(3**N)
O(N**3)位までは計算量を落とさないといけない

ありうる辺の長さ全列挙→むりぽ
短い2辺の和 < 長い辺の和　なら構成不可能
構成不可能分配の方を数える？

少なくとも各辺に1本分配する場合、
構成不可能な場合の最長辺の長さは必ず総延長の半分以上となる
総延長の半分以上となる取り方の数を数えて引けばよい？

長さとしてありうるのは 300**2 までしかありえないので、
dp推移をO(1)でやれば解けそう

具体的なdp推移を考えてみる
最長辺を赤と決めてあげてよい？

全部赤に割り振って減らしていく
→Nこの中からいくつか取って、半分以上の長さにする方法を網羅できる

調整
→最長3色分をやると、2色に半分ずつ行った時をダブルカウントしてるので処理する

解けた！！ O(sum(a)*N)

→解けてねぇ！！！！！！！
1本の辺の作り方を数えても結局残りの辺の数によって分配が依存してしまう…

N本からA本選んで長さの半分を超える方法がいくつあるか数えればよい
そうすれば残りの分配をO(1)でできる

=======答えを見た========

最初の方針で行けるやん…？
DP[r] = 赤の数がrであるような「塗り分けの個数」

"""

import math
mod = 998244353
N = int(input())

a = []

for i in range(N):

    A = int(input())
    a.append(A)

asum = sum(a)
lis = [0] * ( asum + 1)
lis[0] = 1

for i in range(N):

    nlis = [0] * (asum+1)
    for j in range(asum+1):

        nlis[j] += lis[j] * 2
        nlis[j] %= mod
        if j+a[i] <= asum:
            nlis[j+a[i]] += lis[j]
            nlis[j+a[i]] %= mod

    lis = nlis

#print (lis)
ans = pow(3,N,mod)
#print (ans)

if asum % 2 == 1:
    for i in range( asum//2+1 , asum+1):
        ans -= lis[i] * 3
        ans %= mod

    print (ans)

else:
    for i in range( asum//2 , asum+1):
        ans -= lis[i] * 3
        ans %= mod

    #ダブルカウントを引く→数個選んで半分取る方法の個数を数える→//2
    #その個数*3*2が2回カウントされてるので足す

    lis2 = [0] * (asum+1)
    lis2[0] = 1

    for i in range(N):
        for j in range(asum-a[i],-1,-1):
            lis2[j+a[i]] += lis2[j]
            lis2[j+a[i]] %= mod

    ans += lis2[asum//2] * 3
    print (ans % mod)
        

#WA解
"""
import math
mod = 998244353
N = int(input())

a = []

for i in range(N):

    A = int(input())
    a.append(A)

asum = sum(a)
lis = [0] * ( asum + 1)
lis[-1] = 1

for i in range(N):

    for j in range(len(lis)):

        if j - a[i] >= 0:
            lis[j-a[i]] += lis[j]
            lis[j-a[i]] %= mod

print (lis)
ans = pow(3,N,mod)
print (ans)

if asum % 2 == 1:
    for i in range( asum//2 , asum+1):
        ans -= lis[i] * 6
        ans %= mod

    print (ans)

"""

Measured memory_bytes: 97020
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		char []c = sc.next().toCharArray();
		
		for(int i = 0; i < c.length; i++) {
			int cnt = 0;
			
			while(cnt < n) {
				if(c[i] == 'Z') {
					c[i] = 'A';
					cnt++;
					continue;
				}
				else {
				c[i]++;
				cnt++;
				}
			}
		}
		String t = String.valueOf(c);
		System.out.println(t);

	}

}


Measured memory_bytes: 22868
from collections import deque, defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)

n = int(input())
edges = defaultdict(lambda : defaultdict(lambda: False))
for i in range(n-1):
    a, b = map(int, input().split())
    edges[a][b] = True
    edges[b][a] = True

nums = [deque() for _ in range(3)]
for i in range(1, n+1):
    nums[i%3].append(i)

color = [-1 for _ in range(n)]
cnts = [0 for _ in range(2)]
def coloring(num, pre_color):
    if pre_color:
        col = 0
    else:
        col = 1
    color[num-1] = col
    cnts[col] += 1
    for k in edges[num].keys():
        if color[k-1] == -1:
            coloring(k, col)

coloring(1, 1)

ans = [0 for _ in range(n)]
def solve(v):
    for i in range(n):
        if color[i] == v:
            ans[i] = nums[0].pop()
        else:
            for j in [1, 2, 0]:
                if len(nums[j]) > 0:
                    ans[i] = nums[j].pop()
                    break

if cnts[0] <= n // 3:
    # print("A")
    solve(0)
elif cnts[1] <= n // 3:
    # print("B")
    solve(1)
else:
    # print("C")
    for i in range(n):
        if color[i]:
            if len(nums[1]) > 0:
                ans[i] = nums[1].pop()
            else:
                ans[i] = nums[0].pop()
        else:
            if len(nums[2]) > 0:
                ans[i] = nums[2].pop()
            else:
                ans[i] = nums[0].pop()

print(" ".join(list(map(str, ans))))

Measured memory_bytes: 233296
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int C[510][510],D[35][35];

signed main(){
    int n,c; cin>>n>>c;
    vector<int> x(c,0),y(c,0),z(c,0);
    rep(i,c)rep(j,c)cin>>D[i][j];
    rep(i,n)rep(j,n){ cin>>C[i][j]; C[i][j]--; }
    rep(i,n)rep(j,n){
        if((i+j)%3==0)x.at(C[i][j])++;
        if((i+j)%3==1)y.at(C[i][j])++;
        if((i+j)%3==2)z.at(C[i][j])++;
    }
    vector<int> X(c),Y(c),Z(c);
    rep(i,c){
        int sum=0;
        rep(j,x.size()){
            sum+=D[j][i]*x.at(j);
        }
        X.at(i)=sum;
    }
    rep(i,c){
        int sum=0;
        rep(j,y.size()){
            sum+=D[j][i]*y.at(j);
        }
        Y.at(i)=sum;
    }
    rep(i,c){
        int sum=0;
        rep(j,z.size()){
            sum+=D[j][i]*z.at(j);
        }
        Z.at(i)=sum;
    }
    int ans=INF;
    rep(i,c)rep(j,c)rep(k,c){
        if(i==j or j==k or k==i)continue;
        chmin(ans,X.at(i)+Y.at(j)+Z.at(k));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        scan.close();

        int ans = 0;
        for (int i = 1; i <= n; i += 2) {
            int fact = 0;
            for (int j = 1; j <= n; j++) {
                if (i % j == 0) {
                    fact++;
                }
            }
            if (fact == 8) {
                ans++;
            }
        }
        System.out.println(ans);
    }

}


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

def solve():
    N = int(input())
    A = list(map(int, input().split()))

    ans_num = 0
    ans = ""
    box = [0] * (N)
    for i in range(N-1, -1, -1):
        total = 0
        for j in range(i, N, i+1):
            # iの倍数のボールの個数の和を計算する
            total += box[j]
        if total%2 == A[i]:
            continue
        else:
            ans_num += 1
            ans += str(i+1) + " "
            box[i] = 1
    
    # 検査する
    for i in range(N-1, -1, -1):
        total = 0
        for j in range(i, N, i+1):
            total += box[j]
        if total%2 == A[i]:
            continue
        else:
            print(-1)
            return

    print(ans_num)
    if ans_num != 0:
        print(ans[0:-1])

if __name__ == "__main__":
    solve()


Measured memory_bytes: 10040
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;
int main(){
    ios;
    ll cnt = 0;
    string s, t; cin >> s >> t;
    rep(i,(int) s.size()){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3820
package main
import (
  "fmt"
  "bufio"
  "os"
)

var(
  S string
  T string
  n int
)

func main() {
  var sc = bufio.NewScanner(os.Stdin)
  if sc.Scan() {
    S = sc.Text()
  }
  if sc.Scan() {
    T = sc.Text()
  }
  
  for i, _ := range S {
    if(S[i] == T[i]) {
    	n++
    }
  }
  
  fmt.Println(n)
}

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

typedef pair<int, int> pii;
const int N = 1e5 + 100;

int n, m, l, r, ans;
pii p[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> p[i].first >> p[i].second;
	sort(p, p + m, [](pii a, pii b) {
		return a.second < b.second;
	});
	int last = -1;
	for (int i = 0; i < m; i++)
		if(p[i].first >= last) {
			ans++;
			last = p[i].second;
		}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B
import           Text.Printf

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

--

newtype VDouble =
    VDouble Double
    deriving (Show, Read, Num, Floating, Fractional)

instance Eq VDouble where
    VDouble a == VDouble b = abs (a - b) < 1e-10

instance Ord VDouble where
    VDouble a `compare` VDouble b
        | VDouble a == VDouble b = EQ
        | a <  b                 = LT
        | otherwise              = GT

--

newtype V2 =
    V2 (VDouble, VDouble)
    deriving (Show)

(|+|) :: V2 -> V2 -> V2
V2 (a, b) |+| V2 (c, d) = V2 (a + c, b + d)

(|-|) :: V2 -> V2 -> V2
V2 (a, b) |-| V2 (c, d) = V2 (a - c, b - d)

(*|) :: VDouble -> V2 -> V2
k *| V2 (c, d) = V2 (k * c, k * d)

norm :: V2 -> VDouble
norm (V2 (a, b)) = a * a + b * b

abs' :: V2 -> VDouble
abs' = sqrt . norm

dot :: V2 -> V2 -> VDouble
V2 (a, b) `dot` V2 (c, d) = a * c + b * d

cross :: V2 -> V2 -> VDouble
V2 (a, b) `cross` V2 (c, d) = a * d - b * c

--

data Wise
    = COUNTER_CLOCKWISE
    | CLOCKWISE
    | ONLINE_BACK
    | ONLINE_FRONT
    | ON_SEGMENT
    deriving (Show)

ccw :: V2 -> V2 -> V2 -> Wise
ccw p0 p1 p2
    | cross a b > 0   = COUNTER_CLOCKWISE
    | cross a b < 0   = CLOCKWISE
    | dot a b < 0     = ONLINE_BACK
    | norm a < norm b = ONLINE_FRONT
    | otherwise       = ON_SEGMENT
  where
    a = p1 |-| p0
    b = p2 |-| p0

main :: IO ()
main = do
    [x0, y0, x1, y1] <- fmap (fromIntegral . readi) . B.words <$> B.getLine
    let p0 = V2 (x0, y0)
    let p1 = V2 (x1, y1)
    q <- readLn
    replicateM_ q $ do
        [a, b] <- fmap (fromIntegral . readi) . B.words <$> B.getLine
        let p2 = V2 (a, b)
        print $ ccw p0 p1 p2



Measured memory_bytes: 4268