akhauriyash/Code-Regression huggingface dataset:
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

		ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
		long startCpuTime = threadMXBean.getCurrentThreadCpuTime(), stopCpuTime = 0;

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\0545-input.txt"));

		while (scan.hasNext()) {

			int m = scan.nextInt();
			int n = scan.nextInt();
			if (m == 0 && n == 0)
				break;
			Map mp = new Map(m, n);
			for (int y = 0; y < n; y++)
				for (int x = 0; x < m; x++)
					mp.add(x, y, scan.nextInt());
			System.out.println(mp.count());
			// stopCpuTime = threadMXBean.getCurrentThreadCpuTime();

		}

		scan.close();
		// stopCpuTime = threadMXBean.getCurrentThreadCpuTime();
		// System.out.println("CPU=" + (stopCpuTime - startCpuTime) / 1000000);

		System.exit(0);
	}
}

class Map {
	int[][] mp;
	boolean[][] flg;
	int stx = -1, sty = -1;
	int cnt = 0;

	public Map(int m, int n) {
		mp = new int[m][n];
		flg = new boolean[m][n];
	}

	public int count() {
		return search(stx, sty, cnt);
	}

	private int search(int x, int y, int c) {
		if (c == 0)
			if (isReach(x, y, stx, sty))
				return 1;
			else
				return 0;

		int ret = 0;
		for (int i = x + 1; i < flg.length; i++)
			if (flg[i][y]) {
				flg[i][y] = false;
				ret += search(i, y, c - 1);
				flg[i][y] = true;
				break;
			}
		for (int i = x - 1; i >= 0; i--)
			if (flg[i][y]) {
				flg[i][y] = false;
				ret += search(i, y, c - 1);
				flg[i][y] = true;
				break;
			}
		for (int i = y + 1; i < flg[0].length; i++)
			if (flg[x][i]) {
				flg[x][i] = false;
				ret += search(x, i, c - 1);
				flg[x][i] = true;
				break;
			}
		for (int i = y - 1; i >= 0; i--)
			if (flg[x][i]) {
				flg[x][i] = false;
				ret += search(x, i, c - 1);
				flg[x][i] = true;
				break;
			}
		return ret;
	}

	private boolean isReach(int x, int y, int x2, int y2) {
		if (x == x2) {
			for (int i = y + 1; i <= y2; i++)
				if (i == y2)
					return true;
			for (int i = y - 1; i >= y2; i--)
				if (i == y2)
					return true;
		}
		if (y == y2) {
			for (int i = x + 1; i <= x2; i++)
				if (i == x2)
					return true;
			for (int i = x - 1; i >= x2; i--)
				if (i == x2)
					return true;
		}
		return false;
	}

	public void add(int x, int y, int s) {
		mp[x][y] = s;
		if (s == 2) {
			stx = x;
			sty = y;
		}
		if (s == 1) {
			cnt++;
			flg[x][y] = true;
		}
	}
}

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

int numberoftimes(int n[12],int x,int *y){
  int a = 0;
  int flag = 0;
  for(int i = 0; i < 12; i++ ) {
    if( n[i] == x ){
      a++;
    }else if(flag == 0){
      flag = 1;
      *y = n[i];
    }
  }

  return a;
}

int main(void){
  int n[12];
  int a,b,c,x,y;

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

  x = n[0];
  a = numberoftimes(n,x,&y);
  x = y;
  b = numberoftimes(n,x,&y);
  x = y;
  c = numberoftimes(n,x,&y);

  if ( a % 4 == 0 && b % 4 == 0 && c % 4 == 0){
    cout << "yes" << endl;
  }else{
    cout << "no" << endl;
  }

  return 0;
}

Measured memory_bytes: 3108
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
count=0
for i in range(1,n+1):
    if len(str(i))%2==1:
        count+=1
print(count)
    
    

    


Measured memory_bytes: 9424
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>
#include <cstdint>
#include <set>
#include <deque>
#include <iomanip>

using namespace std;
using ull = unsigned long long;
using ll = long long;

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

#define EPS (1e-7)
#define ALL(x) begin(x), end(x)

ll coincount(ll base, ll thr) {
	ll count = 0;
	while (base < thr) {
		base = base * 2;
		count++;
	}
	return count;
}

double gyaku(double d, ll num) {
	for (size_t i = 0; i < num; i++) {
		d /= 2.0;
	}
	return d;
}

