akhauriyash/Code-Regression huggingface dataset:
import bisect as bi
a,b,q = map(int,input().split())
s = sorted([int(input()) for i in range(a) ])
t = sorted([int(input()) for i in range(b) ])
x = [int(input()) for i in range(q) ]

for i in range(q):
    Q = x[i]
    ans_s = []
    ans_t = []
    ans_s.append(s[bi.bisect_left(s,Q)-1])
    ans_t.append(t[bi.bisect_left(t,Q)-1])
    ans = 10**11
    
    if bi.bisect_right(s,Q) == len(s):
        ans_s.append(s[bi.bisect_left(s,Q)-1])
    else:
        ans_s.append(s[bi.bisect_left(s,Q)])
        
    if bi.bisect_right(t,Q) == len(t):
        ans_t.append(t[bi.bisect_left(t,Q)-1])
    else:
        ans_t.append(t[bi.bisect_left(t,Q)])
    
    for i in range(2):
        for j in range(2):
            ans = min(ans,abs(ans_s[i]-Q)+abs(ans_s[i]-ans_t[j]),abs(ans_t[j]-Q)+abs(ans_s[i]-ans_t[j]))
    
    print(ans)

Measured memory_bytes: 16160
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a= sc.nextInt();
    int b= sc.nextInt();
    boolean c = true;
    for(int i=a;i<=b;i++)
    {
      if(i%n==0)
      {System.out.println("OK");
     return;}

    }
    System.out.println("NG");
 
  }
}

        

Measured memory_bytes: 35776
s = input()
s = s.replace("BC", "D")

cnt = 0
num_a = 0
for i in range(len(s)):
    if s[i] in ["B", "C"]:
        num_a = 0
    elif s[i] == "A":
        num_a += 1
    elif s[i] == "D":
        cnt += num_a

print(cnt)

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

