akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<ll> v(n), h(n), t(m), s(m);
    vector<ll> vs(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> v[i] >> h[i];
        vs[i + 1] = vs[i] + v[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> t[i] >> s[i];
    }
    auto dp = make_v<ll>(m + 1, n + 1);
    fill_v(dp, -INF);
    dp[0][0] = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j <= n; j++) {
            if (t[i] - vs[j] < 0) {
                break;
            }
            if (j > 0) {
                if (dp[i + 1][j - 1] != -INF) {
                    chmax(dp[i + 1][j],
                          dp[i + 1][j - 1] +
                              (j > 1 ? abs(h[j - 1] - h[j - 2]) : 0) +
                              h[j - 1]);
                }
                if (dp[i][j - 1] != INF) {
                    chmax(dp[i + 1][j], dp[i][j - 1] + h[j - 1]);
                }
            }
        }
        for (int j = 0; j <= n; j++) {
            if (t[i] - vs[j] < 0) {
                break;
            }
            if (dp[i][j] != -INF) {
                chmax(dp[i + 1][j], dp[i][j]);
            }
        }
        for (int j = 0; j <= n; j++) {
            if (dp[i + 1][j] < s[i]) {
                dp[i + 1][j] = -INF;
            }
            // cout << i + 1 << " " << j << " " << dp[i + 1][j] << endl;
        }
    }
    for (int i = 0; i <= n; i++) {
        if (dp[m][i] != -INF) {
            cout << t[m - 1] - vs[i] << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}



Measured memory_bytes: 26620
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<Integer, Boolean> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            Boolean b = map.getOrDefault(a, false);
            if (b) {
                b = false;
            } else {
                b = true;
            }
            map.put(a, b);
        }

        System.out.println(map.values().stream().filter(b -> b).count());
    }
}


Measured memory_bytes: 50312
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	s2 := sort.StringSlice(strings.Split(s, ""))
	t2 := sort.StringSlice(strings.Split(t, ""))
	sort.Sort(s2)
	sort.Sort(sort.Reverse(t2))
	a := strings.Join(s2, "")
	b := strings.Join(t2, "")

	if a < b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e9
#define MOD (1000000000+7)

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

    int ans = 0;
    int min_s = 0;
    int max_s = 0;
    for(int i = 0;i < k;i++){
        min_s += i;
        max_s += n - i;
    }
    //cout << min_s << ' ' << max_s<<endl;
    ans = (ans%MOD + (max_s%MOD - min_s%MOD) + 1) % MOD;
    //cout << ans <<endl;

    for(int i = k+1;i <= n + 1;i++){
        min_s += i - 1;
        max_s += n - i + 1;
        /*
        for(int j = 0;j < i;j++){
            min_s += j;
            max_s += n - j;
            //cout << j << endl;
        }
        */
        //cout << min_s << ' ' << max_s<<endl;
        //cout << max_s - min_s + 1 << endl;
        ans = (ans%MOD +(max_s - min_s) + 1) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;


int main() {
  long double a, b; cin >> a >> b;
  cout << static_cast<ll>(a * b) << endl;
}


Measured memory_bytes: 3724
#include<iostream>
#include<climits>
int main()
{
    int imos[100003];
    for(int i = 0; i < 100003; i++)
    {
        imos[i] = 0;
    }
    int N;
    std::cin >> N;
    for(int i = 0; i < N; i++)
    {
        int a, b;
        std::cin >> a >> b;
        imos[a]++;
        imos[b + 1]--;
    }
    for(int i = 0; i < 100002; i++)
    {
        imos[i + 1] += imos[i];
    }
    int ninzu_max = INT_MIN;
    for(int i = 0; i < 100003; i++)
    {
        if(i - 1 <= imos[i])
        {
            ninzu_max = i;
        }
    }
    std::cout << ninzu_max - 1 << std::endl;
    return 0;
}


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

int main() {
  long long N,K;
  cin>>N>>K;
  if(N>K){
    N=N-(N/K)*K;
  }
  cout<<min(N,K-N);
}

Measured memory_bytes: 256
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl

using namespace std;

int main()
{
	int k,i,l=0;
	char s[1000];
	cin>>k;
	cin>>s;
	l=strlen(s);
	if(l<=k){
			cout<<s<<nl;
	}
	else{
		for(i=0;i<k;i++){
			cout<<s[i];
		}
		cout<<"..."<<nl;
	}
	return 0;
}
//Happy coading.....

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 998244353;
#define REP(i,j,n) for(int i=j;i<n;i++)
#define rep(i,n) REP(i,0,n)


ll dp[3010][3010];
// 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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    dp[0][0]  = 1;
    rep(i, c-a+1) rep(j, d-b+1)
    {
        if (i==0 && j==0) continue;

        if (i==0)
        {
            dp[i][j] = dp[i][j-1] * (i+a);
        }
        else if (j==0)
        {
            dp[i][j] = dp[i-1][j] * (j+b);
        }
        else
        {
            dp[i][j] = dp[i-1][j] * (j+b);
            dp[i][j] %= MOD;
            dp[i][j]+= dp[i][j-1] * (i+a);
            dp[i][j] %= MOD;
            ll tmp = (i+a-1) * (j+b-1) * dp[i-1][j-1];
            tmp %= MOD;
            tmp = MOD - tmp;
            dp[i][j] %= MOD;
            dp[i][j] = dp[i][j] + tmp;
            // dp[i][j] %= MOD;
        }
        dp[i][j] %= MOD;
    }
    cout << dp[c-a][d-b] << endl;
}


