akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main () {

 int a,b,c,num;

 cin >> a >> b >> c;

 if (a > b) { 
  num = a;
  a = b;
  b = num;
 }

 if (b > c) { 
  num = b;
  b = c;
  c = num;
 }

 if (a > b) { 
  num = a;
  a = b;
  b = num;
 }

 cout << a <<" "<< b <<" "<< c <<endl;

 return 0;

}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,p,l,m=0;
	
	cin>>n;

	p=n/pow(10,1);
	l=p/pow(10,1);

	int v[3]={l,p-10*l,n-10*p};

	for (int i=0;i<3;i++){
		if(v[i]==1){
			m++;
		}
	}

	cout<<m<<"\n";
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main(){
	ll x,a;
	cin>>x>>a;
	if(x<a){
		cout<<0<<endl;
	} 
	else{
		cout<<10<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
a,b,k = gets.split.map(&:to_i)

k -= 1
if a+k > b || a+k >= b-k
  (a..b).each do |i|
    puts i
  end
else
  (a..a+k).each do |i|
    puts i
  end
  (b-k..b).each do |j|
    puts j
  end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll n, T;
    cin >> n >> T;

    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    
    ll end = 0;
    ll sum = 0;
    rep(i, n) {
        sum += T;
        sum -= max(0LL, end - t[i]);
        end = t[i] + T;
    }

    put(sum);
}
signed main(){ Main();return 0;}

Measured memory_bytes: 4856
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	p := nextInt()
	p += a * 3
	fmt.Println(p / 2)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int x;
  cin>>x;
  vector<int>a(8);
  a.at(0)=600;
  a.at(1)=800;
  a.at(2)=1000;
  a.at(3)=1200;
  a.at(4)=1400;
  a.at(5)=1600;
  a.at(6)=1800;
  a.at(7)=2000;
  //a.at()=;
  rep(i,8){
    if(x<a.at(i)){
      cout<<8-i<<endl;
      return 0;
    }
    
  }
  
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


signed main(){
    FASTER;
    int n,k;
    cin>>n>>k;
    vi v(n);
    for(int &i:v){
        cin>>i;
        i=(i-1+k)%k;
    }
    for(int i=1;i<n;i++)v[i]=(v[i]+v[i-1])%k;
    
    int ans=0;
    map<int,int> mp;
    mp[0]=1;
    for(int i=0;i<min(k-1,n);i++){
        ans+=mp[v[i]];
        mp[v[i]]++;
    }
    if(k<n){
        mp[0]--;
        ans+=mp[v[k-1]];
        mp[v[k-1]]++;
        for(int i=k;i<n;i++){
            mp[v[i-k]]--;
            ans+=mp[v[i]];
            mp[v[i]]++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 17160
#include <stdio.h>
int main(){
  int K,N,i,j,tmp,ans,max,d;
  int A[1000000];
  scanf("%d %d",&K,&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  
  max=A[0]+K-A[N-1];
  for(i=0;i<N;i++){
    d=A[i+1]-A[i];
    if(d>max) max=d;
  }
  
  ans=K-max;
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 2944
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			int n = sc.nextInt();	
			int k = sc.nextInt();	
			int m = sc.nextInt()-1;
			if(n+k+m<=0)break;
			List<Integer>list= new LinkedList<Integer>();
			for (int i = 0; i < n; i++) {
				list.add(i);
			}
			int cur = m;
			list.remove(cur);
			cur--;

			for (int j = 0; j < n-2; j++) {
//				for (int i = 0; i < k; i++) {
//					cur = (cur+1)%list.size();
//				}
				cur = (list.size()+cur+k%list.size())%list.size();
				list.remove(cur);
				cur--;
			}
			System.out.println(list.get(0)+1);
		}

	}

}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


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

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

    sort(all(l),greater<int>());
    int ans = 0;
    rep(i,K) ans += l[i];
    cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
A=[int(i) for i in input().split()]

flag=1
count=0

while flag==1:
  flag=0
  for i in range(n-1,0,-1):
    if A[i-1] > A[i]:
      v =A[i]
      A[i] = A[i-1]
      A[i-1] =v
      flag=1
      count+=1
print(*A, sep=' ')
print(count)


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

using namespace std;
int N, i, S, v[4];
int main()
{
    for(i = 1; i <= 3;  i++) scanf("%d", &v[i]);
    sort(v + 1, v + 1 + 3);
    for(i = 2; i <= 3; i++) S += v[i] - v[i - 1];
    printf("%d", S);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int N=80069;
template<typename TP>
inline void read(TP &kk)
{
	TP ret=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
	kk=ret*f;
}
int n,v[N];
struct shino
{
	int w,id;
	shino():w(0),id(0){}
	shino(int w,int id):w(w),id(id){}
	bool operator < (const shino &a)const{return w<a.w;}
}fs[N];
int dep[N],bl[N],low[N],bi,ct,da;

vector<int> to[N];
int id[N];
void build(int px,int pl,int pr)
{
	id[px]=++ct;
	if(px>1) to[id[px>>1]].push_back(ct);
	if(pl==pr){to[id[px]].push_back(fs[pl].id<=n?fs[pl].id+n:fs[pl].id-n);return;}
	int pm=(pl+pr)>>1;
	build(px<<1,pl,pm);
	build(px<<1|1,pm+1,pr);
}
void add(int px,int pl,int pr,int l,int r,int x)
{
	if(l>r) return;
	if(l<=pl&&r>=pr){to[x].push_back(id[px]);return;}
	int pm=(pl+pr)>>1;
	if(l<=pm) add(px<<1,pl,pm,l,r,x);
	if(r>pm) add(px<<1|1,pm+1,pr,l,r,x);
}

shino find(int i,int v)
{
	int L=n*2+1,R=0,l1=1,r1=i,l2=i,r2=n<<1;
	while(l1<=r1)
	{
		int m1=(l1+r1)>>1;
		if(fs[i].w-fs[m1].w<v) L=m1,r1=m1-1;
		else l1=m1+1;
	}
	while(l2<=r2)
	{
		int m2=(l2+r2)>>1;
		if(fs[m2].w-fs[i].w<v) R=m2,l2=m2+1;
		else r2=m2-1;
	}
	return shino(L,R);
}
int st[N],tp;
void tj(int x)
{
	dep[x]=low[x]=++da;
	st[++tp]=x;
	for(int j=0,t;j<to[x].size();j++)
	{
		t=to[x][j];
		if(!dep[t])
		{
			tj(t);
			low[x]=min(low[x],low[t]);
		}else if(!bl[t])low[x]=min(low[x],dep[t]);
	}
	if(low[x]==dep[x])
	{
		bi++;
		int t;
		while(t!=x)
		{
			t=st[tp--];
			bl[t]=bi;
		}
	}
}

bool check(int km)
{
	memset(dep,0,sizeof(dep)),memset(low,0,sizeof(low));memset(bl,0,sizeof(bl));
	for(int i=1;i<=(80000);i++) to[i].clear();
	bi=0,ct=n<<1,da=0;
	build(1,1,n<<1);
	for(int i=1;i<=n*2;i++){shino stp=find(i,km);add(1,1,n<<1,stp.w,i-1,fs[i].id),add(1,1,n<<1,i+1,stp.id,fs[i].id);}
	for(int i=1;i<=n*2;i++) if(!dep[i]) tj(i);
	for(int i=1;i<=n;i++) if(bl[i]==bl[n+i]) return 0;
	return 1;
}

signed main()
{
	read(n);
	for(int i=1;i<=n;i++) read(v[i]),read(v[n+i]),fs[i]=shino(v[i],i),fs[n+i]=shino(v[n+i],n+i);
	sort(fs+1,fs+1+n*2);
	int el=0,er=1000000000,em,prt;
	while(el<=er)
	{
		em=(el+er)>>1;
//		printf("%d\n",em);
		if(check(em)) prt=em,el=em+1;
		else er=em-1;
	}
	printf("%d\n",prt);
	return 0;
}

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

int main() 
{
    int n, m;
    cin >> n >> m;
    int V[m];
    rep(i,m) V[i] = 0;
    rep(i,n) {
        int k;
        cin >> k;
        rep(j,k) {
            int a;
            cin >> a;
            a--;
            V[a]++;
        }
    }

    int ans = 0;
    rep(i,m) {
        if (V[i] == n) ans++;
    }

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    int n = Integer.parseInt(br.readLine());
    String s = br.readLine();
    String[] sa = s.split(" ");
    List<Integer> na =  Arrays.stream(sa).map(Integer::valueOf).collect(Collectors.toList());
    na.sort(Comparator.reverseOrder());
    int a = 0;
    int b = 0;
    for (int i = 0; i < n; i++) {
      if (i % 2 == 0) {
        a += na.get(i);
      } else {
        b += na.get(i);
      }
    }
    out.println(a - b);
    out.close();
  }
}

Measured memory_bytes: 34260
n = int(input())
h = list(map(int, input().split()))
gap = [0]
mt = []
va = []
i = 0
while i+1 <= len(h)-1:
    if h[i+1]-h[i] != 0:
        gap.append(h[i+1]-h[i])
        i += 1
    else:
        h.pop(i+1)
for i in range(len(h)-1):    
    if gap[i] >= 0: 
        if gap[i+1] < 0:
            mt.append(h[i])
    else:
        if gap[i+1] > 0:
            va.append(h[i])
if gap[-1] > 0 :
    mt.append(h[-1])
if mt == []:
    mt.append(h[0])
ans = 0
for x in mt:
    ans += x
for x in va:
    ans -= x
print(ans)

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

bool isEvenString(string t){
  int n=t.length();
  if(n%2!=0) return false;
  if(t.substr(0,n/2)==t.substr(n/2)) return true;
  return false;
}

int main(){
  string s; cin >> s;
  s = s.substr(0,s.length()-1);
  while(!isEvenString(s)) s = s.substr(0,s.length()-1);
  cout << s.length() << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] rank = new int[n + 1];
        int[] parent = new int[n + 1];
        int[][] edge = new int[m][2];
        for(int i = 0; i <= n; i++){
            parent[i] = i;
            rank[i] = 1;
        }
        for(int i = 0; i < m; i++){
            edge[i][0] = sc.nextInt();
            edge[i][1] = sc.nextInt();
        }
        for(int[] e : edge){
            union(e[0], e[1], rank, parent);
        }
        int res = 0;
        for(int i = 1; i <= n; i++){
            //System.out.println(rank[i]);
            res = Math.max(res, rank[i]);
        }

        System.out.println(res);
    }
    public static void union(int a, int b, int[] rank, int[] parent){
        int A = find(a, parent);
        int B = find(b, parent);
        if(A == B)
            return;
        if(rank[A] < rank[B]){
            parent[A] = B;
            rank[B] += rank[A];
        }
        else{
            parent[B] = A;
            rank[A] += rank[B];
        }
    }
    public static int find(int u, int[] parent){
        while(u != parent[u]){
            u = parent[u];
        }
        return u;
    }
}

Measured memory_bytes: 66408
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans=0;
    for(int i=2;i<n;i++){
        string tmp;
        tmp+=s[i-2];
        tmp+=s[i-1];
        tmp+=s[i];
        if(tmp=="ABC"){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

// 方向ベクトル
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> board(h);
    rep(i, h) {
        cin >> board[i];
    }

    vector<vector<int>> matrix(h, vector<int>(w, -1));  // 数字を書き込むマス。-1で初期化
    queue<pair<int, int>> next;  // 次に探索するマス目を入れるqueue

    int cnt = 0;  // 黒マスの個数
    rep(i, h) {
        rep(j, w) {
            if(board[i][j] == '#') {
                matrix[i][j] = 0;  // 黒マスを0にする
                cnt++;
            }
        }
    }

    matrix[0][0] = 1;
    next.push(make_pair(0, 0));

    while(!next.empty()) {  // nextが空になるまで探索

        int x = next.front().first;
        int y = next.front().second;
        
        // 4方向調べる
        rep(i, 4) {

            int nx = x + dx[i];
            int ny = y + dy[i];

            // 盤外または探索済みのところはダメ
            if(nx < 0 || h <= nx || ny < 0 || w <= ny || matrix[nx][ny] >= 0) {   
                continue;
            }
            
            matrix[nx][ny] = matrix[x][y] + 1;  // 隣接マスに1足す
            next.push(make_pair(nx, ny));  // 隣接マスをnextに入れる
        }

        next.pop();  // nextからいま探索したマスを削除
    }

    if(matrix[h-1][w-1] == -1) {
        cout << -1 << endl;
        return 0;
    }

    int ans = h*w - (cnt + matrix[h-1][w-1]); 

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

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    long[] a=new long[n];
    for(int i=0;i<n;++i){
      a[i]=sc.nextInt();
    }
    if(k>=n){
      System.out.println("0");
    }
    else{
      Arrays.sort(a);
      int temp=n-k-1;
      long ans=0;
      for(int i=0;i<=temp;++i){
      	ans+=a[i];
      }
      System.out.println(ans);
    }
  }
}


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

using namespace std;

typedef long long ll;

const int N = 3000 + 7;
int n;
int m;
int k;
ll a[N][N];
ll dp[N][N][4];
ll tot[N][N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int r, c, x;
    cin >> r >> c >> x;
    a[r][c] = x;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      for (int k = 1; k <= 3; k++) {
        dp[i][j][k] = max(dp[i][j - 1][k], tot[i - 1][j] + a[i][j]);
        dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k - 1] + a[i][j]);
      }
      for (int k = 1; k <= 3; k++) {
        tot[i][j] = max(tot[i][j], dp[i][j][k]);
      }
    }
  }
  cout << tot[n][m] << "\n";
  return 0;
}