int main()
{
    int n;
    cin >> n;
    int p[n];
    for(int i=0;i<n;++i) cin >> p[i];
    int cnt=0;
    for(int i=0;i<n;++i){
        if(p[i]==i+1 && i!=n-1){
            swap(p[i],p[i+1]);
            ++cnt;
        }
        else if(p[i]==i+1 && i==n-1){
            swap(p[i],p[i-1]);
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//↓✟MLE魔、TLE魔✟
#define int long long
//↑✟MLE魔、TLE魔✟
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
class Union_Find{
private:
    vector<int> t,s;
public:
    Union_Find(int max_length){
        rep(i,max_length+1){
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x,int y){
        if(same(x,y))return;
        int tx=Find(x),ty=Find(y);
        if(s[tx]<s[ty]){
            s[ty]+=s[tx];
            t[tx]=ty;
        }
        else if(s[tx]>s[ty]){
            s[tx]+=s[ty];
            t[ty]=tx;
        }
        else if(tx>ty){
            t[tx]=ty;
            s[ty]+=s[tx];
        }
        else{
            t[ty]=tx;
            s[tx]+=s[ty];
        }
    }
    int Find(int n){
        if(t[n]==n)return n;
        else return t[n]=Find(t[n]);
    }
    bool same(int x,int y){
        return Find(x)==Find(y);
    }
    int gets(int a){
        return s[a];
    }
};
signed main(){
    int n,m,c,b[20],ans=0;
    cin>>n>>m>>c;
    rep(i,m)cin>>b[i];
    rep(i,n){
        int cnt=0;
        rep(j,m){
            int in;
            cin>>in;
            cnt+=in*b[j];
        }
        if(cnt+c>0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string str = Console.ReadLine();
        string[] strer = str.Split(' ');

        int n =  int.Parse(strer[0]);
        int m = int.Parse(strer[1]);
        int[,] array1 = new int[n, m];
        int[] array2 = new int[m];
        int[] array3 = new int[n];
        
        for (int i = 0; i < n; i++)
        {
            str = Console.ReadLine();
            strer = str.Split(' ');

            for (int j = 0; j < m; j++)
            {
                array1[i,j] = int.Parse(strer[j]);
            }
        }

        for (int i = 0; i < m; i++)
        {
            array2[i] = int.Parse(Console.ReadLine());
        }

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                array3[i] += array1[i, j] * array2[j];
            }
        }

        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(array3[i]);
        }


              
    }
}


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

int main(){
    
    ios_base::sync_with_stdio(NULL);
    
    int n,k;
    cin>>n>>k;
    vector<int> arr(n);
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr.begin(),arr.end());
    long long ans=0;
    for(int i=0;i<min(k,n) ;i++){
        ans+=arr[i];
        
    }
    
    cout<<ans;
    
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k = 0, n, now, ans = 0;
  scanf("%lld", &n);
  char s[1000010];
  pair<ll, ll> a[n];
  for(i = 0; i < n; ++i) {
    a[i].first = now = 0;
    scanf("%s", s);
    for(j = 0; s[j]; ++j) {
      if(s[j] == '(') now++;
      else now--;
      if(-now > a[i].first) a[i].first = -now;
    }
    a[i].second = now;
    ans += now;
  }
  if(ans) {
    printf("No");
    return 0;
  }
  sort(a, a + n);
  now = 0;
  priority_queue< pair<ll, ll> > q, q2;
  for(i = 0; i < n; ++i) {
    for(; a[k].first <= now && k < n; ++k) q.push(make_pair(a[k].second, a[k].first));
    if(k == n) break;
    if(!q.size() || q.top().first < 0) {
      printf("No");
      return 0;
    }
    now += q.top().first;
    q.pop();
  }
  while(q.size()) {
    if(q.top().first >= 0) now += q.top().first;
    else q2.push(make_pair(q.top().second + q.top().first, -q.top().first));
    q.pop();
  }
  while(q2.size()) {
    if(now < q2.top().first + q2.top().second) {
      printf("No");
      return 0;
    }
    now -= q2.top().second;
    q2.pop();
  }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 49964
import math
  
def floatinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = float(a[i])
    return a
     
def main():
    a = floatinput()
    x1 = a[0]; y1 = a[1]; x2 = a[2]; y2 = a[3]
    print(math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2))
     
if __name__ == "__main__":
    main()


Measured memory_bytes: 5656
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUGLOCAL
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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



int main() {
	pair<Int,Int> res0,res1;
	Int p,n;
	for(;;){
		cin>>p>>n;
		if(p==0&&n==0)break;
		res0.first=1;
		res0.second=n;
		res1.first=n;
		res1.second=1;
		int a,b;
		repn(i,1,n){
			a=1;b=n+1;
			while(a<b-1){
				Int m=(a+b)/2;
				if(m*m<=p*i*i)a=m;
				else b=m;
			}
debug<<a<<endl;
			b=a+1;
			if(res0.first*i<a*res0.second){
				res0.first=a;
				res0.second=i;
			}
			if(b<=n&&b*b>p*i*i&&res1.first*i>b*res1.second){
				res1.first=b;
				res1.second=i;
			}
		}
		cout<<res1.first<<"/"<<res1.second<<" "<<res0.first<<"/"<<res0.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 11000
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var counts = new Dictionary<string, int> {
            ["AC"] = 0,
            ["WA"] = 0,
            ["TLE"] = 0,
            ["RE"] = 0,
        };

        for (int i = 0; i < n; i++) {
            var key = Console.ReadLine();
            counts[key]++;
        }

        foreach (var count in counts) {
            Console.WriteLine($"{count.Key} x {count.Value}");
        }
    }
}

Measured memory_bytes: 30956
package main

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

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	var ch, cw int
	fmt.Scan(&ch, &cw)
	ch--
	cw--
	var dh, dw int
	fmt.Scan(&dh, &dw)
	dh--
	dw--

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	ss := make([][]byte, h)
	for i := range ss {
		sc.Scan()
		ss[i] = []byte(sc.Text())
	}

	cs := make([][]int, h)
	for i := range cs {
		cs[i] = make([]int, w)
	}

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

	nqs := make([][]int, 0)
	iqs := make([][]int, 0)
	iqs = append(nqs, []int{ch, cw, 0})
	for len(iqs) > 0 {
		qs := make([][]int, 0)
		qs = append(qs, iqs...)
		nqs := make([][]int, 0)
		for len(qs) > 0 {
			q := qs[0]
			qs = qs[1:]
			y, x := q[0], q[1]
			//fmt.Println("y,x: ", y, x)
			for i := range dx {
				ny, nx := y+dy[i], x+dx[i]
				if ny < 0 || ny >= h || nx < 0 || nx >= w {
					continue
				}
				if cs[ny][nx] == 1 {
					continue
				}
				if ss[ny][nx] == '#' {
					continue
				}
				if ny == dh && nx == dw {
					fmt.Println(q[2])
					return
				}
				cs[ny][nx] = 1
				qs = append(qs, []int{ny, nx, q[2]})
				nqs = append(nqs, []int{ny, nx, q[2]})
			}
		}
		nqs = append(nqs, iqs...)
		iqs = make([][]int, 0)
		for len(nqs) > 0 {
			q := nqs[0]
			nqs = nqs[1:]
			y, x := q[0], q[1]
			for dy := -2; dy <= 2; dy++ {
				for dx := -2; dx <= 2; dx++ {
					if dy == 0 && abs(dx) <= 1 {
						continue
					}
					if dx == 0 && abs(dy) <= 1 {
						continue
					}
					ny, nx := y+dy, x+dx
					if ny < 0 || ny >= h || nx < 0 || nx >= w {
						continue
					}
					if cs[ny][nx] == 1 {
						continue
					}
					if ss[ny][nx] == '#' {
						continue
					}
					if ny == dh && nx == dw {
						fmt.Println(q[2] + 1)
						return
					}
					cs[ny][nx] = 1
					iqs = append(iqs, []int{ny, nx, q[2] + 1})
				}
			}
		}
	}

	fmt.Println(-1)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 24052
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 D = sc.nextInt();

        sc.close();

        int diff = Math.min(B, D) - Math.max(A, C);
        int count = diff < 0 ? 0 : diff;

        System.out.println(count);

    }
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
typedef long long int ll;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

int main(){
  int n;
  cin >> n;
  
  int sum = 0;
  
  vector<int> a(n), b(n), c(n-1);
  rep(i,n) cin >> a[i];
  rep(i,n){
    cin >> b[i];
    sum += b[i];
  }
  rep(i,n-1) cin >> c[i];
  
  rep(i,n-1){
    if(a[i+1] == a[i] + 1){
      sum += c[a[i]-1];
    }
  }
  
  cout << sum << endl;
    
}

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