Measured memory_bytes: 74064
#include<bits/stdc++.h>
using namespace std;
int main(){
string s; cin>>s;
map<string,int> mp; 
mp["SUN"]=0; 
mp["MON"]=1; 
mp["TUE"]=2; 
mp["WED"]=3; 
mp["THU"]=4; 
mp["FRI"]=5; 
mp["SAT"]=6;
cout<<7-mp[s]<<endl; 
return 0;
} 

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

  public static void main(String[] args) {

    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n;
      String line,s;
      Map<String,String> map = new HashMap<>();
      StringBuilder buf = new StringBuilder(60000);
      while (true) {
        n = Integer.parseInt(br.readLine());
        if(n == 0) break;

        for(int i=0; i<n; i++) {
          line = br.readLine();
          map.put(line.substring(0,1), line.substring(2,3));
        }

        n = Integer.parseInt(br.readLine());
        for(int i=0; i<n; i++) {
          s = br.readLine();
          if(map.containsKey(s))
            buf.append(map.get(s));
          else
            buf.append(s);
        }
        buf.append("\n");
        map.clear();
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.err.println(e);
    }
  }
}


Measured memory_bytes: 36020
#include <bits/stdc++.h>
typedef long double ld;

using namespace std;

long double water_bottle( long double a, long double b, long double x){
  long double ans;
  if(a * a * b / 2.0 <= x) {
    ans = atan(2 * (a * a * b - x) / (a * a * a));
  } else {
    ans = M_PI / 2 - atan(2 * x / (a * b * b));
  }
  return ans * 180 /M_PI;
}

int main() {
  ld a, b, x;
  cin >> a >> b >> x;
  cout << fixed << setprecision(10);
  cout << water_bottle(a, b, x);
}

