akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N;

int main() {
    cin >> N;
    int z = N%10;
    vector<int> a = {2,4,5,7,9}, b = {0,1,6,8};
    if (z == 3) cout << "bon" << endl;
    else if (find(ALL(a), z)  != a.end() ) cout << "hon" << endl;
    else if (find(ALL(b), z)  != b.end() ) cout << "pon" << endl;
}


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

A.sort(reverse = True)

x = A[0]
y = 0
temp = 0

for yy in A:
    d = min(yy, x-yy) # dが大きいと良い
    if d > temp:
        temp = d
        y = yy

ans = (x,y)
print(*ans)

Measured memory_bytes: 14052
N, M = map(int, input().split())
box = [1] * N
red = [1]
red.extend([0] * (N - 1))

for i in range(M):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    
    if red[x] == 1:
        if box[x] == 1:
            red[x] = 0
        red[y] = 1
    
    box[x] -= 1
    box[y] += 1


print(sum(red))


Measured memory_bytes: 5364
#include <iostream>
    #include <vector>
    #include <algorithm>
     
    using namespace std;
     
    void solve() {
        int n;
        cin >> n;
     
        vector<int64_t> a(n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
     
        sort(a.begin(), a.end());
     
        vector<int64_t> b;
        for(int i = 0; i < n-1; i++){
            if(a[i] == a[i+1]) {
                b.push_back(a[i]);
                i++;
            }
        }
     
        int64_t result = 0;
        for(int i = 0; i < b.size(); i++){
            for(int j = i+1; j < b.size(); j++){
                result = max(result, b[i]*b[j]);
            }
        }
     
        cout << result << endl;
    }
     
    int main() {
        solve();
        return 0;
    }

Measured memory_bytes: 1660
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());
        int[] cost = new int[M];
        int[] openable = new int[M];
        for (int i = 0; i < M; i++) {
            cost[i] = Integer.parseInt(scanner.next());
            int b = Integer.parseInt(scanner.next());
            for (int j = 0; j < b; j++) {
                openable[i] |= 1 << (Integer.parseInt(scanner.next()) - 1);
            }
        }

        int[][] dp = new int[M + 1][1 << N];
        for (int[] d: dp) {
            Arrays.fill(d, Integer.MAX_VALUE);
        }
        dp[0][0] = 0;
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < 1 << N; j++) {
                if (dp[i][j] != Integer.MAX_VALUE) {
                    dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j]);
                    dp[i + 1][j | openable[i]] =
                            Math.min(dp[i + 1][j | openable[i]], dp[i][j] + cost[i]);
                }
            }
        }

        System.out.println(dp[M][(1 << N) - 1] == Integer.MAX_VALUE ? -1 : dp[M][(1 << N) - 1]);
    }
}


Measured memory_bytes: 52416
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    set<string> id;
    for(int i=0; i<n; ++i){
        string s;
        cin >> s;
        id.insert(s);
    }

    int m;
    cin >> m;

    bool open = false;
    for(int i=0; i<m; ++i){
        string s;
        cin >> s;
        if(id.find(s) == id.end()){
            cout << "Unknown " << s << endl;
        }else if(open){
            cout << "Closed by " << s << endl;
            open = false;
        }else{
            cout << "Opened by " << s << endl;
            open = true;
        }
    }

    return 0;
}

Measured memory_bytes: 1232
import math

# A:時針の長さ
# B:分針の長さ
# H:時間
# M:分
A, B, H, M = map(int, input().split())

# 時針のなす角
H_angle = H * 30 + (M / 60 * 30)
# 分針のなす角
M_angle = M * 6

# 針のなす角
H_M_angle = abs(H_angle - M_angle)

cosHM = math.cos(math.radians(H_M_angle))

C2 = A**2 + B**2 - 2*A*B*cosHM

print(math.sqrt(C2))

Measured memory_bytes: 9504
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   int n;
   cin >> n;
   vector<int> p(n),q(n),o(n);
   rep(i,n)
   cin >> p[i];
   rep(i,n)
   {
      cin >> q[i]; 
      o[i]=i+1;
   }

   int a,b;
   int now=1;
   do{
      bool c =true,d=true;
      rep(i,n)
      {
         if(o[i]!=p[i])c=false;
         if(o[i]!=q[i])d=false;
      }
      if(c)a=now;
      if(d)b=now;
      now++;

   }while (next_permutation(ALL(o)));
   
   cout<<abs(a-b)<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);int i=0,e=2,x=195,y;int[]p=new int[x];for(;i<x;p[i++]=e++)for(;f(p,e)<1;e++);for(;(x=y=s.nextInt())>0;System.out.println(x-y)){for(;f(p,x)<1;++x);for(;f(p,y)<1;--y);}}static int f(int[]s,int n){for(int e:s)if(e>0&&n!=e&&n%e<1)return 0;return 1;}}

Measured memory_bytes: 12000
//Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
typedef long long LL;
const int MAXN = 1000000; 
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int k;