Measured memory_bytes: 426220
#include<iostream>
#include<string>

int main(){
    int a, b;
    scanf("%d %d%*c", &a, &b);
    std::string a_str = "";
    std::string b_str = "";
    for(int i = 0; i < b; i++){
        a_str += std::to_string(a);
    }
    for(int j = 0; j < a; j++){
        b_str += std::to_string(b);
    }
    if(a_str.compare(b_str) < 0){
        std::cout << a_str << std::endl;
    }else{
        std::cout << b_str << std::endl;
    }
    return 0;
}

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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,b,j;
	cin >> n;
	ll a[n+2],h[n+2]={0};
	for(i=0;i<n;i++)
	{
		cin >> a[i];
		h[a[i]]++;
	}
	k=0;
	for(i=1;i<=n;i++)
	{
		k+=(((h[i]-1)*h[i])/2);
		// cout << k << " for i=" << i << "\n";
		// k/=2;
	}
	for(i=0;i<n;i++)
	{
		b=h[a[i]]-1;
		cout << k-b << endl;
	}
	return 0;
}

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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n,x;
	n=3;
	vector<long long int> v;
	while(n--){
		cin>>x;
		v.push_back(x);
	}
	sort(v.begin(),v.end());
	cout<<abs(v[1]-v[0])+abs(v[2]-v[1]);
	return 0;
}

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