int main() {
	ll N, K;
	cin >> N >> K;
	double sum = 0.0;
	for (size_t i = 1; i <= N; i++) {
		const ll count = coincount(i, K);
		sum += gyaku(1.0, count);
	}

	const double ans = 1.0 / (double)N * sum;

	cout << setprecision(12) <<  ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, T = map(int, input().split())
t = list(map(int, input().split()))

time = []
for i in range(1, N):
    sub = t[i] - t[i-1]
    time.append(min(sub, T))

time.append(T)

print(sum(time))

Measured memory_bytes: 25744
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  int w;
  string s;
  cin >> s >> w;
  REP(i,s.length()){
    if (i%w==0) cout << s[i];
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    cout.precision(10);
    cout << fixed;

    vector<int>
        arr(n);

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

    int s = 0;
    for (int i = 0; i < k; i++)
    {
        s += arr[i];
    }
    int l = 0;
    int r = k;
    int ans = 0;
    while (r < n)
    {
        ans = max(ans, s);
        s += arr[r++];
        s -= arr[l++];
    }

    ans = max(ans, s);

    double a = (double)ans / 2;
    cout << a << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  int n,q;
  string s;
  cin>>n>>s>>q;
  vector <set<int>> is(26);
  rep(i,n){
    is[s[i]-'a'].insert(i);
  }
  rep(i,q){
    int qn;
    cin>>qn;
    if (qn==1){
      int iq; char cq;
      cin>>iq>>cq;
      iq--;
      is[s[iq]-'a'].erase(iq);
      s[iq]=cq;
      is[s[iq]-'a'].insert(iq);
    }
    if (qn==2){
      int lq,rq;
      cin>>lq>>rq;
      lq--;
      int cnt=0;
      rep(j,26){
      auto it=is[j].lower_bound(lq);
      //  cout<<*it;
       if (it!=is[j].end() && *it<rq) cnt++;
//    auto it1=is[j].begin();
  //  auto it2=is[j].end();
  //    if (*it1<=3 && *it2>=2) cnt++;
      }
      cout<<cnt<<endl;

    }
  }


}


Measured memory_bytes: 24196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		boolean first = true;
		int[] city=null;
		int maxNum = 0;
		int loop = 1;
		int num=0;
		while(in.hasNext()){
			String[] str = in.nextLine().split(" ",0);
			if(first){
				num = Integer.parseInt(str[0]);
				city = new int[num];
				maxNum = Integer.parseInt(str[1]);
				first = false;
			}else{
				int left = Integer.parseInt(str[0]);
				int right = Integer.parseInt(str[1]);
				city[left-1] ++;
				city[right-1]++;
				loop++;
			}
			if(loop == maxNum+1){
				break;
			}

		}
		for(int i=0 ; i<num;i++){
			System.out.println(city[i]);
		}

	}

}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>

using namespace std;

#define rep1(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, n, m) for (long long i = (long long)(n); i <= (long long)(m); i++)
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 (a>b) { a=b; return 1; } return 0; }
const long long mod = 1e9 + 7;

long long rec(long long n, long long p) {
    if (p == 0) {
        return 1;
    } else if (p % 2 == 0) {
        long long tmp = rec(n, p / 2);
        return tmp * tmp % mod;
    }
    return n * rec(n, p - 1) % mod;
}

long long combi(long long n, long long r) {
    long long x = 1;
    rep2(i, n - r + 1, n) x = x * i % mod;
    long long y = 1;
    rep2(i, 1, r) y = y * i % mod;
    return x * rec(y, mod - 2) % mod;
}