Measured memory_bytes: 3800
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, C: int, B: "List[int]", A: "List[List[int]]"):

    ans = 0
    for sources in A:
        total = sum([a * b for a, b in zip(sources, B)]) + C
        if total > 0:
            ans += 1
    print(ans)
    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    B = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    A = [
        [int(next(tokens)) for _ in range(M)] for _ in range(N)
    ]  # type: "List[List[int]]"
    solve(N, M, C, B, A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;

//long int ar[10013];
//long int gcd(long int a, long int b)
//{
//    if(b==0)
//        return a;
//    return gcd(b,a%b);
//}
//long int sieve(long long int a)
//{
//    long long int i,j,k = 0;
//    memset(ar,0,sizeof(ar));
//    ar[1] = 1;
//    for(i=2; i<=713; i++)
//    {
//        if(ar[i]==0)
//        {
//            for(j=i+i; j<=713; j+=i)
//            {
//                ar[j] = 1;
//            }
//        }
//    }
//    return ar[a];
//}

void Ok()
{
    long int a[1013],b,c,d,e,f,g,h,t,i,j,k,l,m,n;
    long int ans_1,ans_2,ans_3,cnt_1,cnt_2,cnt_3,Max,Min,flag_1,flag_2,temp,sum;
    double aa,bb,cc,dd,ee,ff,gg;
    char aaa,bbb,ccc,ddd;
    string spc,in,store[13];

    cin>>n>>m;
    for(i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    sum = 0;
    for(i=1;i<=m;i++)
        sum += a[i];
    cout<<sum<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 3636
n,a,b,c=map(int,input().split())
s=[input() for _ in range(n)]
abc=[a,b,c]
d={'A':0,'B':1,'C':2}
dr={0:'A',1:'B',2:'C'}
ans=[]
for i,x in enumerate(s):
  x=[d[y] for y in list(x)]
  if abc[x[0]]==abc[x[1]]==1 and i<n-1:
    nx=[d[y] for y in list(s[i+1])]
    for j,y in enumerate(x):
      if y in nx:
        abc[y]+=1
        abc[x[(j+1)%2]]-=1
        ans.append(dr[y])
        break
  elif abc[x[0]]>abc[x[1]]:
    abc[x[1]]+=1
    abc[x[0]]-=1
    ans.append(dr[x[1]])
  else:
    abc[x[0]]+=1
    abc[x[1]]-=1
    ans.append(dr[x[0]])
  for y in abc:
    if y<0:
      print('No')
      exit()
  
print('Yes')
print(*ans,sep='\n')

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

#define REP(i,n) for(int i = 0;i < n;i++)
#define REPR(i,n) for(int i = n-1;i >= 0;i--)
#define FOR(i,m,n) for(int i = m;i < n;i++)
#define PRINT(s) cout<<s
#define PRINTS(s) cout<<s<<' '
#define PRINTL(s) cout<<s<<endl
#define INF 2e9
#define ALL(v) v.begin(),v.end()
#define ll long long
#define GREATER greater<int>()

using namespace std;

string pop_back(string s){
    string t = s.substr(0,s.size()-1);
    return t;
}

int gcd(int max,int min){
    
    if(max<min){
        int tmp=max;
        max=min;
        min=tmp;
    }

    if(max%min==0)return min;
    else return gcd(min,max%min);

}

int main(void){

    string s;
    cin>>s;
    
    int ans=INF;
    for(int i=0;i<s.size()-2;i++){
        int n=stoi(s.substr(i,3));
        if(ans>abs(753-n))ans=abs(753-n);
    }
    cout<<ans<<endl;

    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int D, N, i, ans;
  scanf("%d %d", &D, &N);
  if(D==0) ans = 1;
  if(D==1) ans = 100;
  if(D==2) ans = 10000;

  if(N==100) printf("%d\n", 101*ans);
  else printf("%d\n", N*ans);

  return 0;
}

Measured memory_bytes: 128
n = gets.to_i
xs = gets.chomp.split.map(&:to_i).sort
min = 10**9
xs[0].upto(xs[-1]) do |i|
  sum = 0
  xs.each do |x|
    sum += (x - i) ** 2
  end
  min = sum if sum < min
end
puts min

Measured memory_bytes: 1788
import java.util.Scanner;

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

    //input
    int a = sc.nextInt();

    //output
    int output = (int)(a+Math.pow(a,2)+Math.pow(a,3));
    System.out.println(output);

  }
}


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

using namespace std;

int main() {
    string s;
    int p = 0, p1, p2;
    getline(cin, s);
    while (1) {
        p1 = s.find("peach", p);
        p2 = s.find("apple", p);
        if (p1 == -1 && p2 == -1) {
            break;
        }

        if (p2 == -1) {
            s.replace(p1, 5, "peach");
            p = p1 + 1;
        }
        else if (p1 == -1){
            s.replace(p2, 5, "peach");
            p = p2 + 1;
        }
        else if (p1 < p2) {
            s.replace(p1, 5, "apple");
            p = p1 + 1;
        }
        else {
            s.replace(p2, 5, "peach");
            p = p2 + 1;
        }
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 1180
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;

int n, m;
int num[305], last[305][305], Max[305];
bool vis[305];
int a[305][305];

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++) { 
		for(int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
		Max[i] = 1; num[a[i][Max[i]]]++;
	}
	int ans = n;
	for(int k = 1; k < m; k++) {
		int p = 0, t = 0;
		for(int j = 1; j <= m; j++) 
			if(num[j] > t) p = j, t = num[j];
		ans = min(t, ans); vis[p] = 1;
		for(int i = 1; i <= n; i++) 
			while(vis[a[i][Max[i]]]) {
				num[a[i][Max[i]]]--;
				Max[i]++;
				num[a[i][Max[i]]]++;
			}
	}
	printf("%d\n", ans);
}

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

int main(){

    int N,count;
    count=0;
    cin >>N;
    vector<int> p(N);
    for (int i=0;i<N;i++){
      cin >>p.at(i);
      }

    vector<int> q(N);
    q=p;
    sort(q.begin(),q.end());
    count=0;
    for (int i=0;i<N;i++){
      if(q.at(i)!=p.at(i))count++;
    }
    string ans="NO";
    if(count<3){
      ans="YES";
    }

    cout<<ans<<endl;


}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll h,w ;
	cin >> h >> w ;
	vvc g(h+2,vc(w+2,'.')) ;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin >> g.at(i).at(j) ;
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(g.at(i).at(j)=='#') continue ;
			ll cnt = 0 ;
			for(int a=-1;a<=1;a++){
				for(int b=-1;b<=1;b++){
					cnt += (g.at(i+a).at(j+b)=='#') ;
				}
			}
			g.at(i).at(j) = '0'+cnt ;
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cout << g.at(i).at(j)  ;
		}
		cout << endl ;
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define INF 100000000
int main(){
  int d[11][11];
  int n;
  while(cin>>n){
    if(n==0) break;
    int a,b,c;
    for(int i=0;i<=10;i++){
      for(int j=0;j<=10;j++) d[i][j] = INF;
    }
    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      d[a][b] = d[b][a] = c;
    }
    for(int k=0;k<=10;k++)
      for(int i=0;i<=10;i++)
	for(int j=0;j<=10;j++) d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
    /*for(int i=0;i<=10;i++){
      for(int j=0;j<=10;j++) cout << d[j][i] << ' ';
      cout << endl;
      }*/
    int s,ans = INF,ansi;
    for(int i=0;i<=10;i++){
      if(d[i][i]==INF) continue;
      s = 0;
      for(int j=0;j<=10;j++) if(i!=j&&d[i][j]!=INF) s += d[i][j];
      //cout << s << endl;
      if(s<ans){
	ans = s;
	ansi = i;
      }
    }
    cout << ansi << ' ' << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main() {

  ll k,a,b;
  cin >> k >> a >> b;

  bool ans = false;

  for(ll i = a; i <= b ; ++i)
  {
    if(i % k == 0)
      ans = true;
  }


  if( ans) cout << "OK" << endl;
  else cout << "NG" << endl;







  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define INF	123456789

int N, A[11234];
int memo_A[11234];
int bound[11234][3][2];
int ans = INF;

int how_same(int num, int color) {
	int s1 = 0, s2 = 0;
	for (int i = num + 1; i < N; ++i) {
		if (A[i] == color) { ++s1; }
		else if (A[i] != -1) {
			bound[num][color][0] = i - 1;
			break;
		}
	}
	for (int i = num - 1; i >= 0; --i) {
		if (A[i] == color) { ++s2; }
		else if (A[i] != -1) {
			bound[num][color][1] = i + 1;
			break;
		}
	}
	return s1 + s2 + 1;
}

int solve(int num, int color) {
	int res = 0;
	res += how_same(num, color);
	if (res >= 4) {
		for (int i = bound[num][color][1]; i <= bound[num][color][0]; ++i) { A[i] = -1; }
		if (A[bound[num][color][1] - 1] == A[bound[num][color][0] + 1]) {
			res += solve(bound[num][color][0] + 1, A[bound[num][color][0] + 1]);
		}
		else {
			int tmp = 0;
			tmp += how_same(bound[num][color][0] + 1, A[bound[num][color][0] + 1]);
			if (tmp < 4) { tmp = 0; }
			tmp += how_same(bound[num][color][1] - 1, A[bound[num][color][1] - 1]);
			if (tmp < 4) { tmp = 0; }
		}
	}
	if (res < 4) { res = 0; }
	return res;
}

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }
		memset(bound, 0, sizeof(bound));
		ans = INF;
		for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); }

		for (int i = 0; i < N; ++i) { memo_A[i] = A[i]; }
		for (int i = 1; i < N - 1; ++i) {
				for (int j = 1; j <= 3; ++j) {
					ans = std::min(ans, N - solve(i, j));
					for (int k = 0; k < N; ++k) {
						A[k] = memo_A[k];
					}
				}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;

double dp[3007][3007] = {};
double p[3007] = {};

int main() {
	
	int i,j;
	int N;
	
	scanf("%d", &N);
	for( i=1; i<=N; i++) {
		scanf("%lf", &p[i]);
	}
	dp[0][0] = 1;
	for( i=1; i<=N; i++) {
		dp[i][0] = dp[i-1][0] * ( 1-p[i]);
		for( j=1; j<=N; j++) {
			dp[i][j] += dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]);
		}
	}
	double ans = 0;
	for( i=N/2+1; i<=N; i++)
		ans += dp[N][i];
	printf("%.15f\n", ans);
	
	return 0;
}