int dsum(int n){
  int ret=0;
  while(n>0){
    ret+=n%10;
    n/=10;
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  int ret = 1000;
  for(int i=1; i<=n/2; i++){
    ret = min(ret, dsum(i)+dsum(n-i));
  }
  cout << ret;
  return 0;
}

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

int main() {
    ll n, p, even = 0, odd = 0, ans;
    cin >> n >> p;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (a % 2 == 0) even++;
        if (a % 2 == 1) odd++;
    }

    if (odd == 0) {
        if (p == 0) ans = pow(2, n);
        else ans = 0;
    } else {
        ans = pow(2, n - 1);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,x,y,z;
	int abc;
	int i,j;
	int flg[3][100];
	int cnt;
	
	cin>>n;
	
	for(i=0;i<3;i++){
		for(j=0;j<n;j++) flg[i][j]=0;
	}
	
	cin>>x;
	for(i=0;i<x;i++){
		cin>>abc;
		flg[0][abc-1]=1;
	}
	
	cin>>y;
	for(i=0;i<y;i++){
		cin>>abc;
		flg[1][abc-1]=1;
	}
	
	cin>>z;
	for(i=0;i<z;i++){
		cin>>abc;
		flg[2][abc-1]=1;
	}
	
	cnt=0;
	for(i=0;i<n;i++){
		if(flg[0][i]==0&&flg[2][i]==1) cnt++;
		else if(flg[1][i]==1&&flg[2][i]==1) cnt++;
	}
	
	cout<<cnt<<endl;
	
	return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	char a[1000];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int dp[1000][2][2][2];
	for (int k = 0; k < n; k++)
	{
		for (int j = 0; j < 2; j++)
		{
			for (int o = 0; o < 2; o++)
			{
				for (int i = 0; i < 2; i++)
				{
					dp[k][j][o][i] = 0;
				}
			}
		}
	}
	for (int o = 0; o < 2; o++)
	{
		if (a[0] != 'O' || o != 0)
		{
			for (int i = 0; i < 2; i++)
				{
					if (a[0] != 'I' || i != 0)
					{
						dp[0][1][o][i] = 1;
					}
				}
			}
	}
	for (int k = 1; k < n; k++)
	{
		for (int j = 0; j < 2; j++)
		{
			if (a[k] != 'J' || j != 0)
			{
				for (int o = 0; o < 2; o++)
				{
					if (a[k] != 'O' || o != 0)
					{
						for (int i = 0; i < 2; i++)
						{
							if (a[k] != 'I' || i != 0)
							{
								for (int jj = 0; jj < 2; jj++)
								{
									for (int oo = 0; oo < 2; oo++)
									{
										for (int ii = 0; ii < 2; ii++)
										{
											if (((i * ii) + (j * jj) + (o * oo)) != 0)
											{
												dp[k][j][o][i] += dp[k - 1][jj][oo][ii];
												dp[k][j][o][i] = dp[k][j][o][i] % 10007;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int j = 0; j < 2; j++)
	{
		for (int o = 0; o < 2; o++)
		{
			for (int i = 0; i < 2; i++)
			{
				ans += dp[n - 1][j][o][i];
				ans = ans % 10007;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;

int main(){

    int n, m; cin >> n >> m;

    vector<int> x;
    for(int i=0; i<m; i++){
        int temp; cin >> temp;
        x.push_back(temp);
    }
    sort(x.begin(), x.end());

    vector<int> dx;
    for(int i=0; i<m-1; i++){
        dx.push_back(x[i+1] - x[i]);
    }
    sort(dx.begin(), dx.end());

    int ans = 0;
    for(int i=0; i<m-n; i++){
        ans += dx[i];
    }

    cout << ans;



    return 0;
}

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

using namespace std;

int main(){
	int N;
	cin >> N;
	
	vector<int> A(N + 1);
	vector<int> B(N);
	for (int i = 0; i < N + 1; ++i) {
		cin >> A.at(i);
	}
	for (int i = 0; i < N; ++i) {
		cin >> B.at(i);
	}
	
	long long count = 0;
	for (int i = 0; i < N; ++i) {
		if (A.at(i) >= B.at(i)) {
			A.at(i) -= B.at(i);
			count += B.at(i);
			B.at(i) = 0;
		} else {
			B.at(i) -= A.at(i);
			count += A.at(i);
			A.at(i) = 0;
		}
		
		if (A.at(i+1) >= B.at(i)) {
			A.at(i+1) -= B.at(i);
			count += B.at(i);
			B.at(i) = 0;
		} else {
			B.at(i) -= A.at(i+1);
			count += A.at(i+1);
			A.at(i+1) = 0;
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 1024
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
#define N 101010
void build(){

}
LL n , a[ N ];
void init(){
  n = getint();
  for( int i = 0 ; i < n ; i ++ )
    a[ i ] = getint();
}
void solve(){
  LL pre = 1 , ans = 0;
  for( int i = 0 ; i < n ; i ++ ){
    LL res = a[ i ] - 1;
    LL got = res / pre;
    if( got == 0 ){
      pre = max( pre , a[ i ] + 1 );
      continue;
    }
    ans += got;
    pre = max( pre , 2ll );
  }
  cout << ans << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

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

  bool ok = true;
  for (int i = 0; i < S.size(); i += 2) {
    ok &= S[i] == 'h' && S[i + 1] == 'i';
  }

  cout << (ok ? "Yes": "No") << endl;

  return 0;
}

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

#define pai 3.141592653

using namespace std;

int main(void)
{
	double a, b, C;
	double S, L, h;
	double c;

	cin >> a >> b >> C;

	h = b * sin(pai / 180 * C);
	c = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(pai / 180 * C));

	S = a * h / 2;
	L = a + b + c;

	printf("%f\n", S);
	printf("%f\n", L);
	printf("%f\n", h);

	return 0;
}

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

bool is_even(int* a, int n){
    for (int i=0; i<n; i++) {
        if (a[i] % 2 != 0) {
            return false;
        }
    }
    return true;
}

std::vector<int> A(110);

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

    int a_score = 0;
    int b_score = 0;
    bool a_turn = true;

    while(!A.empty()) {
        std::vector<int>::iterator maxItr = std::max_element(A.begin(), A.end());
        if (a_turn) {
            a_score += *maxItr;
            a_turn = false;
        } else {
            b_score += *maxItr;
            a_turn = true;
        }
        A.erase(maxItr);
    }
    cout << (a_score - b_score) << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int inf = 2147483646;
const double eps = 1e-8;
typedef long long LL;

int n,a[100005];
LL ans = 1;
int main() {
    cin >> n;
    int color[5];
    for (int i=1;i<=n;i++) cin >> a[i];
    for (int i=1;i<=n;i++) {
        LL cnt = 0; int id = 0;
        if (a[i] == color[1]) {cnt++; id=1;}
        if (a[i] == color[2]) {cnt++; id=2;}
        if (a[i] == color[3]) {cnt++; id=3;}
        if (id == 0) {
            cout<<'0'<<endl;
            return 0;
        }
        ans *= cnt;
        ans %= 1000000007;
        color[id]++;
    } 
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
import sys

def is_contained(a, area):
    rx1, ry1, rx2, ry2 = a
    for r in area:
        x1, y1, x2, y2 = r
        if x1 <= rx1 <= x2 and x1 <= rx2 <= x2 and \
           y1 <= ry1 <= y2 and y1 <= ry2 <= y2:
            return True
    return False

def add_area(a, area):
    if is_contained(a, area):
        return area
    xs, ys, xe, ye = a
    if xs >= xe or ys >= ye:
        return area
    ret = area
    if area == []:
        return [a]
    rr = []
    for r in area:
        rxs, rys, rxe, rye = r
        if xs < rxs < xe and ys < rys < ye and xe <= rxe and ye <= rye:
            rr = [[xs, ys, xe, rys], [xs, rys, rxs, ye]]
        elif xs < rxs < xe and ys < rye < ye and rys <= ys and xe <= rxe:
            rr = [[xs, ys, rxs, rye], [xs, rye, xe, ye]]
        elif xs < rxe < xe and ys < rys < ye and rxs <= xs and ye <= rye:
            rr = [[xs, ys, rxe, rys], [rxe, ys, xe, ye]]
        elif xs < rxe < xe and ys < rye < ye and rxs <= xs and rys <= ys:
            rr = [[xs, rye, rxe, ye], [rxe, ys, xe, ye]]
        elif xs < rxs and ys <= rys < ye and rxe < xe and ye <= rye:
            rr = [[xs, ys, xe, rys], [xs, rys, rxs, ye], [rxe, rys, xe, ye]]
        elif xs < rxs and ys < rye <= ye and rxe < xe and rys <= ys:
            rr = [[xs, rye, xe, ye], [xs, ys, rxs, rye], [rxe, ys, xe, rye]]
        elif xs <= rxs < xe and ys < rys and rye < ye and xe <= rxe:
            rr = [[xs, ys, rxs, ye], [rxs, ys, xe, rys], [rxs, rye, xe, ye]]
        elif xs < rxe <= xe and ys < rys and rye < ye and rxs <= xs:
            rr = [[rxe, ys, xe, ye], [xs, ys, rxe, rys], [xs, rye, rxe, ye]]
        elif rxs <= xs and xe <= rxe and ys < rys < ye and ye <= rye:
            rr = [[xs, ys, xe, rys]]
        elif rys <= ys and ye <= rye and xs < rxs < xe and xe <= rxe:
            rr = [[xs, ys, rxs, ye]]
        elif rxs <= xs and xe <= rxe and ys < rye < ye and rys <= ys:
            rr = [[xs, rye, xe, ye]]
        elif rys <= ys and ye <= rye and xs < rxe < xe and rxs <= xs:
            rr = [[rxe, ys, xe, ye]]
        elif xs < rxs < xe and xs < rxe < xe and ys < rys < ye and ys < rye < ye:
            rr = [[xs, ys, rxs, rye], [xs, rye, rxe, ye], [rxe, rys, xe, ye], [rxs, ys, xe, rys]]
        elif rxs <= xs and xe <= rxe and ys < rys and rye < ye:
            rr = [[xs, ys, xe, rys], [xs, rye, xe, ye]]
        elif rys <= ys and ye <= rye and xs < rxs and rxe < xe:
            rr = [[xs, ys, rxs, ye], [rxe, ys, xe, ye]]
        if rr != []:
            for q in rr:
                ret = add_area(q, ret)
            break
    if rr == []:
        ret.append(a)
    return ret

def calc_area(area):
    s = 0.0
    for r in area:
        s += (r[2]- r[0]) * (r[3] - r[1])
    return s

n = 0
c = 0
area = []
for line in sys.stdin:
    if n == 0:
        n = int(line)
        c += 1
        area = []
        if n == 0:
            break
    else:
        ant = list(map(float, line.strip().split()))
        r = [ant[0] - ant[2], ant[1] - ant[2], ant[0] + ant[2], ant[1] + ant[2]]
        area = add_area(r, area)
        n -= 1
        if n == 0:
            print("%d %.2f" % (c, calc_area(area)))


Measured memory_bytes: 5824
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int fallen = 0, L[MAXN], R[MAXN], ans[MAXN], K, n;
vector<int> adj[MAXN];

void dfs(int u, int p = -1) {
	for (int i=0; i<sz(adj[u]); i++) {
		int v = adj[u][i];
		if (v == p) continue;
		dfs(v, u);
		if (fallen) return;
		
		if (L[v] == -oo && R[v] == oo) continue;
		int lo = L[v] - 1;
		int hi = R[v] + 1;
//		cout << u << " " << v << " " << lo << " " << hi << endl;
		
		if (L[u] == -oo && R[u] == oo) {
			L[u] = lo; R[u] = hi;
		}
		else {
			if (((L[u] - lo) % 2 != (R[u] - hi) % 2)) {
//				cout << u << " " << v << " " << lo << " " << hi << endl;
				fallen = 1;
				return;
			}
			
			L[u] = max(L[u], lo);
			R[u] = min(R[u], hi);
			
			if (R[u] < L[u]) {
				fallen = 1;
				return;
			}
		}
	}
}

void findTree(int u, int p = -1) {
	if (!~p) {
		ans[u] = L[u];
	}
	else {
		int nxt = ans[p] + 1;
		if (L[u] <= nxt && nxt <= R[u]) {
			ans[u] = nxt;
		}
		else {
			ans[u] = ans[p] - 1;
		}
	}
	
	for (int i=0; i<sz(adj[u]); i++) {
		int v = adj[u][i];
		if (v == p) continue;
		findTree(v, u);
	}
}

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	scanf("%d", &n);
	for (int i=0; i<n-1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}

	scanf("%d", &K);
	
	for (int i=0; i<n; i++) {
		L[i] = -oo; R[i] = oo;
	}
	
	int root = -1;
	for (int i=0; i<K; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		L[x] = y; R[x] = y;
		root = x;
	}
	
	dfs(root);
	findTree(root);
	
	for (int i=0; i<n; i++) {
		for (int j=0; j<sz(adj[i]); j++) {
			int t = adj[i][j];
			if (abs(ans[i] - ans[t]) != 1) {
				fallen = 1;
				break;
			}
		}
		if (fallen) break;
	}
	
//	for (int i=0; i<n; i++) cout << ans[i] << endl;
	
	if (fallen) puts("No");
	else {
		puts("Yes");
		for (int i=0; i<n; i++) {
			printf("%d\n", ans[i]);
		}
	}
}


Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

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

    ll N, K; cin >> N >> K;
    vll h(N); rep(i,N) cin >> h[i];

    vll dp(N+1, INF);
    dp[0] = 0;
    rep(i, N) {
        for(ll j = 1; j <= K; j++) {
            if(i-j >= 0) chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

int main(){
    int A,B,K;
    cin >> A >> B >> K;

    int k = 0;
    int i = 101;

    while(k < K){
        i--;
        if(A % i == 0 && B % i == 0){
            k++;
        }
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable:4996)

int main()
{

	int MontainIn[10];

	for (int nCnt = 0; nCnt < 10; nCnt++)
		scanf("%d", &MontainIn[nCnt]);

	for (int nCnt = 0; nCnt < 10; nCnt++)
	{
		for (int nCnt2 = 0 ; nCnt2 < 10; nCnt2++)
		{
			if (nCnt2 == nCnt)
				continue;

			if (MontainIn[nCnt] > MontainIn[nCnt2])
			{
				MontainIn[nCnt] ^= MontainIn[nCnt2];
				MontainIn[nCnt2] ^= MontainIn[nCnt];
				MontainIn[nCnt] ^= MontainIn[nCnt2];
			}
		}
	}

	for (int nCnt = 0; nCnt < 3; nCnt++)
		printf("%d\n", MontainIn[nCnt]);

	return 0;
}

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

string S;
int main(void) {

	cin >> S;

	int N = S.size();

	string ans;

	for (int i = 0; i < N; i++) {
		if (S[i] == 'A') { ans += "T"; }
		else if (S[i] == 'C') { ans += "G"; }
		else if (S[i] == 'G') { ans += "C"; }
		else { ans += "A"; }
	}

	cout << ans << endl;


	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>
#include <cmath>
#include <map>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
namespace mp = boost::multiprecision;
typedef long long ll;
const ll M = 1000000007;

int main(){
	int n=1;
	cin >> n;
	map<long, long> mp;
	map<long, long> end_time;

	for (int i = 0; i<n; i++) {
		long k, v;
		cin >> k >> v;
		mp[k] = v;
		end_time[min(k+v, 10000000000)] = 0;
	}

	for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
		long x = end_time[min(itr->first + itr->second, 10000000000)];
		end_time[min(itr->first + itr->second, 10000000000)] = max(itr->first, x);
	}

	long tmp = 0;
	long ret = 0;
	for(auto itr = end_time.begin(); itr != end_time.end(); ++itr) {
		if (tmp <= max(0l, itr->second - mp[itr->second])) {
			ret++;
			tmp = min(mp[itr->second] + itr->second, 10000000000);
		}
	}

	cout << ret;
	return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,M,Q;
int A[2010][2010];
int x[200010];
int y[200010];
int x2[200010];
int y2[200010];
int B[2010][2010];
int C[2010][2010];
int D[2010][2010];

int calc(int a,int a2,int b){
	return B[a2][b]-B[a][b]+C[a][b];
}

int calc2(int a,int b,int b2){
	return B[a][b2]-B[a][b]+D[a][b];
}


int answer(int a,int b,int a2,int b2){
	int ans=0;
	int aa,bb;
	if(a!=0){
		aa=B[a2][b2]-B[a-1][b2]+C[a][b2];
		if(b==0){
			bb=0;
		}else{
			bb=B[a2][b-1]-B[a-1][b-1]+C[a][b-1];
		}
	}else{
		aa=B[a2][b2];
		if(b==0){
			bb=0;
		}else{
			bb=B[a2][b-1];
		}
	}
	//cout<<aa<<" "<<bb<<endl;
	if(a==0){
		ans=aa-bb+D[a2][b];
	}else{
		ans=aa-bb+D[a2][b]-D[a-1][b];
	}
	return ans;
	/*
	int ans=B[a2][b2];
	cout<<a<<" "<<b<<" "<<a2<<" "<<b2<<" "<<ans<<endl;
	if(a!=0){
		ans-=B[a-1][b];
	}
	cout<<a<<" "<<b<<" "<<a2<<" "<<b2<<" "<<ans<<endl;
	if(b!=0){
		ans-=B[a][b-1];
	}
	cout<<a<<" "<<b<<" "<<a2<<" "<<b2<<" "<<ans<<endl;
	if(a!=0&&b!=0){
		ans+=B[a-1][b-1];
	}
	cout<<a<<" "<<b<<" "<<a2<<" "<<b2<<" "<<ans<<endl;
	return ans;*/
}
int main(){
	cin>>N>>M>>Q;
	REP(i,N){
		string S;
		cin>>S;
		REP(j,M){
			if(S[j]=='0'){
				A[i][j]=0;
			}else{
				A[i][j]=1;
			}
		}
	}
	REP(i,N){
		REP(j,M){
			if(i==0){
				C[i][j]=0;
			}else{
				C[i][j]=A[i][j]&A[i-1][j];
				if(j!=0){
					C[i][j]+=C[i][j-1];
				}
			}
			if(j==0){
				D[i][j]=0;
			}else{
				D[i][j]=A[i][j]&A[i][j-1];
				if(i!=0){
					D[i][j]+=D[i-1][j];
				}
			}
		}
	}
	int num=0;
	REP(i,M){
		if(i==0){
			if(A[0][0]==1){
				num++;
			}
			B[0][0]=num;
		}else{
			if(A[0][i]==1&&A[0][i-1]==0){
				num++;
			}
			B[0][i]=num;
		}
	}
	num=0;
	REP(i,N){
		if(i==0){
			if(A[0][0]==1){
				num++;
			}
			B[0][0]=num;
		}else{
			if(A[i][0]==1&&A[i-1][0]==0){
				num++;
			}
			B[i][0]=num;
		}
	}
	REP(i,N){
		REP(j,M){
			if(i==0)continue;
			if(j==0)continue;
			B[i][j]=B[i-1][j]+B[i][j-1]-B[i-1][j-1];
			//cout<<i<<" "<<j<<" pre"<<B[i][j]<<endl;
			if(A[i][j]==1){
				B[i][j]+=(A[i][j]-A[i-1][j]-A[i][j-1]);
			}
			//cout<<i<<" "<<j<<" after"<<B[i][j]<<endl;
		}
	}
	
	REP(i,Q){
		cin>>x[i]>>y[i]>>x2[i]>>y2[i];
		x[i]--;
		y[i]--;
		x2[i]--;
		y2[i]--;
	}
	/*
	cout<<endl;
	REP(i,N){
		REP(j,M){
			cout<<A[i][j]<<" ";
		}
		cout<<endl;
	}
	
	cout<<endl;
	REP(i,N){
		REP(j,M){
			cout<<B[i][j]<<" ";
		}
		cout<<endl;
	}
	
	cout<<endl;
	REP(i,N){
		REP(j,M){
			cout<<C[i][j]<<" ";
		}
		cout<<endl;
	}
	
	cout<<endl;
	REP(i,N){
		REP(j,M){
			cout<<D[i][j]<<" ";
		}
		cout<<endl;
	}*/
	
	REP(i,Q){
		cout<<answer(x[i],y[i],x2[i],y2[i])<<endl;
	}
	return 0;
}

Measured memory_bytes: 67968
(X, Y, Z, K), As, Bs, Cs = readlines.map{|l| l.split.map(&:to_i)}

$as, $bs, $cs = [As, Bs, Cs].map{|xs| [nil] + xs.sort.reverse}

class Cakes
  include Comparable
  attr_accessor :ids, :taste

  def initialize(ids)
    @ids = ids
    @taste = $as[ids[0]] + $bs[ids[1]] + $cs[ids[2]]
  end

  def <=>(other)
    @taste <=> other.taste
  end
end

class PriorityQueue
  def initialize
    @q = [nil]
    @done = Hash.new(false)
  end

  def bubble_up(i)
    pi = i / 2
    return if i <= 1 || @q[pi] >= @q[i]
    @q[i], @q[pi] = @q[pi], @q[i]
    bubble_up(pi)
  end

  def add(e)
    return if @done[e.ids]
    @q << e
    bubble_up(@q.size - 1)
    @done[e.ids] = true
  end

  def bubble_down(i)
    ci = i * 2
    return if ci > @q.size - 1
    ci += 1 if ci != @q.size - 1 && @q[ci] < @q[ci + 1]
    return if @q[i] >= @q[ci]
    @q[i], @q[ci] = @q[ci], @q[i]
    bubble_down(ci)
  end

  def pop
    @q[1], @q[-1] = @q[-1], @q[1]
    ret = @q.pop
    bubble_down(1)
    ret
  end
end

def go(x, y, z)
  $pq.add(Cakes.new([x, y, z]))
end

$pq = PriorityQueue.new
go(1, 1, 1)
K.times do |i|
  e = $pq.pop
  puts e.taste
  x, y, z = e.ids
  go(x+1, y, z) if x < X
  go(x, y+1, z) if y < Y
  go(x, y, z+1) if z < Z
end

Measured memory_bytes: 2808
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e5+10;
const ll mod =   1e9+7;
int n;
ll a[N],b[N];
int main()
{  fast
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
sort(a+1,a+1+n);
sort(b+1,b+n+1);
if(n%2){
	cout<<b[n/2+1]-a[n/2+1]+1;
}
else
{
	cout<<(b[n/2]+b[n/2+1]-a[n/2]-a[n/2+1])+1;
}
}

Measured memory_bytes: 6736
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
int64_t dp[100000][3];
int main(){
    int N;
    cin>>N;
    cin>>dp[0][0];
    dp[0][2]=dp[0][1]=-1e16;
    for(int i=1;i<N;i++){
        int A;
        char op;
        cin>>op;
        cin>>A;
        if(op=='+'){
            dp[i][0]=max({dp[i-1][0]+A,dp[i-1][1]-A,dp[i-1][2]+A});
            dp[i][1]=max({dp[i-1][1]-A,dp[i-1][2]+A});
            dp[i][2]=dp[i-1][2]+A;
        }else{
            dp[i][0]=max({dp[i-1][0]-A,dp[i-1][1]+A,dp[i-1][2]-A});
            dp[i][1]=max({dp[i-1][0]-A,dp[i-1][1]+A,dp[i-1][2]-A});
            dp[i][2]=max(dp[i-1][1]+A,dp[i-1][2]-A);
        }
    }
    cout<<max({dp[N-1][0],dp[N-1][1],dp[N-1][2]})<<endl;
    return 0;
}

Measured memory_bytes: 2560
import java.io.*;
public class Main{
	public static void main(String args[]){
    int x , y;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    try{
			String line = reader.readLine();
      x = Integer.parseInt(line);
      y = x;
		}catch(Exception e){
      x = 0;
      y = 0;
    }
    for(int i = 1 ; i <= 2 ; i ++){

      x = x * y;
      
    }
		System.out.println((x));
	}
}


Measured memory_bytes: 24216
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 18;
 
int TT[maxN * 7], *pref = TT + maxN, *suf = TT + maxN * 3;
char in[maxN]; 
vector <pair <int, int> > T;
 
void solve()
{
	int n, k, c;
	scanf ("%d%d%d", &n, &k, &c);
	scanf ("%s", in);
	c++;
	
	vector <int> a(0), b(0);
	FOR(i, 0, n)
	{
		pref[i] = pref[i-1];
		if (in[i] == 'o')
			pref[i] = max(pref[i], pref[i-c] + 1);
		if (pref[i] != pref[i-1])
			a.pb(i);
			
		if (pref[i] == k)
			break;
	}
	
	FORD(i, n-1, -1)
	{
		suf[i] =  suf[i+1];
		if (in[i] == 'o')
			suf[i] = max(suf[i], suf[i+c] + 1);
		if (suf[i] != suf[i+1])
			b.pb(i);
			
		if (suf[i] == k)
			break;
	}
	
	reverse(ALL(b));
	FOR(i, 0, k)
		if (a[i] == b[i])
			printf("%d\n", a[i]+1);

}
 
int main()
{
	int t;
t=1;////	scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}


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

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

using namespace std;

/*

全体の方針としては，'7' '5' '3'のみで構成された数字を333, 335, 337, 353, ...
のように小さい順に列挙していき，753数(753それぞれが一回ずつは存在する数字)であったなら
それをカウントしていき，列挙された数字が与えられたNを超えてしまったらそこで列挙を終了して
答えを出力する．

今回は使用される数字が等間隔だったので，列挙が割とリーズナブルに書けた気がする．

*/

//次に小さい3, 5, 7のみで構成される数字に変える
void nexts(string& str)
{
	bool f=true;
	//全部'7'か調べる
	rep(i, str.size()){
		if (str[i] != '7'){
			f = false;
			break;
		}
	}
	//全部'7'である時は位を1つ増やして全部'3'にする．
	if (f){
		rep(i, str.size()){
			str[i] = '3';
		}
		str.push_back('3');
		return;
	}
	//'7' '5' '3'の差はどれも2なのでとりあえず一番右の位を2足す
	//後ろのfor文は繰上げの処理
	str[str.size()-1] += 2;
	for(int i=str.size()-1; str[i] == '9'; i--){
		str[i] = '3';
		str[i-1] += 2;
	}
	return;
}

//'7' '5' '3'がちゃんと全部含まれているかチェックする関数
//含まれていたらtrueを返す
bool find753(string& str){
	bool ret, f7=false, f5=false, f3=false;
	rep(i, str.size()){
		if (str[i] == '7') f7 = true;
		if (str[i] == '5') f5 = true;
		if (str[i] == '3') f3 = true;
	}
	return f7*f5*f3;
}

int main()
{
	ll n, ans=0;
	cin >> n;
	string s;
	//3桁未満はありえないので"333"から列挙スタート
	rep(i, 3) s.push_back('3');
	//列挙している数字がnを超えてしまったらbreakする
	//それまでは753数ならansをインクリメントしてカウント
	while(true){
		nexts(s);
		if (stoll(s) > n){
			break;
		}
		if (find753(s)){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split();
	public K()
	{
		var N = F;
		var ps = new List<Point>(N);
		for (var i = 0; i < N; i++) ps.Add(new Point(GL));
		var hull = ps.ToList().ConvexHull();
		foreach (var p in ps)
		{
			var ok = false;
			for (var j = 0; j < hull.Count; j++)
			{
				if (hull[j].CompareTo(p) == 0)
				{
					ok = true;
					if (hull.Count == 2) { WriteLine(0.5); break; }
					var prev = j > 0 ? hull[j - 1] : hull[hull.Count - 1];
					var next = j + 1 < hull.Count ? hull[j + 1] : hull[0];
					var z = (hull[j] - prev) / (next - hull[j]);
					WriteLine(Abs(z.Phase) / (2 * PI));
					break;
				}
			}
			if (!ok) WriteLine(0);
		}
	}
}
static class Geometry
{
	public static bool CCW(Point a, Point b, Point c)
	{
		var p = b - a;
		var q = c - a;
		var cross = p % q;
		return cross <= 0 && (cross != 0 || p * q >= 0);
	}
	public static List<Point> ConvexHull(this List<Point> points)
	{
		int n = points.Count, k = 0;
		points.Sort();
		var convex = new Point[2 * n];
		for (var i = 0; i < n; convex[k++] = points[i++]) while (k >= 2 && CCW(convex[k - 2], convex[k - 1], points[i])) --k;
		for (int i = n - 2, t = k + 1; i >= 0; convex[k++] = points[i--]) while (k >= t && CCW(convex[k - 2], convex[k - 1], points[i])) --k;
		return convex.Take(k - 1).ToList();
	}
}
class Point : IComparable<Point>
{
	public readonly long X, Y;
	public Point(long x, long y) { X = x; Y = y; }
	public Point(long[] I) : this(I[0], I[1]) { }
	public static Point operator -(Point p, Point q) => new Point(p.X - q.X, p.Y - q.Y);
	public static long operator *(Point p, Point q) => p.X * q.X + p.Y * q.Y;
	public static long operator %(Point p, Point q) => p.X * q.Y - p.Y * q.X;
	public static explicit operator Complex(Point p) => new Complex(p.X, p.Y);
	public static Complex operator /(Point p, Point q) => (Complex)p / (Complex)q;
	public int CompareTo(Point other) => X == other.X ? Y.CompareTo(other.Y) : X.CompareTo(other.X);
}


Measured memory_bytes: 13524
/*
  AtCoder Beginner Contest 100
  C - *3 or /2
*/

#include<iostream>
#include<vector>
using namespace std;

int N, a;

int numDivByTwo(int a) {
  int c = 0;
  while(a % 2 == 0) {
    a /= 2;
    ++c;
  }
  return c;
}

int main() {
  scanf("%d", &N);

  int count = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a);
    count += numDivByTwo(a);
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 256