akhauriyash/Code-Regression huggingface dataset:
n,a,b,c=map(int,input().split())
s=[0]*(n+1)
for i in range(n):
    s[i]=input()
l=[0]*(n+1)
for i in range(n):
    if s[i]=="AB":
        if a==b==0:
            print("No")
            exit()
        if a+b+c==2:
            if a==b==1:
                if s[i+1]=="AC":
                    a+=1
                    b-=1
                    l[i]="A"
                    continue
                elif s[i+1]=="BC":
                    a-=1
                    b+=1
                    l[i]="B"
                    continue
        if a>=b:
            a-=1
            b+=1
            l[i]="B"
        else:
            a+=1
            b-=1
            l[i]="A"
    if s[i]=="BC":
        if c==b==0:
            print("No")
            exit()
        if a+b+c==2:
            if b==c==1:
                if s[i+1]=="AB":
                    c-=1
                    b+=1
                    l[i]="B"
                    continue
                elif s[i+1]=="AC":
                    b-=1
                    c+=1
                    l[i]="C"
                    continue
        if b>=c:
            b-=1
            c+=1
            l[i]="C"
        else:
            b+=1
            c-=1
            l[i]="B"
    if s[i]=="AC":
        if a==c==0:
            print("No")
            exit()
        if a+b+c==2:
            if a==c==1:
                if s[i+1]=="AB":
                    c-=1
                    a+=1
                    l[i]="A"
                    continue
                elif s[i+1]=="BC":
                    a-=1
                    c+=1
                    l[i]="C"
                    continue
        if a>=c:
            a-=1
            c+=1
            l[i]="C"
        else:
            a+=1
            c-=1
            l[i]="A"
if l[-2]!=0:
    print("Yes")
    for i in range(n):
        print(l[i])

Measured memory_bytes: 17080
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		final String fst = sc.next();
		final String lst = sc.next();
		
		int answer = Math.max(N, fst.length() + lst.length());
		
		final int min_len = Math.min(fst.length(), lst.length());
		for(int common_len = 1; common_len <= min_len; common_len++){
			boolean flg = true;
			
			for(int i = 0; i < common_len; i++){
				final int fst_point = (fst.length() - common_len) + i;
				final int lst_point = i;
				
				if(fst.charAt(fst_point) != lst.charAt(lst_point)){
					flg = false;
					break;
				}
			}
			
			if(flg){
				final int next_length = fst.length() + lst.length() - common_len;
				//System.out.println(fst.substring(0, fst.length() - common_len) + lst);
				
				if(next_length >= N){
					answer = Math.min(answer, next_length);
				}
			}
		}
		
		System.out.println(answer);
	}
	
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 8148
def popcount(u):
    t = bin(u)
    h = t.count("1")
    return u % h 

n = int(input())
x = list(input())
c = x.count("1") + 1
d = c - 2
if d == -1:
    for i in range(n):
        print(1)
    exit()
elif d == 0:
    p = x.index("1")
    if p == n-1:
        for i in range(n-1):
            print(2)
        print(0)
        exit()
    elif p != n-1:
        for i in range(n):
            if i == n-1:
                print(2)
            elif i != p:
                print(1)
            elif i == p:
                print(0)
        exit()

amaric = [1 % c]
amarid = [1 % d]
for i in range(n-1):
    amaric.append((amaric[-1]*2)%c)
    amarid.append((amarid[-1]*2)%d)

motoc = 0
motod = 0
for i in range(n):
    if x[i] == "1":
        motoc += amaric[n-1-i]
        motod += amarid[n-1-i]

for i in range(n):
    if x[i] == "0":
        op = motoc
        op += amaric[n-1-i]
        op %= c
    elif x[i] == "1":
        op = motod
        op -= amarid[n-1-i]
        op %= d
    cou = 1
    while True:
        if op == 0:
            break
        op = popcount(op)
        cou += 1
    print(cou)