using namespace std;

int main(){
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector <int> x(N), y(M);

    for(int i = 0; i < N; i++){
        cin >> x[i];
    }
    sort(x.begin(), x.end());

    for(int i = 0; i < M; i++){
        cin >> y[i];
    }
    sort(y.begin(), y.end());


    int count = 0;
    for(int i = X + 1; i <= Y; i++){
        if (x[N-1] < i && i <= y[0]) {
            count += 1;
        }
    }

    if (count == 0) {
        cout << "War" << endl;
    }else{
        cout << "No War" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
K = int(input())

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

count = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        a = gcd(i, j)
        for k in range(j, K + 1):
            n = len(set([i, j, k]))
            if n == 3:
                count += 6 * gcd(a, k)
            elif n == 2:
                count += 3 * gcd(a, k)
            else:
                count += gcd(a, k)
            
print(count)

Measured memory_bytes: 9216
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	a := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		sum += a[i]
	}

	l := 0
	r := 0
	m := 0
	c := 0
	for i := 0; i < N; i++ {
		if r < sum/2 {
			l = r
			r += a[i]
			c++
		} else {
			m = a[c-1]
			r = sum - r
			break
		}
	}
	if N == 2 {
		l = a[0]
		r = a[1]
		m = 0
	}

	//	out(l, r, m, c)
	ans := sum * 2
	if l+m >= r {
		ans = min(ans, (l + m - r))
	} else {
		ans = min(ans, r-(l+m))
	}
	if r+m >= l {
		ans = min(ans, (r + m - l))
	} else {
		ans = min(ans, (l - (r + m)))
	}
	out(ans)

}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
using tdata=pair<ll,data>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }
int main(){
  ll i,ans=0;
  string ss;cin>>ss;
  rep(i,(ll)ss.size()){
    if(ss[i]=='g'){
      ans++;
    }else{
      ans--;
    }
  }
  ans/=2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios		ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ios
	string s;
	cin>>s;
	int k;
	cin>>k;

	int a[26]={0};
	int n=s.length();

	for(int i=0;i<n;i++)
	{
		a[s[i]-'a']++;
	}
	queue<int>q;
	for(int i=0;i<26;i++)
	{
		if(a[i]>0)
		q.push(i);
	}
	set<string>v;
	int x;
	while(!q.empty())
	{
		x=q.front();
		for(int i=0;i<n;i++)
		{
			if(s[i]==char(97+x))
			{
				
				string t="";
				t+=s[i];
				v.insert(t);
				for(int j=i+1;j<min(n,i+11);j++)
				{
					t+=s[j];
					v.insert(t);
				}
			}
		}
		if(v.size()>=k)
		{
			break;
		}
		else
		q.pop();
	}
	
	set<string>::iterator it;
	vector<string>v1;

	for(it=v.begin();it!=v.end();it++)
	v1.pb(*it);

	sort(all(v1));
	
	cout<<v1[k-1];
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < S.size(); i++) {
    S.at(i) += N;
    if (S.at(i) > 'A' + 25) {
      S.at(i) -= 26;
    }
  }
  cout << S << endl;
}



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

#define PI 3.141592653589793

int main(){
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double kakuA, kakuB;
    kakuB=2.0*PI*M/60.0;
    kakuA=2.0*PI*(H/12.0+M/12.0/60.0);
    double theta;
    theta = abs(kakuA-kakuB);
    if(theta>PI){
        theta = 2.0*PI - theta;
    }
    cout << fixed << setprecision(15) << sqrt(A*A + B*B -2.0*A*B*cos(theta)) << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,data[25][25],m=10000000;
  cin>>h>>w;
  for(int i=0;i<h;++i)
    for(int j=0;j<w;++j) cin>>data[i][j];
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      int sum=0;
      for(int k=0;k<h;++k){
	for(int l=0;l<w;++l){
	  if(i!=k&&j!=l)  sum=sum+min(abs(k-i),abs(l-j))*data[k][l];
	}
      }
      m=min(m,sum);
    }
  }
  cout<<m<<endl;
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"YES"<<"\n"
//#define no cout<<"NO"<<"\n"
#define INF (int)1e5+5
#define nax (int)1e6+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define MAX_N (int)1e6+2
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern
 
 

int n,m,pi;
char mat[7][7];

//int ans = 0;
	
