akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,t; cin >> n >> t;
  vector<int> st,en;
  int nen = t;
  int nst = 0;
  for(int i = 0; i < n; ++i){
    int x; cin >> x;
    if(x > nen){
      st.push_back(nst);
      en.push_back(nen);
      nst = x;
    }
    nen = x + t;
  }
  st.push_back(nst);
  en.push_back(nen);
  int ans = 0;
  for(int i = 0; i < (int)st.size(); ++i){
    debug(st[i]);
    debug(en[i]);
    ans += en[i] - st[i];
  }
  cout << ans << endl;
}



Measured memory_bytes: 3604
package main

import (
	"bufio"
	"fmt"
	"os"
)

type Edge struct {
	source, target, cost int
}

const Inf = 1 << 60

func main() {
	N, M := ReadInt(), ReadInt()
	edges := make([]Edge, M)
	for i := 0; i < M; i++ {
		edges[i].source = ReadInt() - 1
		edges[i].target = ReadInt() - 1
		edges[i].cost = -ReadInt()
	}
	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = Inf
	}
	d[0] = 0
	foundNegativeCycle := false
	for i := 0; i < N; i++ {
		update := false
		for _, e := range edges {
			if d[e.source] == Inf {
				continue
			}
			newD := d[e.source] + e.cost
			if newD < d[e.target] {
				d[e.target] = newD
				update = true
				if i == N-1 && e.target == N-1 {
					foundNegativeCycle = true
				}
			}
		}
		if !update {
			break
		}
	}
	if foundNegativeCycle {
		fmt.Println("inf")
	} else {
		fmt.Println(-d[N-1])
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

int main(){
  int A,B,C,D,x,y;
  cin >> A >> B >> C >> D;
  x = A + B;
  y = C + D;
  if(x > y){
  cout << "Left" << endl;
  }
  else if (x == y){
  cout << "Balanced" << endl;
  }
  else{
  cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
p = 2019
s = list(map(int, list(input())))[::-1]
n = len(str(s))

sum = 0
cnt = [0] * p
cnt[0] = 1
n = len(s)
for i in range(n):
    d = s[i] * pow(10, i, p)
    sum = (sum + d) % p
    cnt[sum] += 1

ans = 0
if p in [2, 5]:
    if p == 2:
        ok_list = [0, 2, 4, 6, 8]
    if p == 5:
        ok_list = [0, 5]

    for i in range(n):
        d = s[i]
        if d in ok_list:
            ans += n - i
           
else:
    for i in range(p):
        ans += cnt[i] * (cnt[i]-1) // 2


print(ans)


Measured memory_bytes: 99160
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007 
int main(){
   int n;
   long long sum=0,s=0;
   long long a[200005];
   cin>>n;
   for(int i=0; i<n; i++){
       cin>>a[i];
       s+=a[i];
       s%=MOD;
   }
   for(int i=0; i<n; i++){
        s-=a[i];
        if (s < 0) s += MOD;
        sum+=a[i]*s;
        sum%=MOD;
   }

   cout<<sum<<'\n';
   return 0;
}

Measured memory_bytes: 5184
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s0 = Console.ReadLine().Split(' ');
            int N = int.Parse(s0[0]);
            long K = long.Parse(s0[1]);

            string s = Console.ReadLine();
            int firstR = 0;
            int lastR = 0;
            int firstL = 0;
            int lastL = 0;
            long RL = 0;
            long LR = 0;

            if (s[0] == 'L')
            {
                firstL = 1;
            }
            else
            {
                firstR = 1;
            }

            if (s[N - 1] == 'R')
            {
                lastR = 1;
            }
            else
            {
                lastL = 1;
            }

            long ans = 0;
            char prev = s[0];
            for (int i = 1; i < N; i++)
            {
                if (prev == s[i])
                {
                    ans++;
                }
                else
                {
                    if (prev == 'L')
                    {
                        LR++;
                    }
                    else if (prev == 'R')
                    {
                        RL++;
                    }
                }

                prev = s[i];
            }


            long add = Math.Min(LR, RL);
            add = Math.Min(K, add);

            K -= add;
            ans += add * 2;

            LR -= add;
            RL -= add;

            if (firstL == 1 && LR > 0 && K > 0)
            {
                ans++;
                LR--;
                K--;
            }
            if (firstR == 1 && RL > 0 && K > 0)
            {
                ans++;
                RL--;
                K--;
            }



            if (lastR == 1 && LR > 0 && K > 0)
            {
                ans++;
                LR--;
                K--;
            }
            if (lastL == 1 && RL > 0 && K > 0)
            {
                ans++;
                RL--;
                K--;
            }

            Console.WriteLine(ans);
        }
    }
}




Measured memory_bytes: 13280
import sys
sys.setrecursionlimit(100000000)

N,X = map(int,input().split())

total_b = [0]
total_p = [1]
total = [1]