int main() {
    long long n, a, b;
    cin >> n;
    cin >> a;
    cin >> b;
    long long total = rec(2, n) - 1;
    long long ac = combi(n, a);
    long long bc = combi(n, b);
    total -= ac;
    if (total < 0) total += mod;
    total -= bc;
    if (total < 0) total += mod;
    cout << total << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
bool check(ll dpa[],ll dpb[],ll n,ll m,ll x,ll k)
{
    for(ll i=0;i<=x;i++)
    {
        ll j = x-i;
        if(i<=n && j<=m)
        {
            if(dpa[i]+dpb[j]<=k)
                return true;
        }
    }
    return false;
}
int main()
{
    fastio();
   
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n],b[m],dpa[n+1]={0},dpb[m+1]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        dpa[i+1]=a[i]+dpa[i];
    }
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
        dpb[i+1]=b[i]+dpb[i];
    }
    ll l=0,h=n+m,mid,ans=0;
    while(l<=h)
    {
        mid = (l+h)/2;
        if(check(dpa,dpb,n,m,mid,k))
        {
            ans = mid;
            l = mid+1;
        }
        else
        {
            h = mid-1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9904
// A - αlphabet
#include <bits/stdc++.h>
using namespace std;

int main(){
	char c; cin>>c;
	// puts('a'<=c && c<='z'? "a":"A");
	// puts(tolower(c) == c? "a":"A");
	puts(toupper(c) == c? "A":"a");
}


Measured memory_bytes: 3552
#include<stdio.h>

long long int gcm(long long a,long long b){
	long long r,tmp;
	if(a<b){
		tmp=a;
		a=b;
		b=tmp;
	}
	
	r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}

int main(){
	long long N,X;
	scanf("%lld%lld",&N,&X);
	long long x[N];
	for(long long i=0;i<N;i++){
		scanf("%lld",&x[i]);
		x[i]-=X;
		if(x[i]<0)x[i]=x[i]*(-1);
	}
	
	long long ans=x[0];
	for(long long i=1;i<N;i++)ans=gcm(ans,x[i]);
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0212

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX_VAL 110
#define MAX_C 12

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

struct edge{ll to, cost;};


int dijkstra(vector<edge> G[MAX_VAL], int s, int g, int V, int c){
	priority_queue<P,vector<P>,greater<P>> q;
	ll d[MAX_C][MAX_VAL];
	
	for(int i = 0; i < MAX_C; i++) for(int j = 0; j < MAX_VAL; j++) d[i][j] = INF;
	
	d[0][s] = 0;
	q.push(P(make_pair(0,s),0));
	
	while(!q.empty()){
		P p = q.top();q.pop();
		ll v = p.first.second;
		
		if(v == g) return d[p.second][v];
		
		if(d[p.second][v] < p.first.first) continue;
		
		for(edge e : G[v]){
			if(d[p.second][e.to] > d[p.second][v] + e.cost){
				d[p.second][e.to] = d[p.second][v] + e.cost;
				q.push(P(make_pair(d[p.second][e.to],e.to),p.second));
			}
			if(c > p.second && d[p.second+1][e.to] > d[p.second][v] + e.cost/2){
				d[p.second+1][e.to] = d[p.second][v] + e.cost/2;
				q.push(P(make_pair(d[p.second+1][e.to],e.to),p.second+1));
			}
		}
	}
	
	// int res = INF;
	
	// for(int i = 0; i <= c; i++){
		// res = min(res,d[i][g]);
	// }
	// return res;
}

signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int c, n, m, s, d;
	int a, b, f;
	edge temp;
	
	
	while(true){
		vector<edge> G[MAX_VAL];
		
		cin>>c>>n>>m>>s>>d;
		
		if(!c&&!n&&!m&&!s&&!d) break;
		
		for(int i = 0; i < m; i++){
			cin>>a>>b>>f;
			temp.cost = f, temp.to = b;
			G[a].push_back(temp);
			temp.to = a;
			G[b].push_back(temp);
		}
		
		cout<<dijkstra(G,s,d,n,c)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
int INF = 10000000;
int main(){
  int R, C, M;
  cin >> R >> C >> M;
  vector<vector<char>> A(R + 2, vector<char>(C + 2, '#'));
  for (int i = 1; i <= R; i++){
    for (int j = 1; j <= C; j++){
      cin >> A[i][j];
    }
  }
  vector<vector<vector<int>>> P(R + 2, vector<vector<int>>(C + 2, vector<int>(3)));
  for (int i = 0; i < 3; i++){
    for (int j = 1; j <= R; j++){
      for (int k = 1; k <= C; k++){
        cin >> P[j][k][i];
      }
    }
  }
  vector<int> y(M), x(M);
  for (int i = 0; i < M; i++){
    cin >> y[i] >> x[i];
    y[i]++;
    x[i]++;
  }
  vector<pair<int, int>> p;
  p.push_back(make_pair(y[0], x[0]));
  for (int i = 0; i < M - 1; i++){
    vector<vector<bool>> used(R + 2, vector<bool>(C + 2, false));
    used[y[i]][x[i]] = true;
    vector<vector<pair<int, int>>> prev(R + 2, vector<pair<int, int>>(C + 2));
    queue<pair<int, int>> Q;
    Q.push(make_pair(y[i], x[i]));
    while (!Q.empty()){
      int cy = Q.front().first;
      int cx = Q.front().second;
      Q.pop();
      for (int j = 0; j < 4; j++){
        int y2 = cy + dy[j];
        int x2 = cx + dx[j];
        if (!used[y2][x2] && A[y2][x2] == '.'){
          used[y2][x2] = true;
          prev[y2][x2] = make_pair(cy, cx);
          Q.push(make_pair(y2, x2));
        }
      }
    }
    vector<pair<int, int>> tmp;
    tmp.push_back(make_pair(y[i + 1], x[i + 1]));
    while (1){
      tmp.push_back(prev[tmp.back().first][tmp.back().second]);
      if (tmp.back() == make_pair(y[i], x[i])){
        tmp.pop_back();
        break;
      }
    }
    reverse(tmp.begin(), tmp.end());
    for (auto c : tmp){
      p.push_back(c);
    }
  }
  int t = p.size();
  vector<vector<int>> prev(R + 2, vector<int>(C + 2, -1));
  long long ans = 0;
  for (int i = 0; i < t; i++){
    int cy = p[i].first;
    int cx = p[i].second;
    if (prev[cy][cx] == -1){
      ans += P[cy][cx][1] + P[cy][cx][2];
    } else {
      ans += min(P[cy][cx][1] + P[cy][cx][2], P[cy][cx][0] * (i - prev[cy][cx]));
    }
    prev[cy][cx] = i;
  }
  cout << ans << endl;
}


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

#金額と理解度のリスト
money = []
skill = []
for i in range(n) :
    a = []
    a = (list(map(int, input().split())))
    money.append(a[0])
    skill.append(a[1:])

#本の購入パターン
l_list = []
for j in range(2 ** n) :
    l = []
    for k in range(n) :
        if (j >> k) & 1 :
            l.append(1)
        else:
            l.append(0)
        
    l_list.append(l)

#金額と理解度の合計のリスト
ans = -1
min_money_sum = sum(money)
for o in l_list :
    ability = [0 for s in range(m)]
    money_sum = 0
    for p in range(n) :
        if o[p] == 1 :
            ability = [q + r for (q, r) in zip(ability, skill[p])]
            money_sum += money[p]
    
    cnt = 0 
    for t in range(m) :
        if ability[t] < x :
            cnt += 1
    
    if cnt == 0 :
        min_money_sum = min(min_money_sum, money_sum)
        ans = 0

#最小額
if ans != -1 :
    print(min_money_sum)
else:
    print(ans)

Measured memory_bytes: 9560
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
void swap(int& a,int& b)
{
	int temp;
	temp=a;
	a=b;
	b=temp;
}
 int main()
{
ll n,k;
cin>>n>>k;
cout<<6-(n+k);
}

Measured memory_bytes: 256
import math
n = int(input())
a = list(map(int, input().split()))

count_list = [0]*n

for i in range(n):
    count_list[a[i]-1] += 1
    
tmp_ans = 0

for i in count_list:
    tmp_ans += math.floor((i*(i-1))/2)

for i in range(n):
    exclution = a[i]
    diff = math.floor((count_list[a[i]-1]*(count_list[a[i]-1]-1))/2) - math.floor(((count_list[a[i]-1]-1)*(count_list[a[i]-1]-2))/2)
    print(tmp_ans-diff)
    
    

Measured memory_bytes: 26140
N = int(input())
As = input().split()
Bs = input().split()

count = 0
r = 0
for i in range(N):
    a = int(As[i])
    b = int(Bs[i])
    count += min(a, r)
    a2 = max(a - r, 0)
    count += min(a2, b)
    r = max(b - a2, 0)

count += min(int(As[N]), r)
print(count)


Measured memory_bytes: 19372
N,x = map(int,input().split())
a = [int(i) for i in input().split()]

a.sort()

counter = 0
for i in range(len(a)):
    x = x - a[i]
    if x < 0:
        break
    counter = counter + 1

if x > 0:
    counter = counter - 1

print(counter)


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

int main(void){
   int room[3][10][4] = {{{0}}};
   int n;
   int a,b,c;
   int x,y,z,w;
   cin >> n;
   for (int i = 0; i<n; i++){
       cin >> x >> y >> z >> w;
       room[y-1][z-1][x-1] += w;
   }
   for (c = 0; c<4; c++){
       for (b = 0; b<3; b++){
           for (a = 0; a<10; a++){
               if(room[b][a][c] == 0){
                   cout << " 0";  
               }
               else{
                   cout << " " << room[b][a][c]; 
               }
           }
           cout << endl;
       }
       if(c != 3){
           cout << "####################" << endl;
       }
   }
}


Measured memory_bytes: 3080
import bisect

a, b, q = map(int, input().split())
INF = float('inf')
s = [-INF] + [int(input()) for _ in range(a)] + [INF]
t = [-INF] + [int(input()) for _ in range(b)] + [INF]
x = [int(input()) for _ in range(q)]

for i in x:
    si = bisect.bisect_left(s, i)
    ti = bisect.bisect_left(t, i)
    sl, sr = i-s[si-1], s[si]-i
    tl, tr = i-t[ti-1], t[ti]-i
    print(min(max(sl,tl), sl+tr+min(sl,tr), sr+tl+min(sr,tl), max(sr,tr)))

Measured memory_bytes: 20876
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

ll dp[200005],n,k;
vector<ll> g[200005];

void dfs(ll node,ll p,ll c)
{
    ll t=(node==1)?1:2;
    dp[node]=(k-c)%mod;
    for(auto y:g[node])
    {
        if(y==p)continue;
        dfs(y,node,t);
        t++;
    }   
}

int main()
{
    ll i,j,l;
    cin>>n>>k;
    dp[1]=k;
    rep(i,0,n-2)
    {
        cin>>j>>l;
        g[j].pb(l);g[l].pb(j);
    }dfs(1,-1,0);
    ll ans=1;
    rep(i,1,n)
    {   //cout<<dp[i]<<" ";
        ans*=(dp[i]);
        ans%=mod;
    }cout<<ans%mod<<en;
    //cout<<1522054186920312832%mod;
    return 0;
}


Measured memory_bytes: 13056
n=int(input())
p=[]

for i in range(2,int(-(-n**0.5//1))+1) :
    if n%i==0 :
        count=0
        while n%i==0 :
            count+=1
            n//=i
        p.append([i,count])

if n!=1 :
    p.append([n,1])


ans=0
for i in range(len(p)) :
    m=p[i][1]
    j=1
    while m>0 :
        m-=j
        if m>=0 :
            j+=1
            ans+=1

print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int L, N, dx[200001];

ll count() {
    ll ret = 0, cs = 0, add_cs = 0;
    FOR(i, 1, N + 1) add_cs += dx[i];

    int p1 = 0, p2 = 1;
    REP(i, N) {
        cs += add_cs;
        ret = max(cs, ret);

        add_cs += (dx[p1] - 2 * dx[p2]);
        if (i % 2 == 0) p1++;
        p2++;
    }
    return max(cs + add_cs, ret);
}

int main() {
    int x, bx = 0;
    cin >> L >> N;
    REP(i, N) {
        cin >> x;
        dx[i] = x - bx;
        bx = x;
    }
    dx[N] = L - bx;

    ll ans = max(count(), 0LL);
    reverse(dx, dx + N + 1);
    ans = max(count(), ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
mod = 1000000007

H,W = map(int,input().split())
root = []
for _ in range(H):
    s = list(input())
    root.append(s)

dp = [[0]*(W+1) for _ in range(H+1)]
dp[0][0] = 1
for h in range(H):
    for w in range(W):
        if root[h][w] == '#':
            continue
        if (h != 0 or w != 0):
            dp[h][w] = (dp[h-1][w] + dp[h][w-1])%mod

print(dp[H-1][W-1])

Measured memory_bytes: 117328
use proconio::input;
#[allow(unused_mut)]
fn main() {
    input! {
        n: usize,
        a: [usize;n]
    }
    let num = a
        .iter()
        .filter(|s| *s % 2 == 0)
        .filter(|s| *s % 3 != 0)
        .filter(|s| *s % 5 != 0)
        .count();
    if num == 0 {
        println!("APPROVED");
    } else {
        println!("DENIED");
    }
}


Measured memory_bytes: 2096
#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;

const int maxn = 10010;
const int INF = 1<<29;
struct edge {
    int to,cost,distance;
    edge(){}
    edge( int x,int y,int z ) {
        to=x;
        distance=y;
        cost=z;
    }
};

typedef pair<int,int>P;
vector<edge>G[maxn];
bool used[maxn];
int d[maxn];
int N;

void dijkstra(int s) {
    priority_queue<P,vector<P>,greater<P> >que;
    for(int i=1;i<=N;i++) d[i]=INF;
    for(int i=1;i<=N;i++) used[i]=false;
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()) {
        P p=que.top(); 
		que.pop();
        int v=p.second;
        if(used[v]) continue;
        for(int i=0;i<G[v].size();i++) {
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.distance) {
                d[e.to]=d[v]+e.distance;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

int main()
{
    int M;
    while(~scanf("%d%d",&N,&M)&&(N+M)) {
        for(int i=1;i<=N;i++) G[i].clear();
        int a,b,c,v;
        for(int i=0;i<M;i++) {
            scanf("%d%d%d%d",&a,&b,&c,&v);
            G[a].push_back(edge(b,c,v));
            G[b].push_back(edge(a,c,v));
        }
        dijkstra(1);
        int sum=0;
        for(int i=2;i<=N;++i) {
            int min_cost=INF;
            for(int j=0;j<G[i].size();++j) {
                edge &e=G[i][j];
                if(d[e.to]+e.distance==d[i]&&e.cost<min_cost)
                {
                    min_cost=e.cost;
                }
            }
            sum+=min_cost;
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 5064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		if (N % 2 == 0)
			System.out.println(N);
		else
			System.out.println(N * 2);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


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


int main()
{
    string a,b;
    cin>>a;
    b=a;
    int x=1;
    int len=a.size();
    reverse(b.begin(),b.end());
    if(a==b){
        x=0;
    }
    int c=0,d=0;
    int p=(len-1)/2;
    int q=(len+3)/2;

    for(int i=0,j=p-1;i<p,j>=0;i++,j--){
        if(a[i]==a[j]){
            c++;
           ;
        }
    }
    for(int i=q-1,j=len-1;i<len,j>=0;i++,j--){
        if(a[i]==a[j]){
            d++;

        }
    }


     if(x==0 && c==p && d==len-q+1){
        printf("Yes");
     }
     else{
        printf("No");
     }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

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; }

const ll INF=1LL << 60;


int main() {
  int n;cin >> n;
  map<string,int> ss;
  queue<string> x;
  string s;cin >> s;
  ss[s]=1;x.push(s);
  rep(i,n-1){
    string p;cin >> p;
    string y=x.front();
    x.pop();
    if(ss[p]==1){cout << "No";return 0;}
    if(y[(y.size())-1] != p[0]){cout << "No";return 0;}
    x.push(p);
    ss[y]=1;
  }

  cout << "Yes";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int N, M, R;
int d[201][201];
int r[9];
int INF = 1 << 29;
int res = INF;
bool used[9];
void dfs(int c, int las, int dist) {
	if (c == R + 1) {
		if (res > dist) res = dist;
		return;
	}
	else {
		for (int i = 1; i <= R; ++i) {
			if (!used[i]) {
				used[i] = true;
				if (las == -1) dfs(c + 1, i, 0);
				else dfs(c + 1, i, dist + d[r[las]][r[i]]);
				used[i] = false;
			}
		}
	}
}
int main(void) {
	cin >> N >> M >> R;
	for (int i = 1; i <= R; ++i) {
		cin >> r[i];
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (i != j) {
				/*d[i][j] = 0;
			}
			else {*/
				d[i][j] = INF;
			}
		}
	}
	for (int i = 1; i <= M; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		if (d[a][b] > c) {
			d[a][b] = d[b][a] = c;
		}
	}
	for (int k = 1; k <= N; ++k) {
		for (int i = 1; i <= N; ++i) {
			for (int j = 1; j <= N; ++j) {
				if (d[i][j] > d[i][k] + d[k][j]) {
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}
	dfs(1, -1, 0);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp(a,b) make_pair(a,b)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };

int modpow(int x, int n, int mod) {
	if (!n)return 1;
	int res = modpow(x*x%mod, n / 2, mod);
	if (n & 1)res = res*x%mod;
	return res;
}

signed main() {
	int n, k; cin >> n >> k;
	if (k == 1)cout << 0 << endl;
	else cout << n - k << endl;
}

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

int main(){
	int H, W, i, j;	
	
	while(1){
		cin>>H>>W;

		if (H == 0 && W == 0) break;

		for(i = 0; i < H; i++){
			for(j = 0; j < W; j++){
				cout<<"#";
			}
			cout<<endl;
		}
	cout<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            int M = sc.nextInt();
            int[][] data = new int[N][];
            for (int i = 0; i < N; i++) {
                data[i] = new int[2];
                data[i][0] = sc.nextInt();
                data[i][1] = sc.nextInt();
            }
            Arrays.sort(data, (a,b) -> a[0] - b[0]);
            long sum = 0;
            int index = 0;
            while(M != 0) {
                if (M - data[index][1] < 0) {
                    sum += (long) data[index][0] * M;
                    M = 0;
                    index++;
                } else {
                    M = M - data[index][1];
                    sum += (long) data[index][0] * (long) data[index][1];
                    index++;
                }
            }
            System.out.println(sum);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

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

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

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

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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

const int dx[]={1,-1,0,0},
		  dy[]={0,0,1,-1};

const int inf=1e9;

int n,m,a[N],k,q,u,v,x,y,tc,c,l,r,ans,p,cnt,root[N],sz[N];

char s[N];

bool ok[N];

vector<int> f[N],b[N];

int Find(int u){
	if (root[u]==u)
		return u;
	return root[u]=Find(root[u]);
}

int main(){
	
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		root[i]=i;
		sz[i]=1;
	}
	while(m--){
		scanf("%d %d",&u,&v);
		f[u].push_back(v);
		f[v].push_back(u);
		int _u=Find(u),_v=Find(v);
		if (_u!=_v){
			root[_u]=_v;
			sz[_v]+=sz[_u];
		}
	}
	while(k--){
		scanf("%d %d",&u,&v);
		b[u].push_back(v);
		b[v].push_back(u);
	}
	for(int i=1;i<=n;i++){
		int u=Find(i);
		int ans=sz[u]-f[i].size()-1;
		for(int j=0;j<b[i].size();j++){
			int v=b[i][j];
			int _v=Find(v);
			if (u==_v)
				ans--;
		}
		printf("%d ",ans);
	}

}



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

int main() {
	// your code goes here
	int K,S;
	cin >> K >> S;	

	int counter=0;
	for(int X=0; X<=K; X++)
		for(int Y=0; Y<=K; Y++) {
			int Z = S -(X+Y);
			if ((0 <= Z) && (Z <= K)) counter++;
			}
	cout << counter << '\n';
	return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

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

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

template< typename T, typename Compare = greater< T > >
vector< T > knapsack_limitations(const vector< int > &w, const vector< int > &m, const vector< T > &v,
                                 const int &W, const T &NG, const Compare &comp = Compare()) {
  const int N = (int) w.size();
  vector< T > dp(W + 1, NG), deqv(W + 1);
  dp[0] = T();
  vector< int > deq(W + 1);
  for(int i = 0; i < N; i++) {
    for(int a = 0; a < w[i]; a++) {
      int s = 0, t = 0;
      for(int j = 0; w[i] * j + a <= W; j++) {
        if(dp[w[i] * j + a] != NG) {
          auto val = dp[w[i] * j + a] - j * v[i];
          while(s < t && comp(val, deqv[t - 1])) --t;
          deq[t] = j;
          deqv[t++] = val;
        }
        if(s < t) {
          dp[j * w[i] + a] = deqv[s] + j * v[i];
          if(deq[s] == j - m[i]) ++s;
        }
      }
    }
  }
  return dp;
}

int main() {
  int N, W;
  cin >> N >> W;
  vector< int > v(N), w(N), m(N);
  for(int i = 0; i < N; i++) {
    cin >> v[i] >> w[i] >> m[i];
  }
  auto ret = knapsack_limitations(w, m, v, W, -1);
  cout << *max_element(begin(ret), end(ret)) << endl;
}



Measured memory_bytes: 3204
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read()[0];
    let a: Vec<usize> = read();
    let b: Vec<usize> = read();

    let mut ans = a[0] + b.iter().sum::<usize>();
    let mut candies = ans;
    for i in 1..n {
        candies = candies + a[i] - b[i - 1];
        ans = std::cmp::max(ans, candies);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let (n, m): (usize, usize) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a = ws.next().unwrap().parse().unwrap();
        let b = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    let (p, s): (Vec<usize>, Vec<String>) = {
        let mut v: Vec<usize> = Vec::new();
        let mut s: Vec<String> = Vec::new();
        for _ in 0..m {
            let (a, b): (usize, String) = {
                let mut s = String::new();
                std::io::stdin().read_line(&mut s).unwrap();
                let s = s.trim_right().to_owned();
                let mut ws = s.split_whitespace();
                let a = ws.next().unwrap().parse().unwrap();
                let b = ws.next().unwrap().parse().unwrap();
                (a, b)
            };
            v.push(a);
            s.push(b);
        }
        (v, s)
    };

    let ac = "AC";
    let wa = "WA";
    let mut is_ac = vec![false; n];
    let mut v_penalty = vec![0; n];
    let mut ac_num = 0;
    for i in 0..m {
        let p = p[i] - 1;
        if !is_ac[p] {
            if s[i] == ac {
                ac_num += 1;
                is_ac[p] = true;
            } else {
                v_penalty[p] += 1;
            }
        }
    }

    let mut penalty = 0;
    for i in 0..n {
        if is_ac[i] {
            penalty += v_penalty[i];
        }
    }
    println!("{} {}", ac_num, penalty);
}


Measured memory_bytes: 11768
N, M = map(int, input().split())
Ks = []
for _ in range(M):
    tmp = list(map(int, input().split()))
    k = tmp[0]
    s = tmp[1:]
    Ks.append(s)

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


def is_light_on(values):
    for i in range(M):
        count = 0
        for s in Ks[i]:
            if values[s-1] == 'on':
                count += 1
        if count % 2 != Ps[i]:
            return 0

    return 1


def search(depth, values):
    global ans
    if depth == N:
        ans += is_light_on(values)
    else:
        search(depth=depth+1, values=values+['on'])
        search(depth=depth+1, values=values+['off'])


ans = 0
search(depth=0, values=[])
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) (V).begin(),(V).end()
const ll MOD = 998244353;

ll dp[310][90010] = { 0 };

ll half(ll a) {
	if (a % 2)
		return (a + MOD) / 2;
	else
		return a / 2;
}

ll rp(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b % 2)
			ans *= a;
		b /= 2;
		a *= a;
		ans %= MOD;
		a %= MOD;
	}
	return ans;
}

int main() {
	int N;cin >> N;
	ll cnt = 0, p2n = rp(2, N), p3n = rp(3, N);
	vector<int> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		cnt += A[i];
	}
	for (int i = 0;i < N;i++) {
		if (i == 0) {
			dp[0][0] = p2n;
			dp[0][A[i]] = half(p2n);
			continue;
		}
		for (int j = 0;j <= cnt;j++) {
			if (j >= A[i]) {
				dp[i][j] += half(dp[i - 1][j - A[i]]);
			}
			dp[i][j] += dp[i - 1][j];
			dp[i][j] %= MOD;
		}
	}
	ll ans = 0;
	for (int j = (cnt + 1) / 2;j <= cnt;j++) {
		ans += dp[N - 1][j];
		ans %= MOD;
	}
	if (cnt % 2 == 0) {
		for (int i = 0;i < N;i++) {
			for (int j = 0;j <= cnt / 2;j++) {
				dp[i][j] = 0;
				if (i) {
					dp[i][j] += dp[i - 1][j];
					if (j >= A[i])
						dp[i][j] += dp[i - 1][j - A[i]];
				}
				else {
					if (j == 0 || j == A[i])dp[i][j] = 1;
				}
				dp[i][j] %= MOD;
			}
		}
		ans -= dp[N - 1][cnt / 2];
	}
	ans += MOD * 2;
	ans *= 3;
	ans %= MOD;
	cout << ((p3n - ans) + MOD) % MOD << endl;
}

Measured memory_bytes: 212864
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = a; i < (b + a); i++)
#define W1 while (1)
#define COUT(x) cout << x << endl
using namespace std;
using ll = long long;
using ld = long double;
#define ALL(x) x.begin(),x.end()
#define P pair<int,int>
#define mod 1000000007
#define PB push_back
#define F first
#define S second

int main() {
  char c;
  cin >> c;
  c++;
  COUT(c);

  return 0;
}


Measured memory_bytes: 3564
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
using namespace std;
#define NIL -2000000001
#define MAX 2000000000000

int main() {
  long long n;
  scanf("%lld", &n);
  long long X[n];
  map<long long, long long> m1, m2;
  for( int i=0; i<n; i++ ){
    scanf("%lld", &X[i]);
    if (i % 2 == 0) {
      ++m1[X[i]];
    } else {
      ++m2[X[i]];
    }
  }

  map<long long, long long>::iterator ite;
  long long max1=0, max2=0, m1f, m2f, sec1=0, sec2=0;
  for (ite = m1.begin(); ite != m1.end(); ++ite) {
    if (max1 < ite->second) {
      sec1 = max1;
      max1 = ite->second;
      m1f = ite->first;
    } else if (sec1 < ite->second) {
      sec1 = ite->second;
    }
  }
  for (ite = m2.begin(); ite != m2.end(); ++ite) {
    if (max2 < ite->second) {
      sec2 = max2;
      max2 = ite->second;
      m2f = ite->first;
    } else if (sec2 < ite->second) {
      sec2 = ite->second;
    }
  }

  long long printnum;
  if (m1f != m2f) {
    printnum = n-max1-max2;
  } else {
    printnum = min(n-sec1-max2,n-max1-sec2);
  }

  printf("%lld\n", printnum);

  return 0;
}


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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int n;
	cin >> n;
	int sum = n;
	for(int i = 0; i < n; i++){
		sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
using pi = pair<int, int>;

const int M=1e9+7;
bool sortbysec(const pair<int,int> &a,
                   const pair<int,int> &b)
{
       return a.second<b.second;
}

long long mod(long long x){
    return ((x%M + M)%M);
}

long long add(long long a, long long b){
    return mod(mod(a)+mod(b));
}

long long mul(long long a, long long b){
    return mod(mod(a)*mod(b));
}

long long minu(long long a, long long b){
    return mod(mod(a)-mod(b));
}

ll modPow(ll a, ll b){
    if(b==0)
        return 1LL;
    if(b==1)
        return a%M;
    ll res=1;
    while(b){
        if(b%2==1)
            res=mul(res,a);
        a=mul(a,a);
        b=b/2;
    }
    return res;
}


int main()
{
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        string s;
        cin >> s;
        if(s[s.size()-1] == 's')s+="es";
        else s+='s';
        cout << s << endl;
    }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int h,w,n,x,y,lx,rx,ly,ry;
string s,t;

int main(){
	cin>>h>>w>>n>>x>>y;
	cin>>s>>t;
	lx=1,rx=h,ly=1,ry=w;
	bool B=1;
	for(int i=n-1;i>=0;i--){
		if(t[i]=='L') ry=min(ry+1,w);
		if(t[i]=='R') ly=max(ly-1,1);
		if(t[i]=='U') rx=min(rx+1,h);
		if(t[i]=='D') lx=max(lx-1,1);
		if(s[i]=='L') ly=ly+1;
		if(s[i]=='R') ry=ry-1;
		if(s[i]=='U') lx=lx+1;
		if(s[i]=='D') rx=rx-1;
		if(rx<lx||ry<ly) B=0;
	}
	if(B&&lx<=x&&x<=rx&&ly<=y&&y<=ry) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 776
#include<stdio.h>

int main(void) {
int A, B, C, D;
scanf("%d %d %d %d", &A, &B, &C, &D);
int train = 0;
int bus = 0;
if  (A > B) train = B;
else train = A;

if  (C > D) bus = D;
else bus = C;

printf("%d", train + bus);

 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int size = s.length();
	int a = 0, z = 0;

	for (int i = 0; i < size; i++)
	{
		if (s[i] == 'A') break;
		a++;
	}
	for (int j = size - 1; j >= 0; j--)
	{
		if (s[j] == 'Z') break;
		z++;
	}
	cout << size - (a + z) << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int p,l,r;};
struct Node T[MAX];
int n;

void preParse(int u){
  if(u==NIL)return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if(u==NIL)return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

void postParse(int u){
  if(u==NIL)return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }
for(i=0;i<n;i++){
  scanf("%d %d %d",&v,&l,&r);
T[v].l=l;
T[v].r=r;
if(l!=NIL)T[l].p=v;
if(r!=NIL)T[r].p=v;
}
for(i=0;i<n;i++)if(T[i].p==NIL)root=i;

printf("Preorder\n");
preParse(root);
printf("\n");
printf("Inorder\n");
inParse(root);
printf("\n");
printf("Postorder\n");
postParse(root);
printf("\n");

return 0;
}



Measured memory_bytes: 2096
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int maxn = 2e5 + 500;
int a[maxn];
int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);
	cout << a[n - 1] << " ";
	int kk=a[n-1],x = a[n - 1] / 2;
	int p = lower_bound(a, a + n - 1, x) - a;
	if (a[p] == x)
		cout << x << endl;
	else if (kk % 2 == 1)
	{
		if(a[p]==x||a[p]==x+1)
			cout << a[p] << endl;
		else
		{
			int xx = min(abs(a[p] - x), abs(a[p] - x - 1));
			int yy= min(abs(a[p-1] - x), abs(a[p-1] - x - 1));
			if (xx < yy)
				cout << a[p] << endl;
			else
				cout << a[p - 1] << endl;
		}
	}
	else
	{
		int xx = abs(a[p] - x);
		int yy = abs(a[p - 1] - x);
		if (xx < yy)
			cout << a[p] << endl;
		else
			cout << a[p - 1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 640
H,W=map(int, input().split())

bomb=[]

for i in range(H):
    bomb.append(list(input()))

for i in range(len(bomb)):
    bomb[i].insert(0,0)
    bomb[i].append(0)

bomb.insert(0,[0 for j in range(W+2)])
bomb.append([0 for j in range(W+2)])

result=[[0 for i in range(W+2)] for j in range(H+2)]

count=0

for i in range(1,H+1):
    for j in range(1,W+1):
        if bomb[i][j]=='#':
            result[i][j]=-1
            for k in range(i-1,i+2):
                for l in range(j-1,j+2):
                    if(bomb[k][l] != '#'):
                        result[k][l]+=1

for i in range(1,H+1):
    for j in range(1,W+1):
        if result[i][j]==(-1):
            print("#",end="")
        else:
            print(result[i][j],end="")
    print("")

Measured memory_bytes: 3572