signed main() {	
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);	

	
	cin >> n >> m >>pi;
	
	int row[7] , col[7];
	memset(row , 0 , sizeof(row));
	
	memset(col , 0 , sizeof(col));
	
	
	int cnt = 0;
	
	for(int i =0 ; i < n; i++){
		for(int j =0; j <m ;j++){
			cin >> mat[i][j];
			if(mat[i][j] == '#'){
				row[i] += 1;
				col[j] += 1;
				cnt += 1;
				
				
			}
		}
	}
	
	
	int mask1 = 1<<(n);
	int mask2 = 1<<(m);
	
	int ans = 0;
	
	//debug(mask1 , mask2);
	
	for(int i = 0; i < mask1 ;i++){
		
		
		vector<int> selected;
			
		int rem = 0 ,ku;
		for(int k =1 ; k <= n ;k++){
			if((i &(1 << (k-1)))  == (1<<(k-1))){
				selected.pb(k-1);
				rem += row[k-1];
			}
		}
		ku = rem;
		//debug(selected);
		for(int j = 0; j < mask2 ;j++){
			
			//debug(rem);
			rem = ku;
			
			vector<int> sele;
			
			for(int p = 1 ; p <= m; p++){
				if((j &(1 << (p-1)))  == (1<<(p-1))){
					
					sele.pb(p-1);
					
					rem += col[p-1];
					for(auto it : selected){
						if(mat[it][p-1] == '#'){
							rem -= 1;
						}
					}
				}
			}
			
			//debug(sele);
			//debug(rem);
			if(cnt - rem == pi){
				ans += 1;
			}
			
		}
	}
	
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
string st,st1;
int djy,ll,gs;
int main()
{
cin>>st;
ll=st.size();
st1="CODEFESTIVAL2016";
while(djy<ll)
{
	if(st[djy]!=st1[djy])gs++;
	djy++;
}
cout<<gs<<endl;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n,a[4],t[100],p[100],i,j,k;
	scanf("%d",&n);
	for(i=0;i!=n;++i)
		t[i]=0;
	for(i=0;i!=n*(n-1)/2;i++){
		for(j=0;j!=4;j++)
			scanf("%d",&a[j]);
		if(a[2]<a[3])
			t[a[1]-1]+=3;
		else if(a[2]>a[3])
			t[a[0]-1]+=3;
		else{
			t[a[0]-1]+=1;
			t[a[1]-1]+=1;
		}
	}
	for(i=0;i!=n;++i)
		p[i]=t[i];
	for(i=0;i!=n;++i){
		for(j=i;j!=n;j++){
			if(p[i]<p[j]){
				k=p[i];
				p[i]=p[j];
				p[j]=k;
			}
		}
	}
	for(i=0;i!=n;++i){
		for(j=0;j!=n;++j){
			if(t[i]==p[j]){
				printf("%d\n",j+1);
				break;
			}
		}
	}
}

Measured memory_bytes: 2636
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

ll dp[100010][3];