for i in range(N):
    b = total_b[-1]*2 + 2
    p = total_p[-1]*2 + 1
    x = b+p
    total_b.append(b)
    total_p.append(p)
    total.append(x)
#print(total,total_b,total_p)

def dfs(x,level):
    if x == 1 or x == 0:
        #print(1)
        return 0
    if x == total[level-1] + 1:
        #print(2)
        return total_p[level-1]
    if x == total[level-1] + 2:
        #print(3)
        return total_p[level-1] + 1
    if x == total[level-1]*2 + 2:
        #print(4)
        return total_p[level-1]*2 + 1
    if x == total[level-1]*2 + 3:
        #print(5)
        return total_p[level-1]*2 + 1
    if x > 1 and total[level-1] + 1 > x:
        #print(6)
        return dfs(x-1,level-1)
    if x > total[level-1] + 2 and total[level-1]*2 + 2 > x:
        #print(7)
        return dfs(x - total[level-1] - 2,level-1) + total_p[level-1] + 1
ans = dfs(X,N)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n;
    ll y;
    cin>>n>>y;
    int man=0;
    int gosen=0;
    int sen=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            int remain=n-i-j;
            if(remain>=0 and 10000*i+5000*j+1000*remain==y)
            {
                cout<<i<<" "<<j<<" "<<remain;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int n,m;
unsigned long long w[110],v[110];
unsigned long long f[100010];

int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=m;j>=w[i];j--)
		{
			f[j]=max(f[j],f[j-w[i]]+v[i]);
		}
	}
	cout<<f[m];
	return 0;
} 

Measured memory_bytes: 1024
h, w, k = map(int, input().split())
c = [[] for _ in range(h)]
count = 0

for i in range(h):
  c_now = input()
  c[i] = [0 if cc=="." else 1 for cc in c_now]
  
  

for i in range(2**h):
  ii = bin(i)[2:].zfill(h)
  for j in range(2**w):
    jj = bin(j)[2:].zfill(w)
    
    count_now = 0
    for hh in range(h):
      if(ii[hh] == '1'):
        continue
      
      for ww in range(w):
        if(jj[ww] == '1'):
          continue
        if(c[hh][ww] == 1):
          count_now += 1
    if(count_now == k):
      count += 1
        
print(count)

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

using namespace std;

const int N = 3003;
typedef long long ll;
const ll MOD = 1000000007ll;
ll p1[N],p2[N],comb[N][N];
int l[N],r[N];
char S[N];

int main(){
    int n,m;
    scanf("%d%d%s",&n,&m,S);
    for(int i = 0; i<m; i++){
        scanf("%d%d",&l[i],&r[i]);
        l[i]--,r[i]--;
        if(i&&l[i]==l[i-1]){
            r[i-1] = max(r[i],r[i-1]);
            i--;
            m--;
        }else if(i&&r[i]<=r[i-1]){
            i--;
            m--;
        }
    }
    for(int i = 0; i<N; i++){
        comb[i][0] = comb[i][i] = 1;
        for(int j = 1; j<i; j++)
            comb[i][j] = (comb[i-1][j-1]+comb[i-1][j])%MOD;
    }
    p1[0] = 1;
    int rem = 0;
    for(int i = 0; i<m; i++){
        int nxt = 0;
        if(i<m-1&&l[i+1]<=r[i])
            nxt = r[i]-l[i+1]+1;
        int L = l[i];
        if(i&&r[i-1]>=l[i])
            L = r[i-1]+1;
        int R = r[i];
        int cnt = 0;
        for(int j = L; j<=R; j++)
            cnt += (S[j]=='1');
        for(int j = 0; j<=nxt; j++)
            p2[j] = 0;
        int sz = r[i]-l[i]+1;
        for(int j = 0; j<=rem; j++){
            int avail = cnt+j;
            for(int k = 0; k<=nxt; k++){
                int sel = avail-k;
                if(sz-nxt-sel>=0&&sel>=0)
                    p2[k] = (p2[k]+(p1[j]*comb[sz-nxt][sel])%MOD)%MOD;
            }
        }
        for(int k = 0; k<=nxt; k++) p1[k] = p2[k];
        rem = nxt;
    }
    printf("%lld\n",p1[0]);
    return 0;
}