Measured memory_bytes: 26484
import java.util.*;
public class Main {
    static int mod = 1000000007;
    static long modpow(long a, int p) {
        if (p == 0) return 1;
        if (p % 2 == 0) {
            int halfP = p / 2;
            long half = modpow(a, halfP);
            return half * half % mod;
        } else {
            return a * modpow(a, p - 1) % mod;
        }
    }
    static long calcComb(int a, int b) {
        if (b > a - b) return calcComb(a, a - b);
        long ansMul = 1;
        long ansDiv = 1;
        for (int i = 0; i < b; i++) {
            ansMul *= (a - i);
            ansDiv *= (i + 1);
            ansMul %= mod;
            ansDiv %= mod;
        }
        long ans = ansMul * modpow(ansDiv, mod - 2) % mod;
        return ans;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), M = sc.nextInt();
        sc.close();
        int MNokori = M;
        long ans = 1;
        for (int i = 2; i * i <= MNokori; i++) {
            if (MNokori % i == 0) {
                int cnt = 0;
                while (MNokori % i == 0) {
                    cnt++;
                    MNokori /= i;
                }
                ans *= calcComb(N + cnt - 1, N - 1);
                ans %= mod;
            }
        }
        if (MNokori != 1) {
            ans *= calcComb(N + 1 - 1, N - 1); 
            ans %= mod;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    int index = 0;
    for (int i = 0; i < (int)s.size(); i++){
        if (s[i] != '1'){
            index = i-1;
            break;
        }
    }
    if (index >= k-1){
        cout << '1' << endl;
    } else {
        cout << s[index+1];
    }


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int SH = 1e5 + 7, N = SH << 1;
int n;
int l[N], r[N];

void calc(int a[N]) {
    for (int i = 1; i < N; ++i)
        a[i] += a[i - 1];
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        a += SH; b += SH;
        ++l[a];
        ++r[b];
    }   

    calc(l); calc(r);

    int ans = 0;
    for (int i = SH; i + 1 < N; ++i) {
        int inl = r[i] + 1;
        int inr = n - l[i];
        ans += min(inl, inr) * 2;        
    }   
    for (int i = SH; i; --i) {
        int inl = r[i - 1];
        int inr = n - l[i - 1] + 1;
        ans += min(inl, inr) * 2;
    }   
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <stdio.h>

int main(void) {
   int a,b,c;
   
   scanf("%d %d %d",&a,&b,&c);
   
    if (a<=b && b<=c)
    {
    	printf("%d %d %d\n",a,b,c);
    }
    
    else if(a<=c && c<=b)
    {
    	printf("%d %d %d\n",a,c,b);
    }
    
    else if(b<=a && a<=c)
    {
    	printf("%d %d %d\n",b,a,c);
    }
    
    else if(b<=c && c<=a)
    {
    	printf("%d %d %d\n",b,c,a);
    }
    
    else if(c<=a && a<=b)
    {
    	printf("%d %d %d\n",c,a,b);
    }
    
    else if(c<=b && b<=a)
    {
    	printf("%d %d %d\n",c,b,a);
    }
    
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin>>A[i];

    sort(all(A));
    
    int temp=0;
    string ret="YES";
    rep(i, N){
        if(temp!=A[i]) temp=A[i];
        else{
            ret="NO";
            break;
        }
    }

    cout << ret << endl;

    return 0;
}

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

int main(){
  
  //三角形ABCはL ABC = 90度の直角三角形である。
  
  int a,b,c; 
  int S;
  
  cin >> a >> b >> c;
  
  S = 0.5 * a * b;
  
  cout << S << endl;
  
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, C, K; cin >> N >> C >> K;
  vector<ll> T(N); REP(i, N) cin >> T[i];
  sort(all(T));
  ll k = 0;
  ll cnt = 1;
  ll tmp = 0;
  bool flag = false;
  for(int i = 0; i < N; ++i) {
    if(T[k] + K >= T[i]) {
      tmp++;
      if(tmp == C) {
        tmp = 0;
        cnt++;
        k = i + 1;
        if(i + 1 == N) cnt--;
      }
    } else {
      tmp = 1;
      cnt++;
      k = i;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1152
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
 	int n;
  cin>>n;
  double ans=0;
  for(int i=0;i<n;i++)
  {
    double tmp;
    cin>>tmp;
    ans += (double)(1.0/tmp);
  }
  ans = (double)(1.0/ans);
  cout<<setprecision(10)<<fixed<<ans<<endl;
  return 0;
}


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

int main(void) {
    int r,g,b;
    int a;
    cin >> r >> g >> b;
    if((g * 10 + b) % 4) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {

	int n, a, b;
	cin >> n >> a >> b;
	long long int c = 0;
	
	for (int i = 0; i <= n; i++) {
		int t = i;
		int z = 0;
		while (t) {
			z += t % 10; t /= 10;
		}
		if (z >= a&&z <= b)c += i;
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18
#define PI 3.1415926535

using ll = long long;

#define MAX 2000
ll fac[MAX];
ll finv[MAX];
ll inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    repr(i,2,MAX){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
  int N,K; cin >> N >> K;
  COMinit();
  rep(i,K){
    ll ans = 0;
    ans = COM(N-K+1,i+1) * COM(K-1,i) % MOD;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

ll counting(int n, int k, int t)
{
    ll res = 0;
    res += n / k;
    res += int(t!= 0 and (n % k) >= t);
    // cout << k << ' ' << t << ' ' << res << endl;
    return res;
}

int main()
{
    int n, k;
    cin >> n >> k;

    ll ans = 0;
    ll cnt;
    cnt = counting(n, k, 0);
    // cout << cnt << endl;
    ans += cnt * cnt * cnt;

    if (k % 2 == 0)
    {
        cnt = counting(n, k, k/2);
        // cout << cnt << endl;

        ans += cnt * cnt * cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int a, b;
    cin >> a >> b;
    if (a < b)
        cout << string(b, a + '0') << endl;
    else
        cout << string(a, b + '0') << endl;

    return 0;
}

Measured memory_bytes: 256
import math
N,K = (int(x) for x in input().split())
R = N - K
mod = 10**9 + 7
def fact(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(1,K+1):
    ans = 0 if N - K + 1 < i else fact(R+1, i)*fact(K-1,i-1)
    print(int(ans)%mod)

Measured memory_bytes: 3316
from collections import Counter

n = int(input())
l = list("")
for i in range(n):
    s = ''.join(sorted(input()))
    l.append(s)
c = Counter(l)
c = c.most_common()
ans = 0
for i in range(len(c)):
    x = c[i][1] - 1
    while x > 0:
        ans += x
        x -= 1
print(ans)

Measured memory_bytes: 24484
fn main() {
    let buf = io::read_string();
    let mut sc = io::Scanner::new(&buf);
    let _n: usize = sc.read();
    let m: usize = sc.read();
    let mut query: Vec<(usize, usize)> = (0..m).map(|_| (sc.read(), sc.read())).collect();
    query.sort_by(|a, b| a.1.cmp(&b.1));

    let mut prev = 0;
    let mut res = 0;
    for q in query {
        if q.0 >= prev {
            prev = q.1;
            res += 1;
        }
    }
    println!("{}", res);
}

#[allow(dead_code)]
mod io {
    use std;
    use std::io::Read;
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        pub iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
    pub fn read_string() -> String {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}


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

int main() {
    string S;
    cin >>S;
    int N=S.size();
    vector<int> s(N+1, 0);
    for (int i=0; i<N; i++) {
        char ss=S.at(i);
        switch(ss) {
            case '/':
                s.at(i+1)=s.at(i)+1;
                break;
            case '\\':
                s.at(i+1)=s.at(i)-1;
                break;
            case '_':
                s.at(i+1)=s.at(i);
                break;
        }
    }
    int l=0;
    int r=N;
    int hl=s.at(l);
    int hr=s.at(r);
    int s2=0;
    vector<int> L;
    vector<int> R;
    while (l<r) {
        if (hl<=hr) {
            int i=l+1;
            while(s.at(l)>s.at(i)) {
                s2 +=(hl-s.at(i-1)+hl-s.at(i));
                i++;
            }
            s2 +=(hl-s.at(i-1)+hl-s.at(i));
            if (0<s2)
                L.push_back(s2/2);
            l=i;
            hl=s.at(l);
            s2=0;
        } else {
            int i=r-1;
            while(s.at(r)>s.at(i)) {
                s2 +=(hr-s.at(i+1)+hr-s.at(i));
                i--;
            }
            s2 +=(hr-s.at(i+1)+hr-s.at(i));
            if (0<s2)
                R.push_back(s2/2);
            r=i;
            hr=s.at(r);
            s2=0;
        }
    }
    int A=0;
    for (int i=0; i<L.size(); i++)
        A += L.at(i);
    for (int i=0; i<R.size(); i++)
        A += R.at(i);
    cout <<A <<endl;
    cout <<L.size()+R.size();
    for (int i=0; i<L.size(); i++)
        cout <<' ' <<L.at(i);
    for (int i=R.size()-1; i>=0; i--)
        cout <<' ' <<R.at(i);
    cout <<endl;
    return 0;
}



Measured memory_bytes: 3300
n, m, x, y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))
max_x = max(xlist)
min_y = min(ylist)
flg = 0
for i in range(max_x+1, min_y+1):
    if i>x and i<=y:
        flg=1
        break
if flg ==1:
    print("No War")
else:
    print("War")

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

int main(){
    int a, b;
    while(1){
        cin >> a >> b;
        if(a == 0 && b == 0)break;
        for(int i = 0;i < a;i++){
            for(int j = 0;j < b;j++){
                if(i == 0 || i == a - 1 || j == 0 || j == b - 1){
                    cout << "#";
                }else {
                    cout << ".";
                }
            }
         cout << endl;
         }
        cout << endl;
    }
    return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m; cin>>n>>m;
	vector<string> grid;
	string row;
	for (int i=0; i<n; i++) {
		cin>>row;
		int cur=0;
		for (int j=0; j<m; j++)
			if(row[j]=='.')
				cur++;
		if(cur!=m)
			grid.push_back(row);
	}
	n=grid.size();
	for (int j=0; j<m; j++) {
		int cur=0;
		for (int i=0; i<n; i++)
			if(grid[i][j]=='.')
				cur++;
		if(cur==n) {
			for (int i=0; i<n; i++)
				grid[i][j]='@';
		}
	}
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++)
			if(grid[i][j]!='@')
				cout << grid[i][j];
		cout << endl;
	}
	return 0;
}


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

const int NUM = 7;

void grooping(int y, int x, int w, int h, char** room, unsigned long*** group, unsigned long* next)
{
	if (room[y][x] != '#') {
		for (int i = y - 1; i <= y + 1; i++) {
			for (int j = x - 1; j <= x + 1; j++) {
				if (i < 0 || j < 0 || i >= h || j >= w) {
					continue;
				}
				if ((i == y && j != x) || (i != y && j == x)) {
					for (int k = 0; k < NUM; k++) {
						group[y][x][k] |= group[i][j][k];
					}
				}
			}
		}
		for (int i = 0; i < NUM; i++) {
			if (group[y][x][i] == 0UL && next[i] != 0UL) {
				group[y][x][i] |= next[i];
				next[i] <<= 1;
				break;
			}
		}
	}
}

int main()
{
	int w, h;
	while (true) {
		cin >> w >> h;
		if (w == 0 && h == 0) {
			break;
		}

		unsigned long next[NUM] = { 1UL, 1UL, 1UL, 1UL, 1UL, 1UL, 1UL };
		char** room = new char*[h];
		unsigned long*** group = new unsigned long**[h];
		int x, y;
		for (int i = 0; i < h; i++) {
			room[i] = new char[w];
			group[i] = new unsigned long*[w];
			for (int j = 0; j < w; j++) {
				cin >> room[i][j];
				if (room[i][j] == '@') {
					x = j;
					y = i;
				}
				group[i][j] = new unsigned long[NUM];
				for (int k = 0; k < NUM; k++) {
					group[i][j][k] = 0UL;
				}
			}
		}

		for (int k = 0; k < 180; k++) {
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					grooping(i, j, w, h, room, group, next);
				}
			}
			for (int i = h - 1; i >= 0; i--) {
				for (int j = w - 1; j >= 0; j--) {
					grooping(i, j, w, h, room, group, next);
				}
			}
			for (int j = 0; j < w; j++) {
				for (int i = 0; i < h; i++) {
					grooping(i, j, w, h, room, group, next);
				}
			}
			for (int j = w - 1; j >= 0; j--) {
				for (int i = h - 1; i >= 0; i--) {
					grooping(i, j, w, h, room, group, next);
				}
			}
		}

		int count = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int k = 0; k < NUM; k++) {
					if ((group[i][j][k] & group[y][x][k]) != 0UL) {
						count++;
						break;
					}
				}
			}
		}

		cout << count << '\n';

		for (int i = 0; i < h; i++) {
			delete[] room[i];
			for (int j = 0; j < w; j++) {
				delete[] group[i][j];
			}
			delete[] group[i];
		}
		delete[] room;
		delete[] group;
	}

	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	ll A, B;
	cin >> A >> B;
	if((A+B)%2==1){
	    cout << "IMPOSSIBLE" << endl;
	}else{
	    cout << (A+B)/2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
N,C = map(int,input().split())
DP = [[0]*C for i in range(10**5+1)]
for i in range(N):
    s,t,c = map(int,input().split())
    DP[s][c-1] = t-s+1
ans = 0
for i in range(10**5):
    hoge = 0
    for j in range(C):
        DP[i+1][j] = max(DP[i][j]-1,DP[i+1][j])
        if DP[i][j]: hoge += 1
    ans = max(ans,hoge)

print(ans)

Measured memory_bytes: 78172
// {{{ by WangYenJen
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll;
typedef pair<int,int> pii;
// macro
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin() , (x).end()
#define REP(i , n) for(int i = 0; i < int(n); i++)
#define REP1(i , a , b) for(int i = a; i <= int(b); i++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LC o<<1 , l , m
#define RC o<<1|1 , m + 1 , r
#define MS(x , v) memset(x , (v) , sizeof(x))
// input
inline bool SR(int &x) {
	return scanf("%d",&x) == 1;
}
inline bool SR(ll &x) {
	return scanf("%lld",&x) == 1;
}
inline bool SR(double &x) {
	return scanf("%lf",&x) == 1;
}
inline bool SR(char *s) {
	return scanf("%s",s) == 1;
}
inline bool RI() {
	return true;
}
template<typename I , typename... T> inline bool RI(I &x , T&... tail) {
	return SR(x) && RI(tail...);
}
// output
inline void SP(const int x) {
	printf("%d",x);
}
inline void SP(const ll x) {
	printf("%lld",x);
}
inline void SP(const double x) {
	printf("%.16lf",x);
}
inline void SP(const char *s) {
	printf("%s",s);
}
inline void PL() {
	puts("");
}
template<typename I , typename... T> inline void PL(const I x , const T... tail) {
	SP(x);
	if(sizeof...(tail)) putchar(' ');
	PL(tail...);
}
// debug
#define WangYenJen
#ifdef WangYenJen
template<typename I> void _DOING(const char *s , I&& x) {
    cerr << s << " = " << x << endl;
}
template<typename I , typename... T> void _DOING(const char *s , I&& x , T&&... tail) {
    int c = 0;
    while(*s != ',' || c != 0) {
        if(*s == '(' || *s == '[' || *s == '{') c++;
        if(*s == ')' || *s == ']' || *s == '}') c--;
        cerr << *s++;
    }
    cerr << " = " << x << " , ";
    _DOING(s + 1 , tail...);
}
#define debug(...) \
do {\
    fprintf(stderr , "%s:%d - ",__PRETTY_FUNCTION__,__LINE__);\
    _DOING(#__VA_ARGS__ , __VA_ARGS__);\
} while(0);
#else
#define debug(...)
#endif
// random function
inline int RAND() {
	static int x = 880301;
	return (x = x * 0xdefaced + 1) & 0x7fffffff;
}
// }}}

const int MAX_N = 500 + 10;
char mp[MAX_N][MAX_N];
char a[MAX_N][MAX_N] , b[MAX_N][MAX_N];
int main() {
    int n , m;
    RI(n , m);
    REP(i , n) {
        RI(mp[i]);
        REP(j , m) a[i][j] = b[i][j] = mp[i][j];
        a[i][0] = '#' , b[i][m - 1] = '#';
    }
    REP(i , n) {
        if(~i&1) REP1(j , 1 , m - 2) a[i][j] = '#';
        else REP1(j , 1 , m - 2) b[i][j] = '#';
    }
    REP(i , n) {
        REP(j , m) putchar(a[i][j]);
        PL();
    }
    PL();
    REP(i , n) {
        REP(j , m) putchar(b[i][j]);
        PL();
    }
    return 0;
}


Measured memory_bytes: 1536
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < n; i++)
			num[i] = scanner.nextInt();
		long[][] dp = new long[n][21];
		dp[1][num[0]] = 1;
		for (int i = 1; i < n - 1; i++)
			for (int j = 0; j <= 20; j++) {
				int a = j + num[i];
				int b = j - num[i];
				if (a <= 20)
					dp[i + 1][a] += dp[i][j];
				if (b >= 0)
					dp[i + 1][b] += dp[i][j];
			}
		System.out.println(dp[n - 1][num[n - 1]]);
	}
}

Measured memory_bytes: 18140
n = int(input())

a = list(map(int, input().split()))

cnt = {}
ans = 0

for i in range(len(a)):
    add = (i + 1) + a[i]
    sub = (i + 1) - a[i]

    #check
    if sub in cnt:
        ans += cnt[sub]

    #add cnt
    if add in cnt:
        cnt[add] += 1
    else:
        cnt[add] = 1

print(ans)


Measured memory_bytes: 40336
A = "01234567"
memo = {A=>0}

stack = [[A, 0]]
table = [[1, 4], [0, 2, 5], [1, 3, 6], [2, 7],
         [0, 5], [4, 6, 1], [5, 7, 2], [3, 6]].freeze

while (board = stack.shift)
  swap = ->(a, b) {
    tmp = board.first.dup
    tmp[a], tmp[b] = tmp[b], tmp[a]
    [tmp, board.last]
  }
  i = board.first.index("0")
  table[i].each do |j|
    nxt = swap.(i, j)
    next if memo[nxt.first]
    nxt[1] += 1
    memo[nxt.first] = nxt.last
    stack << nxt
  end
end

$<.readlines.map {|a| a.split.join}.each do |given|
  puts memo[given]
end


Measured memory_bytes: 8792
n = gets.chomp.to_i
list = Array.new(n, 0)
A = gets.chomp.split.map(&:to_i)
tmp = 1
A.each_with_index do |a, i|
    if a == tmp
        tmp += 1
    else
        list[i] = 1
    end
end
ans = list.inject(:+)
puts ans == n ? -1 : ans

Measured memory_bytes: 20144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int ans = 0;
  while(a %2 == 0 && b%2 == 0 && c%2 == 0){
    int aa = a;
    int bb = b;
    int cc = c;
    a = bb/2 + cc/2;
    b = aa/2 + cc/2;
    c = aa/2 + bb/2;
    ans++;
    if(a == b && b == c){
      ans = -1;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>
int linearSearch();
int S[10005], n, T, q, C; 
int main(){
  int i;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T);
    if( linearSearch(S, n, T) == 0){
      C++;
    }
  }
  printf("%d\n",C);
  return 0;
}

int linearSearch(){
  int i=0;
  S[n] = T;
  while(S[i] != T){
    i++;
  }
  if(i==n){
    return 1;
  }
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

ll gcd (ll a, ll b){
    ll k = a % b;
    while (k > 0){
        a = b;
        b = k;
        k = a % b;
    }
    return b;
}

int main() {
    string s; cin >> s;
    ll k; cin >> k;
    int ans = 0;
    int cnt = 1;
    bool t = false;
    rep(i,s.size()){
        if (s[i] != '1'){
            int p = stoi(s.substr(i,1));
            ans = p;
            cnt += i;
            t = true;
            break;
        }
    }
    if (t){
        if (cnt <= k) cout << ans << endl;
        else cout << 1 << endl;
    }
    else cout << 1 << endl;
}

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

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

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

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

    Graph G(N);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    vector<int> dist(N, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (int nv : G[v]) {
            if (dist[nv] != -1) continue;

            dist[nv] = v + 1;
            que.push(nv);
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
        cout << dist[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10220
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

int main(){
    llong N,K;
    llong d;
    llong ans=0;
    cin >> N >> K;
    vector<vector<llong> > Table(N);
    llong A;
    llong cnt=0;
    for(int i=0; i<Table.size(); i++){
        for(int j=0; j<K; j++){
            Table[i].push_back(0);
        }
    }
    for(int i=0; i<K; i++){
        cin >> d;
        for(int j=0; j<d; j++){
            cin >> A;
            Table[A-1][i] = 1;
        }
    }
    for(int i=0; i<N; i++){
        cnt = 0;
        for(int j=0; j<K; j++){
            if(Table[i][j]==1){
                cnt++;
            }
        }
        if(cnt==0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	set<string> s;
	for(int i=1; i<=n; i++) {
		string ss;
		cin>>ss;
		s.insert(ss);
	}
	int m=(int)s.size();
	cout<<m<<endl;



	return 0;
}


Measured memory_bytes: 19244
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout << "Yes" << endl;
	} else {
		cout<< "No" << endl;
	}
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 3632
/*
	0161:Spoot Meet
*/
#include	<iostream>
#include	<vector>

using namespace std;

int main(void) {
	while(1) {
		int n, l;
		
		cin >> n;
		if(n == 0) { break; }
		
		vector< pair<char, char> > cList(n);
		
		for(int i = 0; i < n; i++) {
			char a, b;
			cin >> a >> b;
			
			cList[i] = make_pair(a, b);
		}
		
		cin >> l;
		
		vector<char> str(l);
		
		for(int i = 0; i < l; i++) {
			char c;
			cin >> c;
			for(int j = 0; j < n; j++) {
				if(c == cList[j].first) {
					c = cList[j].second;
					break;
				}
			}
			str[i] = c;
		}
		
		for(int i = 0; i < l; i++) {
			cout << str[i];
		}
		
		cout << endl;
	}
}

Measured memory_bytes: 1292
//
// Created by Ahmad Hamadneh on 6/14/2020.
//
#include <bits/stdc++.h>
using namespace std;


void solve(){
	int x, y; scanf("%d%d",&x,&y);

	vector<int64_t>v(x),dp(x+1,0);
	for(int i=0;i<x;i++){
	  scanf("%lld",&v[i]);
	}

	dp[0]=0;
	for (int i=1;i<x;i++){
		dp[i]=dp[i-1]+abs(v[i-1]-v[i]);
        for (int j=2;j<=y;j++){
			if (i >= j)
			   dp[i]=min(dp[i],dp[i-j]+abs(v[i-j]-v[i]));
		}
	}
    cout << dp[x-1];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 1792
import math

N, M = map(int, input().split())
yakusu = dict()
sqrt_M = int(math.sqrt(M))
for i in range(2, sqrt_M + 1):
    count = 0
    while M % i == 0:
        count += 1
        M //= i
    if count > 0:
        yakusu[i] = count
if M > 1:
    yakusu[M] = 1


def nCr(n, r):
    if r > n - r:
        return nCr(n, n - r)
    ans = 1
    for i in range(n, n-r, -1):
        ans *= i
    for i in range(1, r+1):
        ans //= i
    return ans


ans = 1
MOD = 10 ** 9 + 7
for n in yakusu.values():
    ans *= nCr(n + N - 1, N - 1)
    ans %= MOD

print(ans)


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

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    cin >> n;

    vector<int> a(50001),b(50001);
    for(int i = 0;i < 50001;i ++){
        a.at(i) = i;
    }
    for(int i = 0;i < 50001;i ++){
        b.at(i) = a.at(i) * 1.08;
    }

    for(int i = 0;i < 50001;i ++){
        if(n == b.at(i)){
            cout << a.at(i) << endl;
            return 0;
        }
    }

    cout << ":(" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n, m;
    cin >> n >> m;
    std::vector<std::vector<int>> a(n, std::vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    std::vector<int> check(m + 1, 0);
    std::vector<int> diff(n, 0);
    int mi = INF;
    int num = 0;
    while (num < m) {
        std::vector<int> count(m + 1, 0);
        int ma = 0;
        for (int i = 0; i < n; i++) {
            while (check[a[i][diff[i]]] == 1 && diff[i] < m - 1) {
                diff[i]++;
            }
            count[a[i][diff[i]]]++;
        }
        int now = 0;
        for (int i = 0; i < m + 1; i++) {
            int te = ma;
            chmax(ma, count[i]);
            if (te != ma) {
                now = i;
            }
        }
        check[now]++;
        chmin(mi, ma);
        num++;
    }
    cout << mi << endl;

    return 0;
}

Measured memory_bytes: 1024
line = input()
size = len(line)
a = line.count('a')
b = line.count('b')
c = size - a - b
MIN = min(min(a, b), c)
a -= MIN
b -= MIN
c -= MIN
if a > 1 or b > 1 or c > 1:
	print('NO')
else:
	print('YES')

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
using namespace std;


vector<vector<int>> dia;
vector<vector<int>> dp = vector<vector<int>>();


void input(){
	string s;
	stringstream ss;
	while (cin >> s){
		replace(s.begin(), s.end(), ',', ' ');
		ss.clear();
		ss << s;

		int a;
		dia.push_back(vector<int>());
		while (ss >> a) dia.back().push_back(a);
	}
}


void makeDP(){
	dp = dia;
	for(int y = 1;y < (int)dp.size();y++){
		for(int x = 0;x < (int)dp[y].size();x++){
			if (y <= (int)dp.size() / 2){
				dp[y][x] = max(dp[y-1][max(0, x-1)], dp[y-1][min(x, (int)(dp[y-1].size()-1))]) + dia[y][x] ;
			}
			else {
				dp[y][x] = max(dp[y-1][x], dp[y-1][x+1]) + dia[y][x];
			}
		}
	}
}


int main(){
	input();

	makeDP();

	cout << dp.back().back() << endl;

	return 0;
}

Measured memory_bytes: 2988
#include <iostream>

using namespace std;
// 1 is sheep
int mem[100005];
int s[100001];
int N;
bool search(int at0, int at1) {
	mem[0] = at0;
	mem[1] = at1;
	for (int i=1; i<N; i++) {
		mem[i+1] = s[i] * mem[i-1] * mem[i];
	}
	
	if (mem[N] == mem[0] && mem[1] == s[0] * mem[N-1]*mem[0]) {
		//clear
		for (int i=0; i<N; i++) {
			cout << ((mem[i]==1)?'S':'W');
		}
		cout << endl;
		return true;
	}
	return false;
}
int main(){
	cin >> N;

	for (int i=0; i<N; i++) {
		char c;
		cin >> c;
		s[i] = c=='o'?1:-1;
	}

	// SS
	if (search(1,1)) {
		return 0;
	}
	// SW
	if (search(1,-1)) {
		return 0;
	}
	// WS
	if (search(-1,1)) {
		return 0;
	}
	// WW
	if (search(-1,-1)) {
		return 0;
	}

	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main()
{
    int n, i, a[100000], b[100000], s=0;
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>b[i];
    }
    a[1]=b[1];
    a[2]=b[1];
    for(i=2;i<n;i++)
    {
        a[i+1]=b[i];
        a[i]=min(a[i],b[i]);
    }
    for(i=1;i<=n;i++)
    {
        s=s+a[i];
    }
    cout<<s;
    return 0;
}


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n, m, t, p; cin >> n >> m >> t >> p;
    if(n == 0 && m == 0 && t == 0 && p == 0) break;
    vector<vector<int>> s(1000, vector<int>(1000, 0));
    for(int i=0;i<m;++i) {
      for(int j=0;j<n;++j) {
        s[i][j] = 1;
      }
    }
    int cx = 0, cy = 0;
    for(int i=0;i<t;++i) {
      int d, c; cin >> d >> c;
      if(d == 1) {
        for(int i=cy; i<1000;++i) {
          for(int j=0;j<c;++j) {
            // cout << i << ":" << j << endl;
            s[i][cx+2*c-1-j] += s[i][cx+j];
          }
        }
        cx += c;
      } else {
        for(int j=cx;j<1000;++j) {
          for(int i=0;i<c;++i) {
            s[cy+2*c-1-i][j] += s[cy+i][j];
          }
        }
        cy += c;
      }
/*       cout << endl;
      for(int i=0;i<m;++i) {
        printv(s[i]);
      } */
    }
/*     cout << endl;
    for(int i=0;i<m;++i) {
      printv(s[i]);
    } */
    for(int i=0;i<p;++i) {
      int x, y; cin >> x >> y;
      cout << s[cy+y][cx+x] << endl;
    }
  }
}



Measured memory_bytes: 6764
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

#define MOD 10007

int N;
string S;
int dp[1000][2][2][2];

//now日目にそれぞれが出席するときのnow日目以降の場合の数
int solve(int now, int J, int O, int I){
	if(S[now]=='J' && J == 0) return 0;
	if(S[now]=='O' && O == 0) return 0;
	if(S[now]=='I' && I == 0) return 0;
	if(now == N-1) return 1;
	if(dp[now][J][O][I] != -1) return dp[now][J][O][I];

	if(J == 1 && O == 0 && I == 0){
		dp[now][J][O][I] = solve(now+1, 1, 0, 0) + solve(now+1, 1, 1, 0)
			+ solve(now+1, 1, 0, 1) + solve(now+1, 1, 1, 1);
	}
	if(J == 1 && O == 1 && I == 0){
		dp[now][J][O][I] = solve(now+1, 1, 0, 0) + solve(now+1, 1, 1, 0)
			+ solve(now+1, 1, 0, 1) + solve(now+1, 1, 1, 1)
			+ solve(now+1, 0, 1, 0) + solve(now+1, 0, 1, 1);
	}
	if(J == 1 && O == 0 && I == 1){
		dp[now][J][O][I] = solve(now+1, 1, 0, 0) + solve(now+1, 1, 1, 0)
			+ solve(now+1, 1, 0, 1) + solve(now+1, 1, 1, 1)
			+ solve(now+1, 0, 0, 1) + solve(now+1, 0, 1, 1);
	}
	if(J == 1 && O == 1 && I == 1){
		dp[now][J][O][I] = solve(now+1, 1, 0, 0) + solve(now+1, 1, 1, 0)
			+ solve(now+1, 1, 0, 1) + solve(now+1, 1, 1, 1)
			+ solve(now+1, 0, 1, 0) + solve(now+1, 0, 1, 1)
			+ solve(now+1, 0, 0, 1);
	}
	if(J == 0 && O == 1 && I == 0){
		dp[now][J][O][I] = solve(now+1, 0, 1, 0) + solve(now+1, 1, 1, 0)
			+ solve(now+1, 0, 1, 1) + solve(now+1, 1, 1, 1);
	}
	if(J == 0 && O == 1 && I == 1){
		dp[now][J][O][I] = solve(now+1, 0, 1, 0) + solve(now+1, 1, 1, 0)
			+ solve(now+1, 0, 1, 1) + solve(now+1, 1, 1, 1)
			+ solve(now+1, 0, 0, 1) + solve(now+1, 1, 0, 1);
	}
	if(J == 0 && O == 0 && I == 1){
		dp[now][J][O][I] = solve(now+1, 0, 0, 1) + solve(now+1, 1, 0, 1)
			+ solve(now+1, 0, 1, 1) + solve(now+1, 1, 1, 1);
	}
	//cout << now << " " << J << " " << O << " " << I << " " << dp[now][J][O][I] << endl;
	return dp[now][J][O][I] = dp[now][J][O][I] % MOD;
}

int main(){

	cin >> N;
	cin >> S;
	for(int i=0; i<N; i++){
		for(int j=0; j<2; j++){
			for(int k=0; k<2; k++){
				for(int l=0; l<2; l++){
					dp[i][j][k][l] = -1;
				}
			}
		}
	}

	cout << (solve(0, 1, 0, 0) + solve(0, 1, 1, 0)
			+ solve(0, 1, 0, 1) + solve(0, 1, 1, 1)) % MOD << endl;


	return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int A, B;
    cin >> A >> B;
    if(A - 2*B > 0)
        cout << A - 2 * B << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 384