int main() {
    ll N;
    cin >> N;
    ll a[N], b[N], c[N];
    REP(i, 0, N) {
        cin >> a[i] >> b[i] >> c[i];
    }
    REP(i, 0, 100010) {
        fill(dp[i], dp[i] + 3, 0);
    }
    REP(i, 0, N) {
        dp[i + 1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i]);
        dp[i + 1][1] = max(dp[i][0] + b[i], dp[i][2] + b[i]);
        dp[i + 1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i]);
    }
    ll ans = 0;
    REP(i, 0, 3) {
        ans = max(ans, dp[N][i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    string s;
    cin>>s;
    int count=1;
    string s1;
    s1+=s[0];
    for(int i=1;i<s.size();i++)
    {
       if((s1.size()==2)||(s[i]!=s1[0]))
       {
           count++;
           s1=s[i];
           continue;
       }
       else
       {
           if(i==s.size()-1)
           break;
           else
           {
              s1=s[i];
              i++;
              s1+=s[i];
              count++;
             continue;
           }
       }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
char a[maxn],b[maxn],s[maxn],t[maxn];
int main(){
	memset(s, '*', sizeof(s));
	memset(t, '*', sizeof(t));
    scanf("%s",a);
    scanf("%s",b);
    int len = strlen(a);
    for(int i = 1; i <= len ; i++){
    	if(s[a[i] - 'a'] == '*' || s[a[i] - 'a'] == b[i])
    		s[a[i] - 'a'] = b[i];
    	else {
    		puts("No");
     	    return 0;
		}
		if(t[b[i] - 'a'] == '*' || t[b[i] - 'a'] == a[i])
			t[b[i] - 'a'] = a[i];
		else {
			puts("No");
			return 0;
			}	
    }
    puts("Yes");
    return 0;
	}

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

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    int x = (a+d-1)/d,y = (c+b-1)/b;
    if(x>=y) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>

using namespace std;

int main(void) {
    string s;
    int s_length;
    int ans = 1;
    cin >> s;
    s_length = s.size();

    ans = floor(s_length / 2);
    int base_k = ans + 1;

    for( int k = base_k;; k++ ) {
        int length = 2*k-s_length;
        int pos = s_length-k;
        if (length <= 0 || pos < 0) break;

        string sub_s = s.substr(pos, length);
        if (sub_s == string(sub_s.size(), '1') || sub_s == string(sub_s.size(), '0')) {
            ans = k;
        } else {
            break;
        }
    }
    cout << ans;

    return 0;
}

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

int main(){
	int n;
	cin>>n;
	int a[n],sum=0,sum1=0,avg,avg1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	avg=sum/n;
	avg1=avg+1;
	
	sum=0;
	for(int i=0;i<n;i++){
		sum+=(a[i]-avg)*(a[i]-avg);
		sum1+=(a[i]-avg1)*(a[i]-avg1);
	}
	cout<<min(sum,sum1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  ll ten = 1LL;
  ll zero = 1LL;
  ll two = 1LL;
  rep(i,n) {
    ten *= 10LL;
    ten %= mod;
    zero *= 9LL;
    zero %= mod;
    two *= 8LL;
    two %= mod;
  }
  ll ans = ten - 2*zero + two;
  while(ans<0) ans += mod;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int n, d, a, f[200015]; long long res;
pair <int, int> x[200015];

int main() {
    cin >> n >> d >> a;
    for (int i = 0; i < n; ++i)
        cin >> x[i].first >> x[i].second,
        x[i].second = x[i].second / a + (x[i].second % a > 0);
    sort(x, x + n); d = 2 * d;
    for (int i = 0; i < n; f[++i] += f[i - 1])
        if (f[i] < x[i].second) {
            int k = upper_bound(x, x + n, make_pair(x[i].first + d, int(1e9))) - x;
            res += x[i].second - f[i];
            f[k] -= x[i].second - f[i];
            f[i] = x[i].second;
        }
    cout << res;
}

Measured memory_bytes: 2560
mod = 10**9 + 7
n = int(input())
dat = list(map(int, input().split()))
cnt0 = [0] * 64
cnt1 = [0] * 64
for i in range(n):
    for j in range(62):
        if ((dat[i] >> j) & 1) == 1:
            cnt1[j] += 1
        else:
            cnt0[j] += 1
#print(cnt0)
#print(cnt1)
res = 0
for i in range(62):
    res += (cnt0[i] * cnt1[i]) << i
    res %= mod
print(res)

Measured memory_bytes: 124560
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD 1000000007

#define int long long

int N_global;

vector<int> N_A(500,0);
vector<int> N_P(500,0);

int ReFUNC(int N,int X)
{
  // cout<<"call"<<endl;
  if(N == 0)
  {
    if(X <= 0)return 0;
    else return 1;
  }
  else if (X <= 1 + N_A[N-1])
  {
    return ReFUNC(N-1,X-1);
  }
  else
  {
    return N_P[N-1] + 1 + ReFUNC(N-1, X -2 - N_A[N-1]);
  }

}



void solve()
{
  int N,X;
  cin>>N>>X;

  N_A[0] = 1;
  N_P[0] = 1;
  for (int i = 1; i < N; i++)
  {
    N_A[i] = N_A[i-1]*2 + 3;
    N_P[i] = N_P[i-1]*2 + 1;
  }
  
  cout<<ReFUNC(N,X)<<endl;
  
  return;
}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import math

n = ii()


def calc(x):
    nq = int(math.sqrt(x)+1)
    for i in range(2,nq +1):
        if x % i == 0:
            return x//i, i
    return -1,x

x = n
ans = []
while 1:
    x,m = calc(x)
    ans.append(m)
    if x <= 1:
        break
    

print(str(n)+': ',end='')
print(*ans)


Measured memory_bytes: 5668
using System;

namespace ABC106_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = 0;
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            s = (a - 1) * (b - 1);
            Console.WriteLine(s);
            
            
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
#define MIN(a,b) a<b?a:b

int main(){
    int i,j;
    int n;
    int s[3];
    int min=100000001;
    int count=0;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &s[i]);
        min=MIN(min,s[i]);
    }
    for(i=1;i<=min;i++){
        for(j=0;j<n;j++){
            if(s[j]%i)break;
            else count++;
        }
        if(count==n)printf("%d\n", i);
        count=0;
    }

    return 0;
}


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

int sw=0;

void outputArray(int A[],int n){
	for(int i=0;i<n-1;i++)
		cout<<A[i]<<" ";
	cout<<A[n-1]<<endl;
}

void bubbleSort(int A[], int n){
	bool flag=1;
	for(int i=0;flag;i++){
		flag = 0;
		for(int j=n-1;j>i;j--){
			if(A[j]<A[j-1]){
				swap(A[j],A[j-1]);
				flag = 1;
				sw++;
			}
		}
//	outputSort(A,n);
	}
}

int main(){
	
	int n;
	cin>>n;
	int A[n];
	for(int i=0;i<n;i++)
		cin>>A[i];
	
	bubbleSort(A,n);
	outputArray(A,n);
	cout<<sw<<endl;
	return 0;
} 


Measured memory_bytes: 3116
import java.util.*;
public class Main {
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
		String po=sc.nextLine();
        String p[]=po.split("",0);
      int count =700;
        for(int i=0;i<p.length;i++){
         if(p[i].equals("o"))count+=100;
        }
        System.out.println(count);
	}
}

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

void solve(long long N, long long K, std::string S){
    ll original = 0;
    for(int i=1;i<N;i++){
        if(S[i-1] == S[i]){
            original++;
        }
    }
    if(N==2){
        cout << original << endl;
        return;
    }
    cout << min(original + 2*K,N-1) << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(N, K, S);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e2+9;
const long long int inf=INT_MAX;
int dis[MAX][MAX];
void init(int n){
	for(int i=0;i<n;i++){
		dis[i][i]=0;
		for(int j=0;j<n;j++){
			dis[i][j]=inf;
		}
	}
}
int main(){
	int i,j, k ,n,m;
	cin>>n>>m;
	init(n);
	
	for(i=0;i<m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		dis[x][y]=z;
	//	dis[y][x]=z;
	}
	for(i=0;i<n;i++)
		dis[i][i]=0;
	for(k=0;k<n;k++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(dis[i][k]==inf||dis[k][j]==inf)
					continue;
				if(dis[i][j]>dis[i][k]+dis[k][j]){
					dis[i][j]=dis[i][k]+dis[k][j];
				//	cout<<dis[i][j];
				}
			}
		}
	}
	int f=0;
	for(k=0;k<n;k++){
		if(dis[k][k]<0)
			f=1;
	}
	if(f){
		cout<<"NEGATIVE CYCLE"<<"\n";
	}
	else{
		for(i=0;i<n;i++){
			if(dis[i][0]==inf)
				cout<<"INF";
			else
				cout<<dis[i][0];
			for(j=1;j<n;j++){
				if(dis[i][j]==inf)
					cout<<" INF";
				else
					cout<<" "<<dis[i][j];

		}
		cout<<"\n";
	}
	
}
}


Measured memory_bytes: 3136
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int a[114514];
lint s1[114514],s2[114514],su[114514];
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	rep(i,n) scanf("%d",&a[i]);
	memset(s1,0,sizeof(s1));memset(s2,0,sizeof(s2));memset(su,0,sizeof(su));
	rep(i,n){
		s1[i+1]=s1[i];su[i+1]=su[i]+a[i];
		if(a[i]>0) s1[i+1]+=a[i];
	}
	for(int i=n;i>0;i--){
		s2[i-1]=s2[i];
		if(a[i-1]>0) s2[i-1]+=a[i-1];
	}
	lint out=0;
	rep(i,n-k+1){
		lint t=s1[i]+s2[i+k],s=su[i+k]-su[i];
		out=max(out,t+max(0LL,s));
	}
	cout<<out<<endl;
}


Measured memory_bytes: 3328
N = int(input())
A = list(map(int, input().split()))
O = []
B = 0

for i in range(len(A)):
    for j in range(i+1, len(A)):
        C = A[i] * A[j]
        O.append(C)
for i in range(len(O)):
    B += O[i]
print(B)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        //コード
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<String, Integer> map = new HashMap<>();

        for(int i=0; i<=n; i++){
        	String a = sc.nextLine();
            if (map.containsKey(a)){
            	map.put(a,map.get(a)+1);
            }else{
            	map.put(a,1);
            }
        }

        // 2.Map.Entryのリストを作成する
        List<Entry<String, Integer>> list_entries = new ArrayList<Entry<String, Integer>>(map.entrySet());

        // 6. 比較関数Comparatorを使用してMap.Entryの値を比較する（降順）
        Collections.sort(list_entries, new Comparator<Entry<String, Integer>>() {
            //compareを使用して値を比較する
            public int compare(Entry<String, Integer> obj1, Entry<String, Integer> obj2)
            {
                //降順
                return obj2.getValue().compareTo(obj1.getValue());
            }
        });

        int count=0;
        ArrayList<String> la = new ArrayList<String>();
        // 5. ループで要素順に値を取得する
        for(Entry<String, Integer> entry : list_entries) {
        	if(count > entry.getValue()) {
        		break;
        	}else {
        		la.add(entry.getKey());
        	}
        	count = entry.getValue();
        }
        Collections.sort(la);
        for(int i=0;i<la.size();i++){
			System.out.println(la.get(i));
		}
    }
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i=0; i<n; ++i) cin >> s.at(i);
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  cout << (int)s.size() << endl;
  return 0;
}


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