Measured memory_bytes: 69120
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
signed main() {
	ll q, n; cin >> n;
    for (int i = 1; i <= 3500; i++) {
        for (int j = 1; j <= 3500; j++) {
            ll bunbo = n * i * j;
            ll bunsi = 4 * i * j - n * j - n * i;
            if (bunsi > 0 && bunbo % bunsi == 0) {
                cout << i << ' ' << j << ' ' << bunbo / bunsi << endl; return 0;
            }
        }
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<lli>>;
using P = pair<int, int>;
// }}} End Header
typedef struct {
	lli to;
	lli cost;
}edge;
vector<vector<edge>> G(100010);
vector<lli> dist(100010, 0);
lli K;

int main(){
	lli n, Q;
	queue<lli> q;
	cin >> n;
	rep(i,n-1){
		lli a, b, c;
		cin >> a >> b >> c;
		G[a].push_back({b, c});
		G[b].push_back({a, c});
	}
	cin >> Q >> K;
	q.push(K);
	while(!q.empty()){
		int v = q.front();
		q.pop();
		for(const auto& x : G[v]){
			if(dist[x.to] > 0 || x.to == K) continue;
			dist[x.to] = dist[v] + x.cost;
			q.push(x.to);
		}
	}
	rep(i,Q){
		lli x, y;
		cin >> x >> y;
		cout << dist[x]+dist[y] << endl;
	}
	return 0;
}

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

int main() {
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(a*n,b)<<endl;
}


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

const int MOD = 1e9 + 7;
void add(int &a, int b)
{
	a += b;
	if (a >= MOD)
		a -= MOD;
}

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

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

	vector<string> grid(h);
	for (int i = 0; i < h; i++)
		cin >> grid[i];

	vector<vector<int>> dp(h, vector<int>(w));
	dp[0][0] = 1;

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (grid[i][j] == '#')
				continue;
			if (i != 0)
				add(dp[i][j], dp[i - 1][j]);
			if (j != 0)
				add(dp[i][j], dp[i][j - 1]);
		}
	}
	
	cout << dp[h - 1][w - 1] << "\n";
}

Measured memory_bytes: 5248
def diff(s, t)
  n = [s.size, t.size].min
  
  c = 0
  
  n.times do |i|
    c += (s[i] == t[i]) ? 1 : 0
  end
  
  return c
end

def main(argv)
  s = gets.chomp
  n = s.size
  
  p = '01' * ((n + 1) / 2)
  q = '10' * ((n + 1) / 2)
  
  puts [diff(s, p), diff(s, q)].min.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 2172
#include<stdio.h>