Measured memory_bytes: 74284
import math
import bisect
import copy
#import time
import itertools
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input()))
l=[]
h,w,k=map(int,input().split())
for i in range(h):
	l.append(list(input()))

ccc=0
black=0
bl=0
for i in range(h):
	for j in range(w):
		if l[i][j]=='#':
			bl+=1

a=[i for i in range(64)]
b=[i for i in range(64)]
c=list(itertools.product(a,b))
for i in range(len(c)):
	a1=bin(c[i][0])[2:]
	b1=bin(c[i][1])[2:]
	if len(a1)>h:
		continue
	if len(b1)>w:
		continue
	if len(a1)<h:
		a1='0'*(h-len(a1))+a1
	if len(b1)<w:
		b1='0'*(w-len(b1))+b1
	row=0
	col=0
	for i in range(h):
		if a1[i]=='0':
			continue
		for j in range(w):
			if l[i][j]=='#':
				row+=1

	for i in range(w):
		if b1[i]=='0':
			continue
		for j in range(h):
			if l[j][i]=='#' and a1[j]!='1':
				col+=1
	if row+col==bl-k:
		ccc+=1

print(ccc)




Measured memory_bytes: 76204
(function set_utils(undefined){
	this.print_float = function print_float(val, base, pad, prec) {
		var p10=Math.pow(10,prec);
		var ival=""+Math.round(val*p10);
		if ( ival === '0' )
			return '0.'+Array(prec+1).join('0');
		var ilen=ival.length-prec;
		if(ilen===0)
			return "0."+ival.substr(ilen,prec);
		return ival.substr(0,ilen)+"."+ival.substr(ilen,prec);
	};
}).call(global);

(function(undefined){
	'use strict';

	(function init() {
		this.output = function() {
			console.log.apply( console, arguments );
		};
		this.stdin = process.openStdin();
		stdin.setEncoding('utf8');
		this.input_list = [];
		stdin.on('data', function(chunk){
			var result = chunk.match(/[-]?\d+/g);
			input_list = input_list.concat(result);
		});
		stdin.on('end', function(){
			fire();
		});
		this.input_number = function() {
			return parseInt( input_list.splice(0,1)[0] );
		};
		this.has_next = function() {
			return ! input_list.length;
		};
	}).call( this );

	(function solver(){
		function sq(x) {
			return x * x;
		}
		function check(v) {
		}
		this.fire = function() {
			setTimeout( function solve() {
				var a = input_number();
				var b = input_number();
				var c = input_number();
				var d = input_number();
				var e = input_number();
				var f = input_number();
				var delta = 1.0 / ( a*e - b*d );
				var x = ( e * c - b * f ) * delta;
				var y = ( a * f - d * c ) * delta;
				output( print_float(x,10,3,3) + ' ' + print_float(y,10,3,3)  );
				if ( ! has_next() )
					setTimeout( solve, 0, this );
			}, 0, this );
		};
	}).call(this);

}).call(global);