int p[302][302];
int yoko[302][302];
int tate[302][302];

int main(){
	int N;
	cin >> N;
	int ans = -2e9;
	for(int i = 1 ; i <= N ; i++){
		for(int j = 1 ; j <= N ; j++){
			cin >> p[i][j];
			yoko[i][j] = tate[i][j] = p[i][j];
		}
	}
	for(int i = 1 ; i <= N ; i++){
		for(int j = 1 ; j <= N ; j++){
			yoko[i][j] += yoko[i][j-1];
			tate[i][j] += tate[i-1][j]; 
		}
	}
	// 1-line 
	for(int i = 1 ; i <= N ; i++){
		for(int l = 1 ; l <= N ; l++){
			for(int r = l ; r <= N ; r++){
				ans = max(ans,yoko[i][r] - yoko[i][l-1]);
				ans = max(ans,tate[r][i] - tate[l-1][i]);
			}		
		}
	}

	for(int u = 1 ; u <= N ; u++){
		for(int d = u+1 ; d <= N ; d++){
			int sub = -2e9;
			int mn = -(tate[d-1][1] - tate[u][1]);
			for(int i = 2 ; i <= N ; i++){
				sub = max(sub, (yoko[u][i] + yoko[d][i]) + (tate[d-1][i] - tate[u][i]) - mn );
				mn = min(mn, -(tate[d-1][i] - tate[u][i]) + (yoko[u][i-1] + yoko[d][i-1]) );
				
			}
			ans = max(ans,sub);
		}
	}
	cout << ans << endl;
}

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

using namespace std;

int mod(int a, int b){
  if(a>b)
    return a-b;
  return b-a;
}

long maximum(long a, long b)
{
  if(a>b)
    return a;
  return b;
}