int main(void)
{
	int x = 1, y = 1;

	while((x != 0) || (y != 0))
	{
		scanf("%d %d", &x, &y);

		if((x != 0) || (y != 0))
		{
			if(x <= y)
			{
				printf("%d %d\n", x, y);
			}
			else
			{
				printf("%d %d\n", y, x);
			}
	
		}
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int cnt = 0;
		for (int i = 0;i <= a;i++){
			for (int j = 0;j <= b;j++){
				for (int k = 0;k <= c;k++){
					if (500 * i + 100 * j + 50 * k == x){
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
		sc.close();
	}
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String[] list = scanner.nextLine().split(" ");

		int t_v = Integer.parseInt(list[0]);
		int t_a = Integer.parseInt(list[1]);
		int a_v = Integer.parseInt(list[2]);
		int a_a = Integer.parseInt(list[3]);
		int t_flag = 0;
		int a_flag = 0;


		while(t_v > 0 || a_v > 0) {
			a_v -= t_a;
			if(a_v <= 0) {
				t_flag ++;
				break;
			}
			t_v -= a_a;
			if(t_v <= 0) {
				a_flag ++;
				break;
			}
		}

		if(t_flag == 1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 35768
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i, n) cin >> a.at(i);
    rep(i, n) cin >> b.at(i);
    rep(i, n) cin >> c.at(i);

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    vector<ll> d(n), e(n+1, 0);
    for(int i=0; i<n; i++){
        if(b.at(i)>c.at(n-1)){
            d.at(i);
            e.at(i+1) = e.at(i);
            continue;
        }
        int tmp = lower_bound(c.begin(), c.end(), b.at(i)+1LL) - c.begin();
        d.at(i) = n - tmp;
        e.at(i+1) = e.at(i) + d.at(i); 
        dump(e.at(i+1));
    }

    ll mina; 
    ll ans = 0;
    for(int i=0; i<n; i++){
        mina = a.at(i)+1;
        if(mina>b.at(n-1)) break;
        int tmp = lower_bound(b.begin(), b.end(), mina) - b.begin();
        ans += e.at(n) - e.at(tmp);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <ctime>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
using namespace std; const int N=3010, Mod=998244353;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w;
}
void print(int x) {if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,S;
int a[N],dp[N][N],G;
inline int ksc(int x,int p) {int res=1; for(;p;p>>=1, x=x*x%Mod) if(p&1ll) res=res*x%Mod; return res; } 
signed main()
{
	G=ksc(2,Mod-2);
	n=read(), S=read();
	for(ri int i=1;i<=n;i++) a[i]=read();
	dp[0][0]=ksc(2,n);
	for(ri int i=1;i<=n;i++)for(ri int k=0;k<=S;(dp[i][k]+=dp[i-1][k])%=Mod, k++)
	if(a[i]<=k)dp[i][k]=dp[i-1][k-a[i]]*G%Mod;
	printf("%lld\n",dp[n][S]);
	return 0;
}

Measured memory_bytes: 74276
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

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

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll N, M, K; std::cin >> N >> M >> K;
  std::vector<ll> A(N), B(M);
  rep(i,N) std::cin >> A[i];
  rep(i,M) std::cin >> B[i];

  std::vector<ll> a(N+1), b(M+1);
  rep(i,N) a[i+1] = a[i] + A[i];
  rep(i,M) b[i+1] = b[i] + B[i];

  ll ans = -1;
  for(int x=0; x<=N; x++) {
    if ( K - a[x] < 0 ) break;
    auto itr = std::upper_bound( all(b), K-a[x] );
    if ( itr == b.begin() ) ans = std::max<ll>(ans, x);
    else {
      itr--;
      ans = std::max<ll>(ans, x + std::distance(b.begin(), itr));
    }
  }
  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 9536
#include<iostream>
using namespace std;
int a,b,c,x,ans;
int main()
{
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
    {
        for(int j=0;j<=b;j++)
        {
             for(int k=0;k<=c;k++)
            {
                if(i*500+j*100+k*50==x) ans++;
                else if(i*500+j*100+k*50>x) break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> multi_vector(size_t a){return vector<T>(a);}template<class T, class... Ts>auto multi_vector(size_t a, Ts... ts){return vector<decltype(multi_vector<T>(ts...))>(a, multi_vector<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  ll maxi{};
  ll sum{};
  rep(i, 0, N){
    ll p;
    cin >> p;
    maxi = max(maxi, p);
    sum += p;
  }
  cout << sum - maxi/2 << rt;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = input()
c = Counter(S[1:])
E_count = c['E']
min_count = E_count

W_left = 0
E_right = E_count
for i in range(1, N):
    if S[i - 1] == 'W':
        W_left += 1
    if S[i] == 'E':
        E_right -= 1
    if W_left + E_right < min_count:
        min_count = W_left + E_right
print(min_count)


Measured memory_bytes: 4084
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
    Node *y =NIL;
    Node *x=root;
    Node *z;
    
    z=(Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while(x!=NIL){
        y=x;
        if(z->key < x->key){
            x=x->left;
        } else {
            x=x->right;
        }
        }
        z->parent=y;
        if(y==NIL){
            root = z;
        } else {
            if(z->key < y->key){
                y->left = z;
            } else {
                y -> right = z;
            }
        }
    }
    
    void inorder(Node *u){
        if(u==NIL) return;
        inorder(u->left);
        printf(" %d", u->key);
        inorder(u->right);
    }
    void preorder(Node *u){
        if(u==NIL)return;
        printf(" %d", u->key);
        preorder(u->left);
        preorder(u->right);
    }
    
    int main(){
        int n, i, x;
        string com;
        
        scanf("%d", &n);
        
        for (i=0; i<n; i++){
            cin >> com;
            if (com == "insert"){
                scanf("%d", &x);
                insert(x);
            }else if(com=="print"){
                inorder(root);
                printf("\n");
                preorder(root);
                printf("\n");
            }
        }
        return 0;
    }


Measured memory_bytes: 26620
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
ll c[600005]={0},tree[1200005]={0};
ll query(ll ql,ll qr,ll s,ll e,ll in){
	if(ql>e || qr<s ||s>e)return -1;
	if(ql<=s && qr>=e){
		return tree[in];
	}

	int mid=(s+e)/2;
	//cout<<"Okay";
	return max(query(ql,qr,s,mid,2*in+1),query(ql,qr,mid+1,e,2*in+2));
}
void update(ll s,ll e,ll in,ll key,ll up){
	if(s>e)return;
	if(s==e && s==key){
		tree[in]=up;
		return;
	}
	else if(s==e)return;
	ll mid=(s+e)/2;

    if(mid>=key)update(s,mid,2*in+1,key,up);
	else update(mid+1,e,2*in+2,key,up);
	tree[in]=max(tree[2*in+1],tree[2*in+2]);
}
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	ll ans=1;
	for(int i=0;i<n;i++){
		ll curr=query(max(0ll,a[i]-k),min(300000ll,a[i]+k),0,300000,0);
		//cout<<curr<<endl;
		ans=max(ans,curr+1);
		update(0,300000,0,a[i],curr+1);
	}
	cout<<ans;

}


Measured memory_bytes: 14172
#include<iostream>
#include<string>
#include<set>

int main(){

  int N;
  std::string S;
  std::cin >> N >> S;

  int maxCnt = 0;
  std::set<char> st;
  for (int i=1;i<N;i++) {
    //部分取得
    std::string Y = S.substr(i,N-i);
    //std::cout << Y << '\n';
    int cnt = 0;
    st.clear();
    for (int j=1;j<=i;j++) {
      if (st.find(S.at(j-1))==st.end()) {
        //std::cout << "newChar" << '\n';
        st.insert(S.at(j-1));
        if ( Y.find(S.at(j-1))!=std::string::npos) cnt++;
      }
    }
    maxCnt = std::max(maxCnt,cnt);
  }

  std::cout << maxCnt  << '\n';

  return 0;
}


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

int main(void){
    int n;
    cin >> n;
    for(int i = 1;i <= 10;i++){
        if(i*1000-n >= 0){
            cout << i*1000-n << endl;
            break;
        }
    }
    
    
}

Measured memory_bytes: 3632
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int k = s.length();
	long long res = 0;
	char* e;
	long long num;
	long long count1,count2;

	for(int i=1; i <= k; i++) {
		for(int j=0; j <= k-i; j++) {
			num = strtol(s.substr(j,i).c_str(), &e, 10);
			count1 = 1;
			if (j > 0){
				count1 = pow(2,j-1);
			}
			count2 = 1;
			if (k-j-i > 0){
				count2 = pow(2,k-j-i-1);
			}
			res += num * count1 * count2;
		}
	}
	cout << res << endl;

	return 0;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second

int cnt=0;
vector<int> adj[200001];
int vis[200001]={0};
int n,m,u,v;

void dfs(int v){
	vis[v]=1;
	++cnt;
	for(int i=0;i<adj[v].size();i++){
		if(vis[adj[v][i]])continue;
		else
		dfs(adj[v][i]);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n>>m;
    
    for(int i=0;i<m;i++){
    	cin>>u>>v;
    	--u,--v;
    	adj[u].push_back(v);
    	adj[v].push_back(u);
	}
    
	int ans=1;
	for(int i=0;i<n;i++){
		if(vis[i])continue;
		cnt=0;
		dfs(i);
		ans=max(ans,cnt);
	}
	cout<<ans;	
	return 0;
}

Measured memory_bytes: 21552
#include <iostream>
#include <string>
#define ll long long

using namespace std;
int main(int argc, const char * argv[]) {
    ll N;
    string A,B,C;
    cin>>N>>A>>B>>C;
    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        if (A[i] == B[i] && A[i] == C[i]) ans += 0;
        else if (A[i] == B[i] && A[i] != C[i]) ans += 1;
        else if (B[i] == C[i] && B[i] != A[i]) ans += 1;
        else if (C[i] == A[i] && C[i] != B[i]) ans += 1;
        else if (A[i] != B[i] && A[i] != C[i] && B[i] != C[i]) ans += 2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (int i = 0; i < n; ++i) cin >> a[i];
  int res = 0;
  for (int x = 1; x <= 100; ++x) {
    V<bool> b(n);
    for (int i = 0; i < n; ++i) {
      b[i] = a[i] >= x;
    }
    int curr = 0;
    for (int i = 0; i < n; ++i) if (b[i] == true) {
      curr += i == 0 or b[i - 1] == false;
    }
    res += curr;
  }
  cout << res << '\n';
}

Measured memory_bytes: 384
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	for(int i=0;i<a;i++)b[i]--;
	int ret=0;
	for(int i=0;i<a;i++){
		if(b[b[i]]==i)ret++;
	}
	printf("%d\n",ret/2);
}

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

int l, k = -1;
vector<int> v;

int main()
{
	cin >> l;

	for (int i = 0; i < l; i++) {
		int c;
		cin >> c;

		if (v.empty()) {
			if (c > 0)
				v.push_back(c);
			else {
				if (k < 0)
					k = i + 1;
			}
		}
		else if (c > 0 && find(v.begin(), v.end(), c) == v.end())
			v.push_back(c);
		else if (c < 0 && v.back() == -c)
			v.pop_back();
		else {
			if (k < 0)
				k = i + 1;
		}
	}

	if (k < 0)
		cout << "OK" << endl;
	else
		cout << k << endl;

	return 0;
}


Measured memory_bytes: 3164
n=int(input())
a=[]
b=[]
ret = 0
for i in range(n):
  s,t=map(int,input().split())
  a+=[s]
  b+=[t]
for i in range(n):
  ret+=(b[-1-i]-(ret+a[-1-i])%b[-1-i])%b[-1-i]
print(ret)

Measured memory_bytes: 11052
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

const int K = 26;

struct Vertex 
{
    int next[K];
    bool leaf = false;
    ll pas=0;
    int num[K];
    Vertex() {
        fill(begin(next), end(next), -1);
        for(int i=0;i<K;i++)
        {
            num[i]=0;
            next[i]=-1;
        }
    }
};

ve<Vertex> tri(1);
 
void add_string(string const& s) 
{
    ll v = 0;
    tri[0].pas++;
    for (char ch : s) 
    {
        ll c = ch - 'a';
        if (tri[v].next[c] == -1) 
        {
            tri[v].next[c] = tri.size();
            tri.emplace_back();
        }
        v = tri[v].next[c];
        tri[v].pas++;
    }
    tri[v].leaf = true;
}

void dfs(ll v)
{
    for(int i=0;i<K;i++)
        if(tri[v].next[i]!=-1)
            dfs(tri[v].next[i]);
    for(int i=0;i<K;i++)
    {
        for(int j=0;j<K;j++)
        {
            if(j!=i)
            {
                if(tri[v].next[j]!=-1)
                    tri[v].num[i]+=tri[tri[v].next[j]].num[i];
            }
            else
                if(tri[v].next[j]!=-1)
                    tri[v].num[i]+=tri[tri[v].next[j]].pas;
        }
    }
}

ll run(string &s)
{
    ll v=0,x=0;
    for(int i=0;i<s.length()-1;i++)
    {
        ll ch=s[i]-'a';
        v=tri[v].next[ch];
    }
    return max(0ll,tri[v].num[s[s.length()-1]-'a']-1ll);
}

int main() 
{
    FAST;
    ll n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        reverse(s[i].begin(),s[i].end());
        add_string(s[i]);
    }
    dfs(0);
    ll ans=0;
    for(int i=0;i<n;i++)
        ans+=run(s[i]);
    cout<<ans;
    subt;
    return 0;
}

Measured memory_bytes: 251004
#include <stdio.h>

#define N 100

int min(int a , int b)
{
	if(a < b) return a;
	else return b;
}

int main()
{
	int n , p[N+1] , m[N+1][N+1];
	scanf("%d",&n);
	for( int i = 1; i <= n; i++)
	{
		scanf("%d %d",&p[i-1],&p[i]);
	}
		for(int i = 1; i <= n; i++) m[i][i] = 0;
		for(int l = 2; l <= n; l++)
		{
			for(int i = 1; i <= n - l + 1; i++)
			{
				int j = i + l -1;
				m[i][j] = ( 1 << 21);
				for(int k = i; k <= j -1 ; k++)
				{
					m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
				}
			}
		}
		printf("%d\n",m[1][n]);
		return 0;
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll a,b;
int main(){
	cin>>a>>b;
	if(abs(a-b)>1)cout<<"Alice"<<endl;
	else cout<<"Brown"<<endl;
	return 0;
}

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

// #include <atcoder/all>

// #LIB#

using namespace std;
// using namespace atcoder;
using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#ifdef ONLINE_JUDGE
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');
#endif

int main() {
  ll n;
  cin >> n;
  vector<ll> spf(n + 1);
  for (ll i = 2; i <= n; ++i) {
    if (spf[i] <= 0) {
      spf[i] = i;
      for (ll j = i * 2; j <= n; j += i) {
        if (spf[j] <= 0) spf[j] = i;
      }
    }
  }
  ll ans = 0;
  repr(c, 1, n) {
    ll x = n - c;
    map<ll, ll> ps;
    while (x >= 2) {
      ++ps[spf[x]];
      x /= spf[x];
    }
    ll cc = 1;
    itr(p, ps) cc *= p.second + 1;
    ans += cc;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11096
s = []
ans = 0
count = 1

n = int(input())
for i in range(n):
	s_i = sorted(input())
	s.append("".join(s_i))
s.sort()

for i in range(n-1):
	if s[i] == s[i+1]:
		count += 1
	else:
		ans += count * (count - 1) // 2
		count = 1
ans += count * (count - 1) // 2

print(ans)

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

int main() {
  int n, d;
  cin>>n>>d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i,n) {
    rep(j,d) cin >> x[i][j];
  }
  int ans = 0;
  rep(i,n)rep(j,i) { // j < i
    int sq = 0;
    rep(k,d) {
      int s = x[i][k]-x[j][k];
      sq += s*s;
    }
    int s = sqrt(sq)+0.5;
    if (s*s == sq) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
def robin(process, q):
    if int(process[0][1]) - q > 0:
        process[0][1] = int(process[0][1]) - q
        process.append([process[0][0],process[0][1]])
        process.pop(0)
        return process, q
    else:
        q = int(process[0][1])
        process.pop(0)
        return process, q


n, q = input().split()
n, q = int(n), int(q)
process = []
for i in range(n):
    process.append([i for i in input().split()])


time = 0
while len(process) != 0:
    length = len(process)
    name = process[0][0]
    process, process_time = robin(process, q)
    time += process_time
    if length > len(process):
        print(name,time)

Measured memory_bytes: 16564
def resolve():
	n = int(input())
	v = []
	for _ in range(n):
		v.append(list(map(int, input().split())))
	t, a = 1, 1
	for i in range(n):
		tv, av = v[i]
		c = max(t//tv + (t%tv!=0), a//av + (a%av!=0))
		t, a = c*tv, c*av
	print(t+a)
resolve()

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ( a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
} 

Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);

		try {
			int x_cube = Integer.parseInt(br.readLine());
			System.out.println((int)Math.pow(x_cube, 3));
		} catch (NumberFormatException | IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 24164
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
    LL n, ans = 0;
    vector<LL> v;
    scanf("%lld", &n);
    for(LL i=1;i*i<=n;i++){
        if(n%i == 0){
            if(i-1 > 0) v.push_back(i-1);
            if(n/i != i){
                if(n/i-1 > 0) v.push_back(n/i-1);
            }
        }
    }
    for(int i=0;i<v.size();i++){
        if(n/v[i] == n%v[i]) ans+=v[i];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 384
N = int(input())
a = list(map(int, input().split()))
x1, x2, x3, x4, x5, x6, x7, x8, x9 = 0, 0, 0, 0, 0, 0, 0, 0, 0

for i in a:
    if i < 400:
        x1 = 1
    elif i < 800:
        x2 = 1
    elif i < 1200:
        x3 = 1
    elif i < 1600:
        x4 = 1
    elif i < 2000:
        x5 = 1
    elif i < 2400:
        x6 = 1
    elif i < 2800:
        x7 = 1
    elif i < 3200:
        x8 = 1
    else:
        x9 += 1
mini = max(x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8, 1)
maxi = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9
print(mini, maxi)


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

int N,W,H,S,T,x,y;
int field[100][100];

int find_max(){

  int max=0;
  
  rep(k,H-T+1){
    rep(l,W-S+1){
      int cnt=0;
      rep(i,T){
	rep(j,S){
	  cnt+=field[i+k][j+l];
	}
      } 
      if(max < cnt)max=cnt;
    }
  }

  return max;
}
int main(){

 
  
  while(1){
    
    cin >>N;
    if(N == 0)break;

    cin >>W>>H;
    
    rep(i,H){
      rep(j,W){
	field[i][j]=0;
      }
    }
    
    rep(i,N){
      cin >>x>>y;
      field[y-1][x-1]=1;
    }

    cin >>S>>T;
    
    cout <<find_max()<<endl;
  }
    
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s[0] == '9' || s[1] == '9')
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn prime_check(n: usize) -> bool {
    let mut j = 2;
    while j * j <= n {
        if n % j == 0 {
            return false;
        }
        j += 1;
    }
    true
}

fn main() {
    let n: usize = read();
    let mut vec: Vec<usize> = vec![0; 110];
    let mut prime: Vec<usize> = Vec::new();
    for i in 2..n + 1 {
        if prime_check(i) {
            prime.push(i);
            vec[i] += 1;
        } else {
            for j in &prime {
                let mut po = i;
                while po % *j == 0 {
                    vec[*j] += 1;
                    po /= *j;
                }
            }
        }
    }
    let mut value: Vec<i64> = vec![0; 110];
    for i in 2..n + 1 {
        value[vec[i]] += 1;
    }
    for i in 1..n {
        value[n - i - 1] += value[n - i];
    }
    let mut ans = 0;
    ans += value[4] * (value[4] - 1) / 2 * (value[2] - 2);
    ans += value[24] * (value[2] - 1);
    ans += value[74];
    ans += value[14] * (value[4] - 1);
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

char S[2005][2005];
int F[2005][2005], H[2005][2005], V[2005][2005];

template<typename T>
int get_rectangle(T arr, int r1, int c1, int r2, int c2) {
  return arr[r2][c2] - arr[r1-1][c2] - arr[r2][c1-1] + arr[r1-1][c1-1];
}

int main() {
  int N, M, Q;
  scanf("%d%d%d", &N, &M, &Q);
  FOR(i,1,N+1)scanf("%s", S[i]+1);
  FOR(i,1,N+1)FOR(j,1,M+1) S[i][j] -= '0';

  ++N, ++M;
  REP(i,N)REP(j,M) {
    F[i][j] = S[i][j];
    H[i][j] = S[i][j] && S[i+1][j];
    V[i][j] = S[i][j] && S[i][j+1];
  }

  REP(i,N) FOR(j,1,M){
    F[i][j] += F[i][j-1];
    H[i][j] += H[i][j-1];
    V[i][j] += V[i][j-1];
  }

  REP(j,M)FOR(i,1,N+1) {
    F[i][j] += F[i-1][j];
    H[i][j] += H[i-1][j];
    V[i][j] += V[i-1][j];
  }

  REP(q,Q) {
    int r1, c1,r2, c2;
    scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
    int nodes = get_rectangle(F, r1, c1, r2, c2);
    int edges = get_rectangle(H, r1, c1, r2 - 1, c2) + get_rectangle(V, r1, c1, r2, c2 - 1);
    int result = nodes - edges;
    printf("%d\n", result);
  }



}


Measured memory_bytes: 52864
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int d[110][110];
int dist[110][110];
void warshall_floyd(int n) {
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
}
int solve(int n) {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (d[i][j] == mod) continue;	
			if (d[i][j] != dist[i][j]) ans++;
		}
	}
	return ans / 2;
}
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i != j) {
				d[i][j] = mod;
				dist[i][j] = mod;
			}
		}
	}
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c;
		d[b][a] = c;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	warshall_floyd(N);
	cout << solve(N) << endl;
}


Measured memory_bytes: 3776
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, K, i, j, k, l, ans, cnt = 0;

int main(){
    int X, Y, reg, ani;
    cin >> X >> Y;

    REP(i, X + 1){
        if(i == 0){
            ani = 0;// 動物の候補
            reg = Y;// 残りの足の数
        }else{
            ani = i;// 動物の候補
            reg = Y - (i * 2);// 残りの足の数
        }

        if(reg < 0){//残りの足が既に0未満 この場合、残りの候補はみる必要なし 
            cout << "No" << endl;
            return 0;
        }

        if(reg % 4 != 0){
            continue;
        } 

        ani += reg / 4;

        // ここで正解とあっているかどうか
        if(X == ani){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000000
using namespace std;
using pii=pair<int,int>;





vector<int64_t> dist;
vector<int> pre;
vector<bool> exist_negative_cycle;

void Bellman_Ford(vector<vector<pii>> adj_list,int start){
    /*trueなら負の閉路が存在*/
    
    int n=adj_list.size();
    /*初期化*/
    dist=vector<int64_t>(n,INF);
    pre=vector<int>(n);/*最短経路におけるひとつ前の頂点*/
    exist_negative_cycle=vector<bool>(n,false);/*nまでの経路に負の閉路があるかどうか*/
    dist.at(start)=0;
    REP(i,n){
        REP(u,n){
            for(auto vpair : adj_list.at(u)){
                int weight_u_to_v,v;
                tie(v,weight_u_to_v)=vpair;
                if(dist.at(v)>dist.at(u)+weight_u_to_v){
                  dist.at(v)=dist.at(u)+weight_u_to_v;
                  pre.at(v)=u;
                  if (i == n - 1){
                    exist_negative_cycle.at(v)=true;
                  }; // n回目にも更新があるなら負の閉路が存在
                }

            }
        }
    }


  
}
int main() {
  int V,E;
  cin>>V>>E;
  vector<vector<pair<int,int>>> adj_list(V);
  
  REP(i,E){
    int s,t,d;
    cin>>s>>t>>d;
    s--;
    t--;/*添字の調整*/
    adj_list.at(s).push_back(make_pair(t,-d));

  }
  

  Bellman_Ford(adj_list,0);
  
  if(exist_negative_cycle.at(V-1)){
    cout<<"inf"<<endl;
    return 0;
  }
  cout<<-dist.at(V-1)<<endl;


  return 0;
}

Measured memory_bytes: 3264
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    string s,t;
    cin >> s >> t;
    int ans = 0;
    rep(i,s.size()) {
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3916
read n k

for i in `seq "$k"`
do
	read "d_$i"
	read -a "a${i}s"
done

result=(`seq "$n"`)

for i in `seq "$k"`
do
	temp=a${i}s[@]

	# ${result[@]} \= ${!temp}
	for j in "${!temp}"
	do
		for k in "${!result[@]}"
		do
			if [[ "${result[k]}" = "$j" ]]; then
				unset result[k]
			fi
		done
	done
done

echo "${#result[@]}"

Measured memory_bytes: 4672
package main

import (
	"fmt"
)

func main() {
	var A, B string
	fmt.Scan(&A)
	fmt.Scan(&B)
	if A == B {
		fmt.Println("EQUAL")
	} else if A > B && len(A) >= len(B) {
		fmt.Println("GREATER")
	} else {
		fmt.Println("LESS")
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt() % 10;

        if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
            System.out.println("hon");
        } else if (n == 0 || n == 1 || n == 6 || n == 8) {
            System.out.println("pon");
        } else {
            System.out.println("bon");
        }
    }
}


Measured memory_bytes: 35504
#include <iostream>

using namespace std;

int main()
{
    int money=1e5;
    int n;
    while(cin>>n)
    {
        for(int x=0;x<n;x++)
        {
            money*=1.05;
            if(money%1000!=0)
                money=(int)(money/1000*1000)+1000;
        }
        cout<<money<<endl;
    }
    return 0;
}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  if (a >= k) {
    cout << k << endl;
  }
  else if ((a + b) >= k) {
    cout << a << endl;
  }
  else {
    cout << (2 * a) + b - k << endl;
  }
}


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

int main() {
    int n,x;
    cin>>n>>x;
    int a;
    cin>>a;
    int g=abs(x-a);
    for (int i=1;i<n;i++) {
        cin>>a;
        g=__gcd(g,abs(x-a));
    }
    cout<<g<<endl;
    return 0;
}

Measured memory_bytes: 256