void init() {
  k = read();
}

LL a[MAXN + 5];
LL nine[MAXN + 5];
int tot = 0;

inline int getSum(LL x) {
  LL t = x, ret = 0;

  while (t) {
    ret += t % 10;
    t /= 10;
  }

  return ret;
}

bool cmp(LL x, LL y) {
  LL a = x * getSum(y), b = y * getSum(x);
  
  if (a != b) {
    return a < b;
  } else {
    return x < y;
  }
}

int main() {
  init();

  for (int i = 1; i <= 15; ++i) 
    nine[i] = nine[i - 1] * 10 + 9;

  for (int i = 1; i <= 999; ++i) {
    LL tmp = 1;
    a[++tot] = i;
    for (int j = 1; j <= 12; ++j) {
      tmp *= 10;
      a[++tot] = i * tmp + nine[j];
    }
  }
  
  sort(a + 1, a + 1 + tot, cmp);
  unique(a + 1, a + 1 + tot);
    
  LL mx = 0;
  int i = 1;

  while (k) {
    if (a[i] > mx) {
      mx = a[i];
      --k;
      printf("%lld\n", a[i]);
    }
    
    ++i;
  }

  return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long
const int maxn = 100 + 100;
int n, a, b;

int main() {
    ios::sync_with_stdio(false);
    while(scanf("%d%d%d", &n, &a, &b) != EOF) {
        printf("%d\n", min(n * a, b));
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A==B && B==C){
    printf("No\n");
 }else if(A==B || B==C || C==A){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1612
n = int(input())
a = list(map(int,input().split()))
cnt = {}
for x in a:
    if x not in cnt:cnt[x] = 1
    else:cnt[x] +=1
res = []
for key in cnt:
    v  = cnt[key]
    if v>=2:
        res.append(key)
    if v >=4:res.append(key)
res.sort(reverse = True)
if len(res) < 2:ans=0
else:
    ans = res[0]*res[1]
print(ans)


Measured memory_bytes: 18060
N = int(input())
L = tuple(map(int, input().split()))
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if L[i] == L[j]:
            continue
        for k in range(j + 1, N):
            if L[i] == L[k] or L[j] == L[k]:
                continue
            ls = sorted((L[i], L[j], L[k]))
            if ls[0] + ls[1] <= ls[2]:
                continue
            ans += 1
print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;


int N;

double arr[3005];

double dp[3005][3005];

bool visited[3005][3005];


double headsProbability(int n, int H)
{

	if (n == 0) {

		if (H * 2 >= N)
			return 1;
		else return 0;

	}


	if (visited[n][H])
		return dp[n][H];


	visited[n][H] = 1;


	double heads = (arr[n - 1]) * headsProbability(n - 1, H + 1);

	double tails = (1 - arr[n - 1]) * headsProbability(n - 1, H);

	return  dp[n][H] = heads + tails;


}





int32_t main()
{


	cin >> N;


	for (int i = 0; i < N; ++i)
		cin >> arr[i];


	memset(visited, 0, sizeof(visited));

	memset(dp, 0, sizeof(dp));

	double ans = headsProbability(N, 0);

	printf("%.15g\n", ans);


}

Measured memory_bytes: 83408
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, m;
    cin >> n >> m;
    cout << (n == m ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
(function(input) {
    var p = input.split('\n');
    var n = Number(p.shift());
    var commands = p.slice(' ', n);
    var dic = {};
    commands.forEach(function(e) {
        execCommand(dic, e);
    });
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function execCommand(dic, c) {
    var a = c.split(' ');
    var command = a.shift();
    var key = a.shift();
    if (command === 'insert') {
        dic[key] = 1;
    } else if (command === 'find') {
        console.log(key in dic ? 'yes' : 'no');
    }
}

Measured memory_bytes: 179856
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;
	int Bidx = 1;
	int pass = 0;
	string s;
	cin >> s;
	for(int i = 0 ;i < s.size();i++){
		if(s[i] == 'a'){
			if(a+b > pass)pass++,cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else if(s[i] == 'b'){
			if(a+b > pass && b >= Bidx)pass++,Bidx++,cout<<"Yes"<<endl;
			else cout << "No" << endl;
		}
		else if(s[i] == 'c'){
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 896
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func readIntLine(N int) []int {
	I := make([]int, N)
	for i := 0; i < N; i++ {
		I[i] = readInt()
	}
	return I
}

func main() {
	sc.Split(bufio.ScanWords)
	N := readInt()

	P := readIntLine(N)
	Q := readIntLine(N)

	A := make([]int, N)
	for i := 0; i < len(A); i++ {
		A[i] = i + 1
	}

	mp = make(map[string]int, factorial(N))
	perm([]int{}, A)

	ansP := mp[intSliceToStr(P)]
	ansQ := mp[intSliceToStr(Q)]

	fmt.Println(math.Abs(float64(ansP - ansQ)))
}

func factorial(n int) int {
	ans := 1
	for i := 0; i < n; i++ {
		ans *= n - i
	}
	return ans
}

var mp map[string]int

func perm(head []int, rest []int) []int {
	if len(rest) == 0 {
		str := intSliceToStr(head)
		mp[str] = len(mp)

		return head
	}
	res := make([]int, 0)

	n := len(rest)
	for i := 0; i < n; i++ {
		restx := make([]int, n)
		copy(restx, rest)

		headx := make([]int, 0)
		headx = append(head[0:], restx[i])

		restx = append(restx[0:i], restx[i+1:]...)

		res = perm(headx, restx)
	}
	return res
}

func intSliceToStr(slice []int) string {
	var str string
	for _, v := range slice {
		str += strconv.Itoa(v)
	}
	return str
}


Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out

struct UF {
public:
  int groupNum;
  UF(int N) {
    uf=vector<int>(N);
    rank=vector<int>(N);
    for(int i=0; i<N; ++i) uf[i]=i,rank[i]=0;
    groupNum=N;
  }
  
  int find(int i) {
    return uf[i]==i?i:uf[i]=find(uf[i]);
  }
  
  bool same(int x, int y) {
    return find(x)==find(y);
  }
  
  void unite(int x, int y) {
    x=find(x);
    y=find(y);
    if(x==y) return;
    groupNum--;
    
    if (rank[x]==rank[y]) {
      uf[x]=y;
      rank[y]++;
      return;
    }
    
    if (rank[x]<rank[y]) {
      uf[x]=y;
    } else {
      uf[y] =x;
      if(rank[x]==rank[y]) ++rank[x];
    }
  }
private:
  vector<int> rank;
  vector<int> uf;
};
const int MAX_N=1e5+1;
int N,M;
LL P[MAX_N],X[MAX_N],Y[MAX_N];
SETI G2P[MAX_N];

LL solve() {
  UF uf(N);
  REP(i,M) uf.unite(X[i],Y[i]);
  REP(i,N) {
    int g=uf.find(i);
    G2P[g].emplace(P[i]);
  }
  
  int res=0;
  REP(i,N) {
    int g=uf.find(i);
    res+=(G2P[g].count(i)>0);
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>M;
  REP(i,N) { cin>>P[i]; P[i]--; }
  REP(i,M) { cin>>X[i]>>Y[i]; X[i]--,Y[i]--; }
  cout<<solve()<<endl;
  return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X,Y;
  cin>>X>>Y;
  
  if(Y%2==0){
  if(2*X<= Y && Y<=4*X)cout<<"Yes";
  else cout<<"No"<<endl;
  }
  else cout <<"No"<<endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int main(){

	ll n,a,b;
	cin>>n>>a>>b;
	ll total=b-1;
	total=min(n-a,total);
	if((b-a)%2==0){
		cout<<(b-a)/2<<endl;
		return 0;
	}
	total=min(a+(b-a-1)/2,total);
	total=min(n-b+1+(n-(a+n-b+1))/2,total);

	cout<<total<<endl;
	return 0;

}




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

char a[6][6];
int main(){
	cin >> a[1][1] >> a[1][2] >> a[1][3] >> a[2][1] >> a[2][2] >> a[2][ 3 ] ;
	if(a[1][1]==a[2][3] && a[1][2]==a[2][2] && a[1][3] == a[2][1]){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}

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

int main () {
  long long N;
  cin >> N;
  long long A[3 * N];
  for (long long i = 0; i < 3 * N; i++) cin >> A[i];
  sort(A, A + 3 * N);
  long long res = 0;
  for (long long i = N; i < 3 * N; i++){
    if ((i - N) % 2 == 0) res += A[i];
  }
  cout << res << endl;
}

Measured memory_bytes: 5980
/*****Enigma_27*****/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pll         pair<ll,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define endl		'\n'
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,l=2,t=0,k=1,x,ans=0;
map<tuple<ll,ll,ll> ,ll > dp;
string s[2];
ll f(int pos , int x ,int y)
{
    //cout<<pos<<" "<<x<<" "<<y<<endl;
    if(pos==n) return 1;
    tuple<ll,ll,ll> state;
    state=tie(pos,x,y);
    if(dp.find(state)!=dp.end()) return dp[state];
    if(s[0][pos]==s[1][pos])
    {
        if(x==-1) return dp[state]=(f(pos+1,0,0)%hell+f(pos+1,1,1)%hell+f(pos+1,2,2)%hell)%hell;
        else if(x==y)
        {
           return dp[state]=(f(pos+1,(x+1)%3,(x+1)%3)%hell+f(pos+1,(x+2)%3,(x+2)%3)%hell)%hell;
        }
        else
        {   int z;
             for(z=0;z<3;z++) if(z!=x&&z!=y) break;
            return dp[state]=f(pos+1,z,z)%hell;
        }

    }
    else
    {
        if(x==-1)
        {
            return dp[state]=(f(pos+2,1,2)%hell+f(pos+2,1,0)%hell+f(pos+2,2,0)%hell+f(pos+2,2,1)%hell+f(pos+2,0,1)%hell+f(pos+2,0,2)%hell)%hell;
        }
        else if(x==y)
        {
            return dp[state]=(f(pos+2,(x+1)%3,(x+2)%3)%hell+f(pos+2,(x+2)%3,(x+1)%3)%hell)%hell;
        }
        else
        {   int z;
           for(z=0;z<3;z++) if(z!=x&&z!=y) break;
            return dp[state]=(f(pos+2,y,x)%hell+f(pos+2,y,z)%hell+f(pos+2,z,x)%hell)%hell;
        }
    }
}
int main()
{   ios
    cin>>n>>s[0]>>s[1];
    cout<<f(0,-1,-1)%hell<<endl;
	return 0;
}


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

typedef pair<int,int>  pint;
typedef pair<ll,ll>    pll;
typedef vector<int>    vint;
typedef vector<ll>     vll;
typedef vector<string> vstr;
typedef vector<pint>   vpint;
typedef vector<pll>    vpll;

#define vint2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init))
#define vll2(v,n,m,init)  vector<vector<ll>>  v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vint var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vstr var(n); rep(i,n){cin >> var[i];}
#define ALL(var)         (var).begin(), (var).end()
#define sortall(var)     sort(ALL(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());

#define prt(var)         cout << (var) << "\n"
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//-----------------------------------------------------------------------------

int main(void){
  int n;
  cin >> n;
  arrll(a,n+1);

  ll sum=0;
  rep(i,n+1){
    sum += a[i];
  }

  if(a[0]>1){
    prt(-1);
    return 0;
  }
  ll b = 1-a[0];
  ll ans = a[0] + b;
  sum -= a[0];
  REP(i,1,n+1){
    if(b*2<a[i]){
      prt(-1);
      return 0;
    }
    sum -= a[i];
    b = min(sum, 2*b-a[i]);
    ans += a[i]+b;
  }

  prt(ans);
}


Measured memory_bytes: 3956
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        TreeSet<Integer>[] positions = new TreeSet[26];
        for (int i = 0; i < 26; i++) {
            positions[i] = new TreeSet<>();
        }
        for (int i = 1; i <= n; i++) {
            positions[arr[i - 1] - 'a'].add(i);
        }
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int type = sc.nextInt();
            if (type == 1) {
                int idx = sc.nextInt();
                int prev = arr[idx - 1] - 'a';
                positions[prev].remove(idx);
                char c = sc.next().charAt(0);
                positions[c - 'a'].add(idx);
                arr[idx - 1] = c;
            } else {
                int left = sc.nextInt();
                int right = sc.nextInt();
                int count = 0;
                for (TreeSet<Integer> set : positions) {
                    Integer x = set.ceiling(left);
                    if (x != null && x <= right) {
                        count++;
                    }
                }
                sb.append(count).append("\n");
            }
        }
		System.out.print(sb);
   }
    

}


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

#define _fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1)
#define MAXS 100000
#define MOD 998244353
#define all(v) v.begin(),v.end()
#define pb push_back

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


int tc,n,a[100005];


void sol()
{
    int neg=0,pos=0,mn=INT_MAX;
    ll sum=0;
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        if(a[i]<0)neg++;
        sum+=abs(a[i]);
        mn=min(mn,abs(a[i]));
    }
    if(neg&1)sum-=2*mn;
    cout<<sum<<endl;
}

int main()
{

    _fastIO;

    //cin>>tc;while(tc--)
    sol();

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    
    int hiro_i, hiro_y, ken_i, ken_y, i_score, y_score, i_score_10, y_score_20;
    int hiro_score, ken_score;
    cin >> hiro_i >> hiro_y >> ken_i >> ken_y >> i_score >> y_score >> i_score_10 >> y_score_20;
    
    hiro_score = (hiro_i/10) * i_score_10 + hiro_i * i_score + (hiro_y/20) * y_score_20 + hiro_y * y_score;
    ken_score = (ken_i/10) * i_score_10 + ken_i * i_score + (ken_y/20) * y_score_20 + ken_y * y_score;
    
    if(hiro_score > ken_score){
        cout << "hiroshi" << endl;
    }
    else if(hiro_score < ken_score){
        cout << "kenjiro" << endl;
    }
    else cout << "even" << endl;
    
    return 0;
}

/*
　点数…釣った魚の数 × １匹ごとの点数 + 10匹(または20匹)ごとの追加点
　10匹ごと(または20匹ごと)は、10(または20)で割ることで計算できます。
*/



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> D(N);
    REP(i, 0, N) cin >> D[i];

    ll ans = 0;
    REP(i, 0, N) {
        REP(j, i + 1, N) {
            ans += D[i] * D[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    s_len=len(s)
    g=[0]*s_len
    g[0]=1
    if s[1]==s[0]:g[1]=1
    else: g[1]=2
    for i in range(2,s_len):
        if s[i]==s[i-1]:
            g[i]=g[i-3]+2
        else:
            g[i]=g[i-1]+1
    print(g[-1])

if __name__=='__main__':
    main()

Measured memory_bytes: 11240
N = int(input())
l = [0]*N
upper = round((N-1)**0.5-1)
for x in range(1, upper+1):
    for y in range(1, upper + 1):
        for z in range(1, upper + 1):
            tmp = x**2+y**2+z**2+x*y+y*z+z*x
            if tmp < N+1:
                l[tmp-1]+=1
for x in l:
    print(x)

Measured memory_bytes: 9444
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sum=0,d,x,i;
	int n,k,arr[456]={0};
	scanf("%d%d",&n,&k);
	while(k--)
	{
		scanf("%d",&x);
		for(i=0;i<x;i++)
		{
			scanf("%d",&d);
			arr[d]=1;
		}
	}
	for(i=1;i<=n;i++)
	{
		if(arr[i]==0)
		sum++;
	}
	printf("%d",sum);
}

Measured memory_bytes: 3828
N,M,K = map(int,input().strip().split())
def judge(N,M,K):
    if K > N * M or K < 0:
        return False
    for n in range(0, N + 1):
        for m in range(0, M + 1):
            if n * M + m * N - 2*m * n == K:
                return True
    return False
if judge(N, M, K):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
def atoi(a):

    if a=="a":
        return 0
    elif a=="b":
        return 1
    elif a=="c":
        return 2
    elif a=="d":
        return 3
    elif a=="e":
        return 4
    elif a=="f":
        return 5
    elif a=="g":
        return 6
    elif a=="h":
        return 7
    elif a=="i":
        return 8
    elif a=="j":
        return 9
    elif a=="k":
        return 10
    elif a=="l":
        return 11
    elif a=="m":
        return 12
    elif a=="n":
        return 13
    elif a=="o":
        return 14
    elif a=="p":
        return 15
    elif a=="q":
        return 16
    elif a=="r":
        return 17
    elif a=="s":
        return 18
    elif a=="t":
        return 19
    elif a=="u":
        return 20
    elif a=="v":
        return 21
    elif a=="w":
        return 22
    elif a=="x":
        return 23
    elif a=="y":
        return 24
    elif a=="z":
        return 25

def itoa(i):
    if i==0:
        return "a"
    elif i==1:
        return "b"
    elif i==2:
        return "c"
    elif i==3:
        return "d"
    elif i==4:
        return "e"
    elif i==5:
        return "f"
    elif i==6:
        return "g"
    elif i==7:
        return "h"
    elif i==8:
        return "i"
    elif i==9:
        return "j"
    elif i==10:
        return "k"
    elif i==11:
        return "l"
    elif i==12:
        return "m"
    elif i==13:
        return "n"
    elif i==14:
        return "o"
    elif i==15:
        return "p"
    elif i==16:
        return "q"
    elif i==17:
        return "r"
    elif i==18:
        return "s"
    elif i==19:
        return "t"
    elif i==20:
        return "u"
    elif i==21:
        return "v"
    elif i==22:
        return "w"
    elif i==23:
        return "x"
    elif i==24:
        return "y"
    elif i==25:
        return "z"


s = []
n = int(input())
for i in range(n):
    s.append(input())

d = [[0 for j in range(n)] for i in range(26)]

for i in range(n):
    for j in range(len(s[i])):
        d[atoi(s[i][j])][i]+=1
ans = ""
for i in range(26):
    ans+=itoa(i)*min(d[i])
print(ans)

Measured memory_bytes: 3192
import sys
sys.setrecursionlimit(10**9)
n = int(input())
graph = [[]for i in range(n)]
for i in range(n-1):
    pre = list(map(int,input().split()))
    graph[pre[0]-1].extend([pre[1]-1,pre[2]])
    graph[pre[1]-1].extend([pre[0]-1,pre[2]])
seen = [0 for i in range(n)]
color = [-1 for i in range(n)]

def DFS(x):
    if seen[x] == 1:
        return 0
    else:
        pass
    seen[x] = 1
    for i in range(len((graph[x]))//2):
        if graph[x][2*i+1] % 2 == 0:
            color[graph[x][2*i]] = color[x]
        else:
            color[graph[x][2*i]] = not color[x]

    for i in range(len((graph[x]))//2):
        DFS(graph[x][2*i])

color[0] = True
DFS(0)
for i in range(n):
    print(int(color[i]))

Measured memory_bytes: 72240
#include <iostream>
#include <vector>
#include <cmath>
#include <string.h>
using namespace std;

int main() {
	char s[1000];
	while(true) {
		fgets(s, 1000, stdin);

		if(s[strlen(s)-1] == '\n') {
			s[strlen(s)-1] = '\0';
		}
		if(s[strlen(s)-1] == '\r') {
			s[strlen(s)-1] = '\0';
		}
		if (strcmp(s, "END OF INPUT") == 0) {
			break;
		}
		int len = 0;
		for (int i = 0; i < (int)strlen(s); i++) {
			if(s[i] != ' ') {
				len++;
			}
			else{
				cout << len;
				len = 0;
			}
		}
		cout << len << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
char mp[305][305],mp2[305][305];
int n,m,i,j,k,l,ans;
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			cin>>mp[i][j];
		}
	}
	for (i=-n;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			for (k=1;k<=n;k++)
			{
				mp2[j][k]=mp[(i+j-1+n+n)%n+1][k];
			}
		}
		bool ok=1;
		for (j=1;j<=n;j++)
		{
			for (k=1;k<=n;k++)
			{
				if (mp2[j][k]!=mp2[k][j])
				{
					ok=0;
					break;
				}
			}
			if (!ok) break;
		}
		if (ok)
		{
			for (j=0;j<n;j++)
			{
				k=i+j;
				if (k>=0&&k<n) ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#define vi vector<int>
//#define debug(x) cout<<#x<<":"<<x<<endl;
//#define UL unsigned long long
//#include<algorithm>
#include<vector>

#define ll long long
#include<iostream>
using namespace std;

int main(){
	ll n,a;
	vi v;
	cin>>n;
	for(int i =0;i<n;i++){
		cin>>a;
		v.push_back(a);
	}
	int num=1;
	int ans=0;
	for(int i=0;i<n;i++){
		if(v[num-1]==2){
			ans=i+1;
			break;
		}else{
			num=v[num-1];
		}
	}
	if(ans==0){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
    char a[4];
    cin>>a;
    if(a[0]==a[1]&&a[0]==a[2])
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
from collections import defaultdict

def solve():
    N = int(input())
    
    d = defaultdict(int)
    for _ in range(N):
        s = input()
        l_s = list(s)
        l_s.sort()
        s = "".join(l_s)
        d[s] += 1

    ans = 0
    for key, value in d.items():
        # 和の公式
        ans += (((value-1)+1) * (value-1)) / 2
    print(int(ans))

if __name__ == "__main__":
    solve()


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

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  for (auto idx(0); idx < n; ++idx) {
    cin >> p[idx];
  }
  auto c(0);
  for (auto idx(1); idx < n - 1; ++idx) {
    if (((p[idx] - p[idx - 1]) * (p[idx] - p[idx + 1])) < 0) {
      ++c;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
import math
import copy
def koch(x1,y1,x2,y2):
    x3,y3 = (x1*2+x2)/3, (y1*2+y2)/3
    x4,y4 = (x1+x2*2)/3, (y1+y2*2)/3
    x5, y5 = x3 + (x4-x3)/2-((y4-y3)*math.sqrt(3))/2, y3 + ((x4-x3)*math.sqrt(3))/2+(y4-y3)/2
    return x3, y3, x4, y4, x5, y5

n = int(input())
a = [[0,0],[100,0]]
b = copy.copy(a)
for _ in range(n):
    b = copy.copy(a)
    for i in range(len(b)-1):
        x3,y3,x4,y4,x5,y5 = koch(b[i][0],b[i][1],b[i+1][0],b[i+1][1])
        a.insert(4*i+1,[x3,y3])
        a.insert(4*i+2, [x5,y5])
        a.insert(4*i+3, [x4,y4])

for i in a:
    i = list(map(str, i))
    print(' '.join(i))


Measured memory_bytes: 6764
import sys
readline = sys.stdin.buffer.readline
n,k = map(int,readline().split())
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def factrial_memo(n=10**6+1,mod=10**9+7):
    fact = [1, 1]
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % mod)
    return fact
def fermat_cmb(n, r, mod=10**9+7): #needs pow,factrial_memo(only fact). return nCk
    return fact[n] * pow(fact[r],mod-2) * pow(fact[n-r],mod-2) %mod
fact = factrial_memo()

if k > n-1: #全通りの再現が可能ならば
    ans = fermat_cmb(2*n-1,n)
else: #移動回数の制限によって全通りの再現ができないならば
    ans = 1
    for i in range(1,k+1): #全ての動作を再現する(kはたかだか2*10**5である)
        ans += fermat_cmb(n,i)*fermat_cmb(n-1,i)
        #n人の中から動かせる人物をi人取り、n-1箇所(それぞれの人物に付き同じ場所には戻れない)
        #にi人を入れる組み合わせ。それぞれの事象に付き、0人になる部屋と他の部屋の人数は
        #必ず違う組み合わせになるので、これをk回だけ繰り返せば良い
        ans %= mod

print(ans)

Measured memory_bytes: 116208
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    cout << setprecision(16);
    int n; cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i];
    b = a; sort(b.rbegin(), b.rend());
    int f=b[0],s=-1;
    if(b[0] != b[1]) s = b[1];
    for(int x:a){
        if(x == f && s != -1) cout << s << endl;
        else cout << f << endl;
    }
    return 0;
}

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

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &el : a){
        cin >> el;
    }
    int res = 0;
    for(int i = 0; i < n-1; ++i){
        for(int j = i+1; j < n; ++j){
            res += a[i]*a[j];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
// AOJ Volume 0 Problem 0076

#include <stdio.h>
#include <math.h>


int main(void)
{
	int n;
	int i;
	double r;
	int ll;
	

	while (1){
		scanf("%d", &n);
		if (n == -1){
			break;
		}

		ll = 1;
		r  = 0.0;
		for (i = 1; i < n; i++){
			r += atan(1 / sqrt((double)ll));			
			ll++;
		}
		
		printf("%.02lf\n%.02lf\n", cos(r) * sqrt(ll), sin(r) * sqrt(ll));
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
using namespace std;


void AGC037A()
{
	string str;
	cin >> str;
	int n = str.size();
	int i = 0;
	int ct = 0;
	string prevS;
	while (i < n)
	{
		string s = str.substr(i, 1);
		if (s == prevS)
		{
			s = str.substr(i, 2);
			++i;
		}
		++i;
		if (i == n)
		{
			++ct;
			break;
		}
		if (i == n - 1)
		{
			string ss = str.substr(i, 1);
			if (ss == s)
			{
				string snew = s + ss; // size 2
				++ct;
				break;

			}
			else
			{
				ct += 2;
				break;
			}
		}

		++ct;
		prevS = s;
	}
	cout << ct << endl;
}

int main()
{
	AGC037A();
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((a+b)>(c+d)) cout << "Left";
    else if((a+b)==(c+d))    cout << "Balanced";
    else    cout << "Right";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
int N;
typedef pair<int,int> p;
vector<p> balls;
map<p,int> mappi;
int costdown=0;
int main(int argc,char const* argv[])
{
  cin >> N;
  for (int i = 0; i < N; ++i)
    {
      int x,y;
      cin >> x >> y;
      balls.push_back(make_pair(x,y));
    }
  if(N==1)
    {
      cout << 1 << endl;
      return 0;
    }
  for (int i = 0; i < N; ++i)
    {
      for (int j = 0; j < N;j++)
	{
	  if(i!=j)
	    {
	      int difx=balls[j].first-balls[i].first;
	      int dify=balls[j].second-balls[i].second;
	      mappi[p(difx,dify)]++;
	    }
	}
    }
  for(auto it=mappi.begin();it!=mappi.end();it++)
    {
      costdown=max(costdown,it->second);
    }
  cout << N-costdown << endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		int k = in.nextInt();
		int[] d = new int[k];
		boolean[] ok = new boolean[10];
		Arrays.fill(ok, true);
		for (int i=0; i<k; i++) {
			d[i] = in.nextInt();
			ok[d[i]] = false;
		}

		for (long i=n; ; i++) {
			long x = i;
			boolean f = true;
			while (x != 0) {
				if (!ok[(int)(x%10)]) {
					f = false;
					break;
				}
				x /= 10;
			}
			if (f) {
				out.println(i);
				return;
			}
		}
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
#define len length

#define print(stuff) cout << stuff << endl

#define ll long long
#define ld long double
#define fi first
//#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

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

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001



int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/

    string s;
    cin>>s;
    ll arr[4];
    loop(i,0,4) arr[i]=s[i]-'0';
    ll a=arr[1]+10*arr[0];
    ll b=arr[2]*10+arr[3];
    // cout<<a<<" "<<b<<endl;
    bool b1=(a>=1 && a<=12);
    bool b2=(b>=1 && b<=12);
    if(b1==0 && b2==0){
        cout<<"NA"<<endl;
    }
    else if(b1==0 && b2==1){
        cout<<"YYMM"<<endl;
    }
    else if(b1==1 && b2==0){
        cout<<"MMYY"<<endl;
    }
    else if(b1==1 && b2==1){
        cout<<"AMBIGUOUS"<<endl;
    }
        
   /* #ifndef ONLINE_JUDGE
        end_routine();
    #endif*/
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
signed main(){
    int n;
    cin>>n;
    vector<string> vec;
    for(int i=0;i<2;i++){
        string t;
        cin>>t;
        vec.push_back(t);
    }
    int ans=1;
    for(int i=0;i<n;i++){
        if(vec[0][i]==vec[1][i]){
            if(i>0){
                if(vec[0][i-1]!=vec[1][i-1]){
                    ans*=1;
                }else{
                    ans*=2;
                }
            }else{
                ans*=3;
            }
        }else{
            if(i>0){
                if(vec[0][i-1]!=vec[1][i-1]){
                    ans*=3;
                }else{
                    ans*=2;
                }
            }else{
                ans*=6;
            }
            i++;
        }
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<ll, ll> P;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll N,K; cin >> N >> K;
    vector<P> v(N);
    REP(i,N){
        ll t,d; cin >> t >> d;
        t--;
        v[i].first = d; v[i].second = t;
    }
    SORT(v); REVERSE(v);
    vector<ll> m[N];
    ll sum_d=0, x=0;
    REP(i,K){
        if(m[v[i].second].empty()) x++;
        m[v[i].second].push_back(v[i].first);
        sum_d += v[i].first;
    }

    vector<ll> f(N+1,-LL_INF);
    f[x] = sum_d;

    priority_queue<ll,vector<ll>,greater<ll>> q;
    REP(i,N){
        if(m[i].size()>1){
            REP(j,m[i].size()-1) q.push(m[i][j+1]);
        }
    }

    int t = K;
    FOR(i,x+1,K+1){
        if(q.empty()) break;
        while(t<N && m[v[t].second].size()) t++;
        if(t == N) break;
        auto p = q.top(); q.pop();
        sum_d -= p;
        sum_d += v[t].first;
        m[v[t].second].push_back(v[t].first);
        f[i] = sum_d;
    }

    ll ans = 0;
    for(ll i=1; i<=K; i++) chmax(ans, f[i]+i*i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ud(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, a, b) for (int i = a, i < b; ++i)
#define rep3(i, n) for (int i = n - 1; i >= 0; ++i)
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void solve(void) {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(a + b, min(b + c, c + a)) << endl;
}
int main(void) { solve(); }


Measured memory_bytes: 3560
input = open(0).readline
n = int(input())
array = []

for i in range(n):
    x = input().rstrip('\n')
    array.append(x)
    
d = {}

for s in array:
    if s in d.keys():
        d[s] +=1
    else:
        d[s] = 1

max_val = max(d.values())
array2 = [key for key in d if d[key] == max_val]
array2 = sorted(array2)

for s in array2:
    print(s)

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

int main() {
  int h, a;
  cin >> h >> a;
  cout << (h+a-1)/a << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int arr[101];
int main()
{
    int n=0,cou=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
 for(int i=0;i<n;i++){
        if((i%2==0)&&(arr[i]%2!=0)){
            cou++;
        }
    } cout<<cou;
    return 0;
}


Measured memory_bytes: 3572
#include<cstdio>
#include<algorithm>
const int N=1e5+5;
int a[N],n,l,t,x,w;
long long cnt;
using namespace std;
inline char tc(void)
{
	static char fl[100000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,100000,stdin),A==B)?EOF:*A++;
}
inline void read(int &x)
{
	x=0; char ch=tc();
	while (ch<'0'||ch>'9') ch=tc();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=tc();
}
inline void write(int x)
{
	if (x/10) write(x/10);
	putchar(x%10+'0');
}
int main()
{
	//freopen("B.in","r",stdin); freopen("B.out","w",stdout);
	register int i;
	read(n); read(l); read(t);
	for (i=0;i<n;++i)
	{
		read(x); read(w);
		if (w==1) a[i]=(x+t)%l,cnt+=(x+t)/l; else 
		{
			a[i]=(x-t)%l; cnt+=(x-t)/l;
			if (a[i]<0) a[i]+=l,--cnt;
		}
	}
	cnt=(cnt%n+n)%n;
	sort(a,a+n);
	for (i=cnt;i<n;++i)
	write(a[i]),putchar('\n');
	for (i=0;i<cnt;++i)
	write(a[i]),putchar('\n');
	return 0;
}

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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int cntlen[17] = { 0 };
	int temp;
	for (int i = 0; i < 3; ++i)
	{
		scanf("%d",&temp);
		++cntlen[temp];
	}
	if(cntlen[5] == 2 && cntlen[7] == 1)	puts("YES");
	else puts("NO");
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        List<int> a = Console.ReadLine().Split().Select(int.Parse).ToList();
        Console.WriteLine(solve(n, a));
    }
    static int solve(int n, List<int> a) {
        int[] lgcd = new int[n-1];
        lgcd[0] = a[0];
        for(int i = 1; i < n-1; i ++) {
            lgcd[i] = Gcd(a[i],lgcd[i-1]);
        }
        a.Reverse();
        int[] rgcd = new int[n-1];
        rgcd[0] = a[0];
        for(int i = 1; i < n-1; i ++) {
            rgcd[i] = Gcd(a[i],rgcd[i-1]);
        }
        a.Reverse();
        int[] ans = new int[n];
        ans[0] = rgcd[n-2];
        ans[n-1] = lgcd[n-2];
        for(int i = 1; i < n-1; i ++) {
            ans[i] = Gcd(lgcd[i-1], rgcd[n-2-i]);
        }
        return ans.Max();
    }
    static int Gcd(int a, int b) {
        if (a < b) return Gcd(b, a);
        while (b != 0) {
            var tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }
}


Measured memory_bytes: 29020
# -*- coding: utf-8 -*-

import sys
import os
import re

def extract_numbers(s):
    lst = re.findall('[0-9]+', s)
    return list(map(int, lst))

sum_value = 0
for s in sys.stdin:
    s = s.strip()
    lst = extract_numbers(s)
    sum_value += sum(lst)
print(sum_value)

Measured memory_bytes: 7788