Measured memory_bytes: 8100
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
char s[4];
int main()
{
	scanf("%s",s+1);
	if(s[2]=='B')puts("ARC");
	else puts("ABC");
	return 0;
}


Measured memory_bytes: 3688
import sys

def debug(*args):
    print(*args, file=sys.stderr)


def solve(N, A):
    S = sorted(A)
    cnt = sum(x != y for x, y in zip(A, S))
    if cnt in (0, 2):
        return "YES"
    return "NO"

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    print(solve(N, A))

main()



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

using namespace std;

int main()
{
    int n,a,flag=1,s;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
    }

   for(int i=0;i<n-1;i++)
   {
       if(v[i]>=v[i+1])
       {
           if(v[i]-v[i+1]>1)
           {
               cout<<"No"<<endl;
               return 0;
           }
           else if(v[i]-v[i+1]==1)
           {
              v[i]--;
           }
           else if(v[i]==v[i+1])
           {
               if(i == 0) v[i]--;
               else
                {
                  if(v[i-1]!=v[i])
                  {
                    v[i]--;
                  }
                }
           }
        }
   }
   for(int i=0;i<n-1;i++)
   {
       if(v[i]>v[i+1]){cout<<"No"<<endl;return 0;}
   }
   cout<<"Yes"<<endl;
    return 0;
}


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

using namespace std;

// O(log(small10)N)
int countDigits(int64_t num) {
    int count = 0;
    while (num > 0) {
        num /= 10;
        count++;
    }
    return count;
}

int main() {
    int64_t N;  // 1 <= N <= 10^10
    cin >> N;

    vector<int64_t> divisors;  // 約数の配列

    // 考え方メモ
    // A * B == N -> B == N / A
    // 約数を見つける際に、どこまで数を調べればよいか？
    // 交換法則が成り立つから、約数を求める場合、A <= Bと置くことができる。
    // A <= B の時、A * B = N -> A^2 <= N -> A <= sqrt(N)

    // O(N) -> 10^10 -> ボトルネック
    // O(sqrt(N)) -> 10^5 < 10^8 -> ボトルネック解消
    for (int64_t i = 1; i <= sqrt(N); i++) {  // 約数を求める
        bool canDvide = !(N % i);
        if (canDvide) divisors.push_back(i);
    }

    int maxDigits = 0;
    for (int i = 0; i < divisors.size(); i++) {
        int currentMaxDigits = max(countDigits(divisors.at(i)), countDigits(N / divisors.at(i)));
        maxDigits = (maxDigits, currentMaxDigits);
    }

    cout << maxDigits << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define ll long long int
#define vr vector
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define loop(i,n) for(i=0;i<n;i++)
#define inp !cin.eof()
#define sec itr->second
#define fir itr->first

ll power(ll x,ll y,ll p)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x)%p;

        // y must be even now
        y = y>>1; // y = y/2
        x = ((x%p)*(x%p))%p;  // Change x to x^2
    }
    return res%p;
}


int main()
{
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     // iterating a loop until input is providing====!cin.eof()
     //ll t; cin>>t;

     //scanf("%lld",&t);
     //while(t--)
        {

         ll n,m,q,i,x,y,p=1,z,j,k,flag=1,cnt=0,mi=mod,c=0,sum=0,ma=0,ans=0;
          vr<ll> v,v1,v2;


            cin>>n;
            if(n>=30)
                cout<<"Yes";
            else
                cout<<"No";

              cout<<endl;
          }


    return 0;

}



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

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll n;
v1 a;
ll sign = 0;
ll unsign = 0;
ll zero = 0;
ll ans = 0;

int main(){
    cin >> n;
    a = v1(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
    }
    for(ll i = 0;i < n;i++){
        if(a[i] > 0){
            sign++;
        }else if(a[i] < 0){
            unsign++;
        }else{
            zero++;
        }
    }
    if(zero > 0){
        for(ll i = 0;i < n;i++){
            ans += abs(a[i]);
        }
    }else if(unsign % 2 == 0){
        for(ll i = 0;i < n;i++){
            ans += abs(a[i]);
        }
    }else{
        ll min_a = abs(a[0]);
        for(ll i = 0;i < n;i++){
            ans += abs(a[i]);
            min_a = min(min_a, abs(a[i]));
        }
        ans -= min_a * 2;
    }
    cout << ans << endl;



}


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

public class Main {
    public static void main(String[] args) {
        Solver s = new Solver();
        s.solve();
    }
}

class Solver {
    Reader in = new Reader();
    Writer out = new Writer();

    void solve() {
        int a = in.nextInt();
        int b = in.nextInt();
        int c = a * 3 + b;
        int d = c / 2;
        out.println(d);
        out.flush();
    }
}

class Reader {
    private StringTokenizer a;
    private BufferedReader b;