int main(){
  int n;
  cin >> n;
  long a[n],b[n],c[n];
  for(int i=0;i<n;i++)
    cin >> a[i] >> b[i] >> c[i];
  long dpa[n],dpb[n],dpc[n];
  dpa[0]=a[0];
  dpb[0]=b[0];
  dpc[0]=c[0];
  for(int i=1;i<n;i++){
    /*dp[i] = minimum(dp[i+1]+mod(h[i],h[i+1]), dp[i+2]+mod(h[i],h[i+2]));
    long ans = maximum(
        maximum(
            maximum(a[i]+b[i+1], a[i]+c[i+1]), 
            maximum(b[i]+a[i+1], b[i]+c[i+1])),
            maximum(c[i]+a[i+1],c[i]+b[i+1]));
    dp[i] = ans+dp[i+2];*/
    dpa[i] = a[i]+maximum(dpb[i-1], dpc[i-1]);
    dpb[i] = b[i]+maximum(dpa[i-1], dpc[i-1]);
    dpc[i] = c[i]+maximum(dpa[i-1], dpb[i-1]);
  }
  cout << maximum(dpa[n-1], maximum(dpb[n-1], dpc[n-1])) << endl;
  return 0;
}

Measured memory_bytes: 8212
#include <iostream>
#include <string>
#include <vector>
 
int main(){
  unsigned long long H, W;
  std::cin >> H >> W;

  if((H == 1) || (W == 1)){
   	std::cout << 1 << std::endl;
    return 0;
  }
  
  auto HW = H*W;
  
  std::cout << (HW>>1) + (HW & 1) << std::endl;
  return 0;
}

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int N,K;
    cin>>N>>K;
    int ans = 0;
    while(N!=0){
        N = N/K;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3572
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scanf("%d\n%s", &n, &s)
	answer := rgb(n, s)
	fmt.Println(answer)
}

func rgb(n int, s string) int {
	var r, g, b int
	for i := 0; i < n; i++ {
		switch s[i] {
		case 'R':
			r++
		case 'G':
			g++
		case 'B':
			b++
		}
	}
	maxSkip := (n - 1) / 2
	cntToExclude := 0
	for i := 1; i <= maxSkip; i++ {
		for j := 0; j+2*i < n; j++ {
			if s[j] != s[j+i] && s[j] != s[j+2*i] && s[j+i] != s[j+2*i] {
				cntToExclude++
			}
		}
	}
	return r*g*b - cntToExclude
}


Measured memory_bytes: 1880
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, L, res;

int main() {
	cin >> N >> L;
	for (int i = L; i < L + N; ++i) {
		res += i;
	}
	if (L <= 0 && L + N - 1 >= 0) {
		res -= 0;
	}
	else if (L <= 0) {
		res -= L + N - 1;
	}
	else {
		res -= L;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
  int N, a, b;
  scanf("%d",&N);
  a = N%10;
  b = (N-a)/10;
  if(a!=9 && b!=9) printf("No\n");
  else printf("Yes\n");

  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 128
#define MOD 1000000007

int n, m, a[MAXN], f[MAXN][MAXN][MAXN], ans = 0;

int main() {
    scanf("%d", &n);
    m = (n << 1) - 1;
    for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
    std::sort(a + 1, a + m + 1);
    auto u = [](int &x, int y) {if((x+=y)>=MOD)x-=MOD; };
    f[n][a[n] != a[n - 1]][a[n] != a[n + 1]] = 1;
    for (int i = n; i > 1; i--) {
        int L = a[i - 1] != a[i - 2];
        int R = a[m - i + 2] != a[m - i + 3];
        for (int l = 0; l <= m; l++) {
            for (int r = 0; r <= m; r++) {
                int now = f[i][l][r];
                u(f[i - 1][l + L][r + R], now);
                for (int k = 0; k < l; k++) u(f[i - 1][k + L][r + R + 1], now);
                for (int k = 0; k < r; k++) u(f[i - 1][l + L + 1][k + R], now);
            }
        }
    }
    for (int i = 0; i <= m; i++)
        for (int j = 0; j <= m; j++)
            u(ans, f[1][i][j]);

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

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vs vector<string>
#define mii map<int, int>

void show(auto a){
  int i = 0;
  while(i < a.size()){
    cout<<a[i]<<" ";
    i++;
  }
  cout<<endl;
}

  double dp[311][311][311];

int main(){
  ios_base::sync_with_stdio(false);

  int n;
  cin>>n;

  int a = 0, b = 0, c = 0;

  for(int i = 0; i < n; i++){
  	int x;
  	cin>>x;
  	if(x == 1) a++;
  	else if(x == 2) b++;
  	else if(x == 3) c++;
  }


  for(int i = 0; i <= 310; i++){
  	for(int j=0;j<=310;j++)for(int k=0;k<=310;k++) dp[i][j][k] = 0;
  }

  for(int k = 0; k < 310; k++){
  	for(int j = 0; j + k< 310; j++){
  		for(int i = 0; i + j + k < 310; i++){
  			if(i == 0 && j == 0 && k == 0) continue;

  			if(i + j + k > 305) continue;

  			double zeros = 1.0*n/(i+j+k);
  			double pi =1.0 * i/(i+j+k);
  			double pj =1.0 * j/(i+j+k);
  			double pk =1.0 * k/(i+j+k);

  			if(i) dp[i][j][k] += pi*dp[i-1][j][k];
  			if(j) dp[i][j][k] += pj*dp[i+1][j-1][k];
  			if(k) dp[i][j][k] += pk*dp[i][j+1][k-1];

  			dp[i][j][k] += zeros;
  		}
  	}
  }
  cout<<setprecision(10);
  cout<<fixed;
  cout<<dp[a][b][c]<<endl;;

}

Measured memory_bytes: 235392
import java.io.*;
import java.util.*;

class Main {
  static final int MAX_N = 15;
  static final int MAX_BITS = (1 << MAX_N) - 1;

  static class RetBox {
    double time;
    ArrayList<Integer> ids;

    RetBox(double time, ArrayList<Integer> ids) {
      this.time = time;
      this.ids = ids;
    }
  }

  static class Storage {
    int id, dist, w;

    Storage(int id, int dist, int w) {
      this.id = id;
      this.dist = dist;
      this.w = w;
    }
  }

  static int[][] edges;
  static RetBox[][] pathhash;

  static String intJoin(int[] ns, String delim) {
    String out = "" + ns[0];
    for (int i = 1; i < ns.length; i++)
      out += delim + ns[i];
    return out;
  }

  static String intJoin(ArrayList<Integer> nlist, String delim) {
    String out = "" + nlist.get(0);
    for (int i = 1; i < nlist.size(); i++)
      out += delim + nlist.get(i);
    return out;
  }

  static RetBox check_path(int src, int bits, Storage[] strs, int w) {
    if (pathhash[src][bits] != null) return pathhash[src][bits];

    int n = strs.length;
    Storage stsrc = strs[src];

    int bits0 = (bits | (1 << src));
    int w0 = w + stsrc.w;

    double min_time = Double.POSITIVE_INFINITY;
    ArrayList<Integer> min_ids = null;

    for (int nxt = 0; nxt < n; nxt++) {
      if (((bits0 >> nxt) & 1) != 0) continue;

      RetBox nret = check_path(nxt, bits0, strs, w0);
      double time = nret.time + (double)edges[src][nxt] * (70 + w0) / 2000;

      if (min_time > time) {
        min_time = time;
        min_ids = new ArrayList<Integer>(nret.ids);
        min_ids.add(0, new Integer(stsrc.id));
      }
    }

    return (pathhash[src][bits] = new RetBox(min_time, min_ids));
  }

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

    int n = Integer.parseInt(br.readLine().trim());

    Storage[] strs = new Storage[n];

    for (int i = 0; i < n; i++) {
      String[] nums = br.readLine().trim().split(" ");
      strs[i] =
        new Storage(Integer.parseInt(nums[0]),
                    Integer.parseInt(nums[1]),
                    Integer.parseInt(nums[2]) * 20);
    }

    edges = new int[n][n];

    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
        edges[i][j] = edges[j][i] =
          Math.abs(strs[i].dist - strs[j].dist);

    pathhash = new RetBox[n][MAX_BITS];
    int nbits = (1 << n) - 1;

    for (int i = 0; i < n; i++) {
      ArrayList<Integer> ids0 = new ArrayList<Integer>(1);
      ids0.add(new Integer(strs[i].id));
      pathhash[i][nbits ^ (1 << i)] = new RetBox(i, ids0);
    }

    double min_time = Double.POSITIVE_INFINITY;
    ArrayList<Integer> min_ids = null;

    for (int src = 0; src < n; src++) {
      RetBox ret = check_path(src, 0, strs, 0);

      if (min_time > ret.time) {
        min_time = ret.time;
        min_ids = ret.ids;
      }
    }

    System.out.println(intJoin(min_ids, " "));
  }
}

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

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

Measured memory_bytes: 3068
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(1e5 + 5)], B[int(1e5 + 5)];
ll deg[int(1e5 + 5)];
bool visited[int(1e5 + 5)];

int main(){
  cin >> N;
  ll suma = 0, sumb = 0;
  for (int i = 0; i < N; i++) cin >> A[i], suma += A[i];
  for (int i = 0; i < N; i++) cin >> B[i], sumb += B[i];

  if (suma < sumb){
    cout << -1 << endl;
    return 0;
  }

  for (int i = 0; i < N; i++){
    deg[i] = A[i] - B[i];
  }
  sort(deg, deg + N);

  int ans = 0, R = N - 1;
  for (int i = 0; i < N; i++){
    if (deg[i] >= 0) break;
    ans++;
    while (deg[i] < 0){
      if (!visited[R]){
        ans++; visited[R] = true;
      }
      if (deg[i] + deg[R] >= 0){
        deg[R] += deg[i];
        deg[i] = 0;
        continue;
      }else{
        deg[i] += deg[R];
        R--;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5900
def main():
	number = int(input())
	li = list(map(int,input().split()))

	sum = 0
	min = li[0]
	max = li[0]

	for i in li:
		if i > max:
			max = i
		if i < min:
			min = i
		sum += i


	print(min,max,sum)


if __name__ == '__main__':
	main()


Measured memory_bytes: 6596
import Control.Monad
import Control.Applicative

solve :: [Int] -> String
solve [h,w] = 
    unlines . replicate h $ replicate w '#'

main =      
    mapM_ putStrLn =<< map solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = takeWhile (all (/= 0)) . map (map read . words)

Measured memory_bytes: 4544