    Reader() {
        a = null;
        try {
            b = new BufferedReader (new InputStreamReader (System.in)); // for file IO, replace this with new FileReader ("in.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String next () {
        while(a == null || !a.hasMoreTokens()) {
            try {
                a = new StringTokenizer (b.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a.nextToken();
    }

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

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

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

    public String nextLine() {
        try {
            return b.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}

class Writer {
    private PrintWriter a;
    private StringBuffer b;

    Writer() {
        try {
            a = new PrintWriter (System.out); // for file IO, replace this with new FileWriter ("out.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
        b = new StringBuffer ("");
    }

    public void print(Object s) {
        b.append(s);
    }

    public void println(Object s) {
        b.append(s).append('\n');
    }

    public void flush() {
        a.print(b);
        a.flush();
        a.close();
    }
}

Measured memory_bytes: 22484
#include <stdio.h>

int main(){
     int a,b,d,r;
     double f;
      scanf("%i %i",&a,&b);
      d = a/b;
      r = a%b;
      f = (double)a/b;
       printf("%i %i %lf\n",d,r,f);
        return 0;
     } 



Measured memory_bytes: 2116
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int a[5], i, j, r, p, s, w, l;
	while (fscanf(stdin, "%d", &a[0]), a[0]) {
		fscanf(stdin, "%d%d%d%d", &a[1], &a[2], &a[3], &a[4]);
		r = p = s = 0;
		for (i = 0; i < 5; i++) {
			if (a[i] == 1) r++;
			else if (a[i] == 2) s++;
			else p++;
		}
		if (r == 5 || s == 5 || p == 5) { i = 5; while (i--)P(d, 3); }
		else if (r == 0 || s == 0 || p == 0) {
			if (r&&s) w = 1;
			else if (r&&p) w = 3;
			else w = 2;
			for (i = 0; i < 5; i++) P(d, a[i] == w ? 1 : 2);

		}
		else { i = 5; while (i--)P(d, 3); }
	}
	return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <algorithm>

using namespace std;



int main(){
	int a,b,c,d,e,table[14],pair,three,four;
	bool st_FLG;

	while(scanf("%d,%d,%d,%d,%d",&a,&b,&c,&d,&e) != EOF){
		for(int i=1;i <= 13;i++)table[i] = 0;
		pair = three = four = 0;
		st_FLG=false;
		table[a]++;
		table[b]++;
		table[c]++;
		table[d]++;
		table[e]++;

		for(int i=1;i<=13;i++){
			if(table[i] == 2)pair++;
			else if(table[i] == 3)three++;
			else if(table[i] == 4)four++;
			if(i >= 5 && table[i] == 1 && table[i-1] == 1 && table[i-2] == 1 && table[i-3] == 1 && table[i-4]== 1)
				st_FLG = true;
		}

		if(four == 1){
			printf("four card\n");
		}else if(pair == 1 && three == 1){
			printf("full house\n");
		}else if(three == 1){
			printf("three card\n");
		}else if(pair == 2){
			printf("two pair\n");
		}else if(pair == 1){
			printf("one pair\n");
		}else if((st_FLG == true) || (table[10] == 1 && table[11] == 1 && table[12] == 1 && table[13] == 1 && table[1] == 1)){
			printf("straight\n");
		}else{
			printf("null\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2504
#include <bits/stdc++.h>
#include <vector>
#include <string.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
//#define INF 2e9
#define ALL(v) v.begin(), v.end()
 
using namespace std;
typedef long long ll;

int main(){
  int n;
  int res = 0;
  bool result = false;
  cin >> n;
  int D1,D2;
  rep(i,n){
    cin >> D1 >> D2;
    if(D1 == D2) res += 1;
    else res = 0; 
    if(res == 3) result = true;
  }
  if(result) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#define ll long long int
#define endl "\n"

using namespace std;

int main(){
    int N;
    cin>>N;
    int a[N+1], b[N+1], c[N+1];
    for(int i = 1;i<N+1;i++)
        cin>>a[i]>>b[i]>>c[i];
    int dp[3][N];
    for(int i = 0;i<3;i++)
        dp[i][0] = 0;
    for(int i = 1;i<N;i++){
        for(int j = 0;j<3;j++){
            if(j==0)
                dp[j][i] = max(b[i] + dp[1][i-1], c[i] + dp[2][i-1]);
            else if(j==1)
                dp[j][i] = max(a[i] + dp[0][i-1], c[i] + dp[2][i-1]);
            else
                dp[j][i] = max(a[i] + dp[0][i-1], b[i] + dp[1][i-1]);
        }
    }
    cout<<max(a[N]+dp[0][N-1], max(b[N]+dp[1][N-1], c[N]+dp[2][N-1]))<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int main(){
    int A, B;
    int ans = 0;
    cin >> A >> B;
    for(int i = A; i <= B; i++){
        string I = to_string(i);
        if(I[0] == I[4] && I[1] == I[3])ans++;
    }
    print(ans);
}

Measured memory_bytes: 256
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  order = True
  for _ in range(n):
    q = list(input_list_str())
    if len(q) == 1:
      order = False if order else True
      continue
    t, f, c = q
    if int(f) == 1:
      if order:
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if order:
        s.append(c)
      else:
        s.appendleft(c)
  if order is False:
    s.reverse()
  print(''.join(s))

    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 10556
//
// Created by Chisec Coin on 17/7/15.
//

#include <iostream>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <sstream>
#include <map>
const int NIL = -1;
typedef long long ll;
using std::cin;using std::cout;using std::endl;using std::max;using std::min;

int main() {
    int a, b;
    cin >> a >> b;
    if (a + b == 0) {
        cout << "Impossible" << endl;
        return 0;
    }
    if (a % 3 == 0) {
        cout << "Possible" << endl;
    } else if (b % 3 == 0) {
        cout << "Possible" << endl;
    } else if ((a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a[100001],b[100001],c[100001],n,dp[100001][3];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	dp[1][0]=a[1];dp[1][1]=b[1];dp[1][2]=c[1];
	for(int i=2;i<=n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
	}
	printf("%d",max(max(dp[n][0],dp[n][1]),dp[n][2]));
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	char s[200];
	cin>>n>>s;
	for(int i=0;i<strlen(s);i++)
	{
		if(i<n)
		{
			cout<<s[i];
		}
		else
		if(i<strlen(s))
		{
			cout<<"...";
			break;
		}
		
	}
}

Measured memory_bytes: 3636
<?php
 fscanf(STDIN,"%d%d",$n,$m);
$citys = array();
 for($i=0;$i<$m;$i++){
   $p_y = explode(" ",trim(fgets(STDIN)));
   $pref[$p_y[0]][] = $p_y[1];
   $py_li[] = $p_y;
 }
 

//昇順にする
$p_y_key_li = array_keys($pref);
for($i=0;$i<count($p_y_key_li);$i++){
  sort($pref[$p_y_key_li[$i]]);
}

$memo = array();

//print_r($pref);
foreach($pref as $c){
  foreach($c as $x => $year){
    $memo[$year] = $x;
  }
}

//print_r($memo);

foreach($py_li as $py){
  $x = $memo[$py[1]]+1;
  for($i=0;$i<6-strlen($py[0]);$i++){
    echo "0";
  }
  echo $py[0];
   for($i=0;$i<6-strlen($x);$i++){
    echo "0";
  }
  echo ($x)."\n";
}
//print_r($pref);


Measured memory_bytes: 115944
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>

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

template<typename T> bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N,C;
    cin>>N>>C;
    vvll D(C,vll(C));
    for(ll i=0;i<C;i++){
        for(ll j=0;j<C;j++){
            cin>>D[i][j];
        }
    }
    vvll c(N,vll(N));
    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            cin>>c[i][j];
            c[i][j]--;
        }
    }
    
    vvll count(3,vll(C,0));
    
    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            count[(i+j)%3][c[i][j]]++;
        }
    }
    
    vvll U(3,vll(C,0));
    for(int i=0;i<3;i++){
        for(ll j=0;j<C;j++){
            U[i][j]=0;
            for(ll k=0;k<C;k++){
                if(k==j)continue;
                U[i][j]+=count[i][k]*D[k][j];
            }
        }
    }
    
    ll ans=LLMAX;
    for(ll i=0;i<C;i++){
        for(ll j=0;j<C;j++){
            for(ll k=0;k<C;k++){
                if(i==j || j==k || k==i)continue;
                if(U[0][i]+U[1][j]+U[2][k]<ans)ans=U[0][i]+U[1][j]+U[2][k];
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


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

int main()
{
	const long long DIV =1000000007;

	int N;
	cin >> N;

	long long res = 1;
	for (int i = 1; i <= N; i++)
		res = (res * i) % DIV;
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = 0;
const int mod = 998244353;

priority_queue<int, vector <int>, greater<int>> pq;
int x, y, a, b, c;
vector <int> red, green, colorless;
int32_t main()
{
    usecppio
    cin >> x >> y >> a >> b >> c;
    for (int i = 0; i<a; i++)
    {
        int u; cin >> u; red.push_back(u);
    }
    for (int i = 0; i<b; i++)
    {
        int u; cin >> u; green.push_back(u);
    }
    for (int i = 0; i<c; i++)
    {
        int u; cin >> u; colorless.push_back(u);
    }
    sort(all(red),greater<int>());
    sort(all(green),greater<int>());
    sort(all(colorless),greater<int>());
    for (int i = 0; i<x; i++)
        pq.push(red[i]);
    for (int i = 0; i<y; i++)
        pq.push(green[i]);
    for (auto it:colorless)
    {
        if (pq.top() < it)
        {
            pq.pop();
            pq.push(it);
        }
    }
    int ans = 0;
    while(!pq.empty())
    {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5748
t = int(input())
dp = [[0 for i in range(3)] for j in range(t)]
for i in range(t):
    var = list(map(int, input().split()))
    for j in range(3):
        if i == 0:
            dp[i][j] = var[j]
        else:
            for k in range(3):
                if j != k:
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + var[j])
print(max(dp[-1]))


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





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

    long long int a,b,c,d,i,j,k,n,m;
    cin>>n;
    long long int ar[n+1],dp[n+1];
    for(i=0;i<n;i++)
        cin>>ar[i];
     dp[0]=0;
    dp[1]=abs(ar[1]-ar[0]);
    for(i=2;i<n;i++)
    {
        a=dp[i-1]+abs(ar[i]-ar[i-1]);
        b=dp[i-2]+abs(ar[i]-ar[i-2]);
        dp[i]=min(a,b);
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

A.append(float("INF"))
AB = [0] * (N+1)
j = 0
for i in range(N):
    while A[j] < B[i]:
        j += 1
        if j == N:
            break
    AB[i+1] = AB[i] + j

ans = 0
B.append(float("INF"))
j = 0
for i in range(N):
    while B[j] < C[i]:
        j += 1
        if j == N:
            break
    ans += AB[j]

print(ans)

Measured memory_bytes: 29120
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,c;
map<string,int> m;
int main()
{
	cin>>n;
	string s;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		m[s]++;
	}
	map<string,int>::iterator it;
	int ma=0;
	for(it=m.begin();it!=m.end();it++)
		ma=max(ma,it->second);
	for(it=m.begin();it!=m.end();it++)
		if(it->second==ma)
			cout<<it->first<<endl;	
} 

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

using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio { ios_base::sync_with_stdio(false), cin.tie(NULL); }
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

#ifdef RICARDO
//Header here
	#include "E:\\Code\\dbg.h"
#else
	#define bug(...) "RICARDO MILOS"
#endif


template<class T> bool mini(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool maxi(T &a, T b) { return a < b ? (a = b, true) : false; }

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

//=================================================CODE=================================================//

signed main()
{	
	fastio;
	cout.precision(10);
	cout << fixed;
#ifdef RICARDO		
	freopen("i", "r", stdin);
#endif
	int n, m; cin >> n >> m;
	vi64 a(n);
	for1(i, n - 1) cin >> a[i], a[i] += a[i - 1];
	vvi b(n + 1, vi(m + 1));
	for1(i, n) for1(j, m) cin >> b[i][j];

	vvi64 f(n + 2, vi64(n + 2));
	auto upd = [&](int i1, int i2, int j1, int j2, int val) {
		f[i1][j1] += val;
		f[i1][j2 + 1] -= val;
		f[i2 + 1][j1] -= val;
		f[i2 + 1][j2 + 1] += val;
	};

	vector<list<int>> q(m + 1);
	vvi64 up(n + 1, vi64(m + 1));
	vvi64 dw(n + 1, vi64(m + 1));

	for1(i, n) for1(j, m) {
		int v = b[i][j];
		while(q[j].size() && b[q[j].back()][j] <= v) q[j].pop_back();
		up[i][j] = q[j].size() ? q[j].back() + 1 : 1;
		q[j].pb(i);
	}

	for(auto &e : q) e.clear();
	for(int i = n; i; i--) for(int j = m; j; j--) {
		int v = b[i][j];
		while(q[j].size() && b[q[j].back()][j] < v) q[j].pop_back();
		dw[i][j] = q[j].size() ? q[j].back() - 1 : n;
		q[j].pb(i);
	}

	for1(i, n) for1(j, m) upd(up[i][j], i, i, dw[i][j], b[i][j]);	

	i64 ANS = 0;
	for1(i, n) for1(j, n) {
		f[i][j] += f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
		if(i <= j) maxi(ANS, f[i][j] - (a[j - 1] - a[i - 1]));
	}
	cout << ANS << endl;
#ifdef RICARDO
	cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

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

using namespace std;

typedef long long ll;

int n, m;
int a[1003]; 
int m_itens = 0, total_votes = 0;
double a_d[1000];
double n_d, m_d, total_votes_d = 0.0;
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

 
    cin >> n >> m;

    n_d = n*1.0;
    m_d = m*1.0;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        a_d[i] = a[i]*1.0;
        total_votes_d += a_d[i];
    }

    for (int i = 0; i < n; i++){
        if (a_d[i] >= (1.0/((4.0)*m_d))*total_votes_d){
            m_itens++;
        }
    }

    if (m_itens >= m){
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}


Measured memory_bytes: 3672
import math

N, D = list(map(int, input().split()))
Xs = [[0 for _ in range(D)] for _ in range(N)]
for i in range(N):
    Xs[i] = list(map(int, input().split()))


def distisint(a, b):
    dsq = 0
    for i in range(D):
        dsq += (Xs[a][i] - Xs[b][i]) ** 2
    d = math.sqrt(dsq)
    return math.floor(d) ** 2 == dsq


c = 0
for i in range(0, N - 1):
    for j in range(i + 1, N):
        if distisint(i, j):
            c += 1
print(c)

Measured memory_bytes: 38256
n, k = map(int, input().split())
s = input()
ss = []
ss.append(0)
for i in range(n-1):
  a = s[i]
  if a == s[i+1]:
    continue
  ss.append(i+1)
ss.append(n)

ans = 0
for i in range(len(ss)):
  p = ss[i]
  if p == n:
    break
  if s[p] == "0":
    ans = max(ans, ss[min(2 * k + i, len(ss) - 1)] - ss[i])
  else:
    ans = max(ans, ss[min(2 * k + 1 + i, len(ss) - 1)] - ss[i])
print(ans)

Measured memory_bytes: 12872