akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

#define MIN -1

void Insert(int);
void Extract();
void Increase(int);
void Swap(int,int);
void MaxHeapify(int);

int *A,size;

int main(void){
	char in[10];
	int key;

	size=0;

	A=(int*)malloc(sizeof(int));

	while(1){
		scanf("%s",in);
		
		if(in[0]=='i'){
			scanf("%d",&key);
			Insert(key);
		}

		else{
			if(in[1]=='x'){
				Extract();
			}
			else break;
		}
	}

	free(A);

	return 0;
}

void Insert(int key){
	size++;
	A=(int*)realloc(A,sizeof(int)*(size+1));
	A[size]=MIN;
	Increase(key);
}

void Increase(int key){
	int num;
	
	num=size;

	if(key<A[num]) return;

	A[num]=key;
	while(num>1 && A[num/2]<A[num]){
		Swap(num/2,num);
		num=num/2;
	}
}

void Extract(){
	
	if(size<1) return;

	printf("%d\n",A[1]);

	Swap(1,size);

	size--;

	MaxHeapify(1);
}

void MaxHeapify(int num){
	int large;

	if(2*num<=size && A[num]<A[2*num]) large=2*num;
	else large=num;
	if(2*num+1<=size && A[large]<A[2*num+1]) large=2*num+1;

	if(large!=num){
		Swap(num,large);
		MaxHeapify(large);
	}
}

void Swap(int a,int b){
	int work;

	work=A[a];
	A[a]=A[b];
	A[b]=work;
}

Measured memory_bytes: 4400
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <numeric>

using namespace std;
int my_abs(int n){
    if(n<0){
        return -n;
    }else{
        return n;
    }

}
int main(){
    int i,n,wi;
    vector<int> w;
    cin >> n; 
    for(i=0;i<n;i++){
        cin>>wi;
        w.push_back(wi);
    }
    int sum=accumulate(w.begin(),w.end(),0);
    int ret=0,ret0,ret1;
    for(i=0;i<n;i++){
        ret+=w[i];
        if(ret>=(sum/2)){
            ret0=abs(sum-2*ret);
            ret1=abs(sum-2*ret+2*w[i]);
            ret=min({ret0,ret1});
            break;
        }
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>

#define ls ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define case "Case " << l << ":"
#define quit return 0

using namespace std;
int main()
{
    ls
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,m,s=0,k;
    cin >> n >> k ;
    int a[n];
    for(m=0;m<n;m++){
        cin >> a[m];
    }
    sort(a,a+n);
    for(m=0;m<k;m++){
        s=s+a[m];
    }
    cout << s ;


    quit;
}


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

using namespace std;
#define ll long long
int num[105];
int main()
{
    int n;
    cin >> n;
    ll ans=10000000000;
    int mi=9999999,ma=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
        mi=min(mi,num[i]);
        ma=max(ma,num[i]);
    }
    for(int i=mi;i<=ma;i++)
    {
        ll tans=0;
        for(int j=0;j<n;j++)
        {
            tans+=(num[j]-i)*(num[j]-i);
        }
        ans=min(ans,tans);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
N  = int(input())
testimony = [[]for i in range(N)]
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1,state])#3次元配列の作り方
honest = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if(i>>j)&1 == 1:
            for x,y in testimony[j]:#3次元リストからx,yを取り出す書きかた　覚える
                if (i>>x)&1 != y: #正直といっているがそうではない　と　嘘つきといっているがそうではない　の二つ同時
                    flag =1
                    break
    if flag == 0:
        honest = max(honest, bin(i)[2:].count('1'))# bin()で二進数に変換　最初の二文字は0bで取り除く count('1')で数える
print(honest)


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

int n;
vector< vector< int > > g(100001);

vector< int > used(100001, -1);

void rec(int p, int c) {
    used[p] = c;
    for(int i = 0; i < g[p].size(); i++) {
        if(used[g[p][i]] == -1) {
            rec(g[p][i], c + 1);
        }
    }
}

int main() {

    cin >> n;
    for(int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector< int > s1, s2;
    rec(n, 0);
    s1 = used;
    used = vector< int > (100001, -1);
    rec(1, 0);
    s2 = used;

    int sum1 = 0, sum2 = 0;
    for(int i = 1; i <= n; i++) {
        if(s1[i] < s2[i]) sum1++;
        else sum2++;
    }
    cout << (sum1 >= sum2 ? "Snuke" : "Fennec") << endl;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    sort(begin(A), end(A), greater<int>());
    
    int a = 0;
    int b = 0;
    rep(i,N) {
        if (i % 2 == 0) a += A[i];
        else b += A[i];
    }

    cout << a - b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

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

	int n;
	cin >> n;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];

	ll ans = 0;
	map<ll, ll> q;
	rep(i, n) {
		if (i - a[i] >= 1) ans += q[i - a[i]];

		q[a[i] + i] += 1;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 18904
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int product = a * b * c;

    if(product == 5 * 7 * 5)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


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

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;


void mymain(){
    int n,k;
    cin >> n >> k;
    int res=0;
    for(int i=0;i<n;i++){
        int h;
        cin >> h;
        if(h >= k)
            res++;
    }
    cout << res <<endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
///cin>>t;

for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    val n = readLine()!!.toInt()
    val p = (1..n).map { readLine()!!.split(" ").map { it.toInt() } }
    val d = Array(n){DoubleArray(n)}
    for (i in 0..n-1) {
        for (j in 0..n-1) {
            val dx = (p[i][0]-p[j][0]).toDouble()
            val dy = (p[i][1]-p[j][1]).toDouble()
            d[i][j] = Math.sqrt(dx*dx+dy*dy)
        }
    }

    val used = BooleanArray(n)
    val perm = IntArray(n)
    val perms = mutableListOf<IntArray>()
    fun generatePermutation(index: Int) {
        if (index > perm.lastIndex) {
            perms.add(perm.copyOf())
            return
        } else {
            (0 until n).filter { !used[it] }.forEach {
                used[it] = true
                perm[index] = it
                generatePermutation(index+1)
                used[it] = false
            }
        }
    }

    generatePermutation(0)
    
    perms.map { perm ->
        (1 until n).map { d[perm[it-1]][perm[it]] }.sum()
    }.average()

})

Measured memory_bytes: 48140
#include<iostream>
#include<array>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <tuple>
#include<cmath>
#include<queue>
#include <climits>

using lli = long long int;
using namespace std;
int inf = 1000000007;

int N, M;
int u, v;
int S, T;

int main() {
	cin >> N >> M;
	vector<vector<int>> G(N + 1);
	for (int i = 0; i < M; i++) {
		cin >> u >> v;
		G[u].push_back(v);
	}
	cin >> S >> T;
	vector<vector<bool>> visit(3, vector<bool>(N + 1));
	for (int i = 0; i < 3; i++)for (int j = 0; j <= N; j++)visit[i][j] = false;
	vector<int> cost(N + 1);
	for (int i = 0; i <= N; i++)cost[i] = -1;
	cost[S] = 0;

	queue<int> q0;
	queue<int> q1;
	queue<int> q2;

	int d = 0;
	q0.push(S);

	while (q0.size() != 0) {
		int u0 = q0.front();
		q0.pop();
		visit[0][u0] = true;
		for (int e : G[u0])
			if (!visit[1][e]) { q1.push(e); }
		while (q1.size() != 0) {
			int u1 = q1.front();
			q1.pop();
			visit[1][u1] = true;
			for (int e : G[u1])
				if (!visit[2][e]) { q2.push(e); }
			while (q2.size() != 0) {
				int u2 = q2.front();
				q2.pop();
				visit[2][u2] = true;
				for (int e : G[u2]) {
					int nx = cost[u0] + 1;
					if (cost[e] == -1 || nx < cost[e]) {
						cost[e] = nx;
						q0.push(e);
					}
				}
			}
		}
	}
	cout << cost[T] << endl;
}


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

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

    int n,q;
    cin>>n>>q;

    queue<pair<string,int>> pr;
    for(int i=1;i<=n;i++){
        string n;
        int t;
        cin>>n>>t;

        pair<string,int> p;
        p=make_pair(n,t);

        pr.push(p);
    }

    int sum=0;
    while(!pr.empty()){
        if(pr.front().second<=q){
            sum+=pr.front().second;
            
            cout<<pr.front().first<<" "<<sum<<"\n";

            pr.pop();
        }

        else{
            sum+=q;
            pr.front().second-=q;

            pair<string,int> p;
            p=make_pair(pr.front().first,pr.front().second);

            pr.pop();
            pr.push(p);
        }
    }
    
    return 0;
}


Measured memory_bytes: 6280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int array[]={-1,1,2,1,3,1,3,1,1,3,1,3,1};
    
    int a,b;
    cin>>a>>b;
    
    if(array[a]==array[b])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n,k;
        cin>>n>>k;
        ll h[n];
        ll dp[n];
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            h[i]=t;
        }
        dp[0]=0;
        REP(i,1,n)
        {
            ll t=1e18;
            REP(j,max((ll)0,i-k),i)
            {
                t=min(t,dp[j]+abs(h[i]-h[j]));
            }
            dp[i]=t;
        }
        cout<<dp[n-1]<<'\n';
    }
 
    return 0;
}

Measured memory_bytes: 1792
N,M=map(int,input().split())

pair=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
graph=[[0]*N for _ in range(N)] 


for p in pair:
	graph[p[0]][p[1]]= graph[p[1]][p[0]]=1
	
def DFS(v):
	if visited[v]:
		return 
	visited[v]=True
	for j in [j for j,v2 in enumerate(graph[v]) if v2==1]:
		DFS(j)
		
res = 0

for i in range(M):
	visited=[False for _ in range(N)] 
	x,y=pair[i]
	graph[x][y]=graph[y][x]=0 
	DFS(0)
#	DFS(0 if i>0 else 1)
	
	if not all(visited):
		res+=1
	
	graph[x][y]=graph[y][x]=1

print(res)

Measured memory_bytes: 3064
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	input = input[0].split(" ");
	const N = input[0];
	const A = input[1];
	const B = input[2];

	if(N*A < B){
		console.log(N*A);
	}else{
		console.log(B);
	}
 }
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
    int kakaku = 700;
    string s;
    cin >> s;
    if(s[0] == 'o') kakaku +=100;
    if(s[1] == 'o') kakaku +=100;
    if(s[2] == 'o') kakaku +=100;

    cout << kakaku << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string S; cin >> S;
	string T; cin >> T;


	bool res = false;
	int n = (int)S.length();
	vector<char> s(n,0);
	rep (i, n) s[i] = S[i];
 
	rep (i, n){
		rotate(s.rbegin(), s.rbegin() + 1, s.rend());
		string U = "";
		rep (j, n){
			U += s[j];
		} // end rep
//		cerr << "U: " << U << endl;
		if (U == T){
			res |= true;
		} // end if
	} // end rep

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

	return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int a, b;

signed main(){
    cin >> a >> b;
    if(a+b == 15) cout << "+" << endl;
    else if(a*b == 15) cout << "*" << endl;
    else cout << "x" << endl;
}

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

using namespace std;

int main ()
{
    int k, a, b;

    scanf("%d %d %d", &k, &a, &b);
    bool c = 0;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            c = 1;
            break;
        }
    }
    if (c) puts("OK");
    else puts("NG");

    return 0;
}


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

int main(void)
{

	int a, b, c, n;
	bool f = false;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		f = false;
		cin >> a >> b >> c;
		if (a * a + b * b == c * c) f = true;
		if (b * b + c * c == a * a) f = true;
		if (c * c + a * a == b * b) f = true;
		if (f == true) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3060
//Bismillahir Rahmanir Rahim
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d,e;
	cin>>a>>b;

	if(a==1&&b==2)
		cout<<3<<endl;
	else if(a==3&&b==1)
		cout<<2<<endl;
	else if(a==1&&b==3)
		cout<<2<<endl;
	else if(a==2&&b==3)
		cout<<1<<endl;
	else if(a==3&&b==2)
		cout<<1<<endl;
	else if(a==2&&b==1)
		cout<<3<<endl;
}

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

int v[50][500][500]={1, 0};

int gcd(int a, int b){
    if(a==0||b==0) return max(a,b);
    int big=max(a,b), small = min(a,b);
    return gcd(small, big%small);
}

int main(){
    int n, ma, mb, answer=5000;
    cin>>n>>ma>>mb;
    for(int i=0; i<n; i++){
        int a,b,c;
        cin>>a>>b>>c;
        for(int j=0; j<500; j++){
            for(int k=0; k<500; k++){
                if(v[i][j][k]!=0){
                    if(v[i+1][j+a][k+b]!=0)
                    v[i+1][j+a][k+b]=min(v[i+1][j+a][k+b], v[i][j][k]+c);
                    else
                    v[i+1][j+a][k+b]=v[i][j][k]+c;
                    
                    if(v[i+1][j][k]!=0)
                    v[i+1][j][k]=min(v[i+1][j][k], v[i][j][k]);
                    else v[i+1][j][k]=v[i][j][k];
                }
            }
        }
    }

    for(int j=1; j<500; j++){
        for(int k=1; k<500; k++){
            if(v[n][j][k]!=0 && j/gcd(j,k)==ma && k/gcd(j,k)==mb){
                answer=min(answer, v[n][j][k]-1);
            }
        }
    }

    if(answer!=5000) cout<<answer;
    else cout<<-1;
    return 0;
}

Measured memory_bytes: 10624
#include<iostream>

int main(){
    int i,j,k;
    int n,m,l;

    std::cin>>n>>m>>l;

    long int a[n][m],b[m][l],c[n][l];

    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            c[i][j]=0;
        }
    }

    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            std::cin>>a[i][j];
        }
    }

    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            std::cin>>b[i][j];
        }
    }

    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                c[i][j]+=a[i][k]*b[k][j];
            }
            if(j==l-1){
                std::cout<<c[i][j]<<std::endl;
            }else{
                std::cout<<c[i][j]<<" "<<std::flush;
            }    
        }
    }  
    return 0;
}




Measured memory_bytes: 3324
import java.util.Scanner;

public class Main {



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

		int[][] a = new int[3][3];
		boolean[][] b = new boolean[3][3];

		for(int i = 0 ; i < 3 ; i++) {
			for(int j = 0 ; j < 3 ; j++) {
				a[i][j] = Integer.parseInt(sc.next());
				b[i][j] = false;
			}			
		}


		int n = Integer.parseInt(sc.next());

		for(int k = 0 ; k < n ; k++) {
			int tmp = Integer.parseInt(sc.next());
			for(int i = 0 ; i < 3 ; i++) {
				for(int j = 0 ; j < 3 ; j++) {
					
				if(a[i][j] == tmp) {
					b[i][j] = true;
				}	
					
					
				}			
			}
		}

		
		String ans = "No";
		for(int i = 0 ; i < 3 ; i++) {
			if(b[i][0] && b[i][1] && b[i][2]){
				ans = "Yes";
				break;
			}
			
			if(b[0][i] && b[1][i] && b[2][i]){
				ans = "Yes";
				break;
			}
		}
		
		if(b[0][0] && b[1][1] && b[2][2]) {
			ans = "Yes";
		}
		
		if(b[2][0] && b[1][1] && b[2][0]) {
			ans = "Yes";
		}
	
		System.out.println(ans);
		
		
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=5010,M=210;
ll c[N][N];
int a[N][M],v[N],s[N],l[N],r[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,m;
    ll ans=0;
    cin>>n>>m;
    for(int i=2;i<=n;i++) s[i]=gi();
    for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++) a[i][j]=gi();
    for(int j=1;j<=m;j++) {
	int tp=0;
	for(int i=1;i<=n;i++) l[i]=r[i]=1;
	for(int i=n;i;i--) {
	    while(tp&&a[i][j]>=a[v[tp]][j]) --tp;
	    r[i]=(tp?v[tp]-1:n);
	    v[++tp]=i;
	}
	tp=0;
	for(int i=1;i<=n;i++) {
	    while(tp&&a[i][j]>a[v[tp]][j]) --tp;
	    l[i]=(tp?v[tp]+1:1);
	    v[++tp]=i;
	}
	for(int i=1;i<=n;i++) {
	    int z=a[i][j];
	    c[l[i]][i]+=z,c[l[i]][r[i]+1]-=z;
	    c[i+1][i]-=z,c[i+1][r[i]+1]+=z;
	}
    }
    for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	    c[i][j]+=c[i-1][j]+c[i][j-1]-c[i-1][j-1];
    for(int i=1;i<=n;i++) {
	ll sum=0;
	for(int j=i;j<=n;sum+=s[++j])
	    ans=max(ans,c[i][j]-sum);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 200192
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N;
    string S;
    cin >> N >> S;
    int max_count = 0;
    int now = 0;
    for (int i=0; i<N; i++) {
        if (S[i] == 'I') {
            now += 1;
        } else {
            now -= 1;
        }

        if (now > max_count) {
            max_count = now;
        }
    }

    cout << max_count << endl;
    return 0;
}

Measured memory_bytes: 3604
X = int(input())
if 1800 <= X:
    print(1)
    exit()

if 1600 <= X:
    print(2)
    exit()

if 1400 <= X:
    print(3)
    exit()

if 1200 <= X:
    print(4)
    exit()

if 1000 <= X:
    print(5)
    exit()

if 800 <= X:
    print(6)
    exit()

if 600 <= X:
    print(7)
    exit()

if 400 <= X:
    print(8)
    exit()


Measured memory_bytes: 61628
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,m;
  cin>>n>>m;
  vector<vector<int> > G(n);
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
  }
  int s,t;
  cin>>s>>t;
  s--;t--;
  vector<vector<int>> dp(3,vector<int>(n,-1));
  using P = pair<int, int>;
  queue<P> que;
  dp[0][s]=0;
  que.emplace(0,s);
  while(!que.empty()){
    int d,v;
    tie(d,v)=que.front();que.pop();//帅！
    int nd=(d+1)%3;
    for(int u:G[v]){
      if(~dp[nd][u]) continue;
      dp[nd][u]=dp[d][v]+1;
      que.emplace(nd,u);
    }
  }
  if(~dp[0][t]) dp[0][t]/=3;
  cout<<dp[0][t]<<endl;
  return 0;
}


Measured memory_bytes: 7296
n = int(input());
s = input();
max = 0;
set = [chr(i) for i in range(97,123)];
for i in range(1,n) :
    x = s[:i];
    y = s[i:];
    cnt = 0;
    #print(x,y,max);
    for ch in set :
        #print(ch);
        if x.find(ch) >= 0 and y.find(ch) >= 0 :
            cnt += 1;
    if cnt > max :
        max = cnt;

print(max);

Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
//桁数把握
ll keta(ll a){
	ll count=0;
	while(a!=0){
		a=a/10;
		count++;
	}
	return count;
}
int main()
{
	ll N,M,ANS=0;
	vector<pair<ll,ll>>V;
	cin>>N>>M;
	rep(i,N){
		pair<ll,ll>t;
		cin>>t.first>>t.second;
		V.push_back(t);
	}
	sort(V.begin(),V.end());
	rep(i,N){
		for(;;){
			V[i].second--;
			M--;
			ANS=ANS+V[i].first;
			if(V[i].second==0||M==0)break;
		}
		if(M==0)break;
	}
	cout<<ANS<<endl;
}

Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<bitset>
using namespace std;
int main(){
    int n,a,x,ans=0;
    bool y;
    cin>>n;
    vector<pair<int,bool>>q[n];
    for(int i=0;i<n;i++){
        cin>>a;
        for(int j=0;j<a;j++){
            cin>>x>>y;
            q[i].push_back(make_pair(x,y));
        }
    }
    bool flag;

    for(int bit=0;bit<(1<<n);bit++){
        flag=true;
        bitset<15>bit_flag(bit);
        //cout<<bit_flag<<endl;
        for(int i=0;i<n;i++){
            //cout<<i<<"人目"<<endl;
            if(bit_flag[i]==false)continue;
            for(auto v:q[i]){
                bool f=v.second;
                if(bit_flag[v.first-1]!=f)flag=false;
            }
        }
        if(flag)ans=max(ans,int(bit_flag.count()));
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int a_noriho=sc.nextInt();
		int b=sc.nextInt();
		int b_noriho=sc.nextInt();

		int kei=Math.min(a,a_noriho)+Math.min(b,b_noriho);
		System.out.println(kei);
	}
}

Measured memory_bytes: 21716
import math
x = int(input())
if x ==2:
    print(2)
    exit()
while True:
    result = math.ceil((x-3)/2)
    for i in range(3,x,2):
        if x % i != 0:
            result -=1
    if result == 0:
        print(x)
        break
    x=x+1

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std; 
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
 
typedef long long int ll; 
typedef long double ld; 
 
#define MAX 300005
#define endl '\n'
#define UPPER 1000000000

int main(){
	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n, x, t;
	cin>>n>>x>>t;
	
	cout<<ll(ceil(n/(x+0.0L)))*t;
	
}


Measured memory_bytes: 3628
#include<stdio.h>
int x=1;
int y=1;
int f=0;
int c[40],d[40]={0};
int a,b;
int z;
int miti(int x,int y);
int main(){
  int e=0;
  int ans=0;
  while(1){
    scanf("%d %d",&a,&b);
    if(a==0&&b==0)break;
    scanf("%d",&f);
    for(e=0;e<f;e++){
      scanf("%d %d",&c[e],&d[e]);
    }
    ans=miti(x,y);
    printf("%d\n",ans);
    x=1;
    y=1;
    ans=0;
    for(e=0;e<40;e++){
    c[e]=0;
    d[e]=0;
    }
  }
  return 0;
}
int miti(int x,int y){
  for(z=0;z<f;z++){
    if(x==c[z]&&y==d[z]){
      return 0;
    }
  }
  if(x==a&&y==b){
    return 1;
  }
  else if(x==a){
    return miti(x,y+1);
  }
  else if(y==b){
    return miti(x+1,y);
  }
  else{
    return miti(x+1,y)+miti(x,y+1);
  }
}

Measured memory_bytes: 600
#include <iostream>
#include <cmath> 
#include <string>
#include<bits/stdc++.h> 
#define ll long long 
//deepaz
using namespace std;
//int num = stoi(a); -> str to int
//a = to_string(num); -> int to str
//total += c-48; -> char to int

//comparison func
bool comp(int x,int y){
	return x<y;
}
//char to int
int to_int(char c){
	return c;
}
//minimum in array
int getMin(long long arr[], int n,long long idx){ 
	long long res;
    for (int i = idx; i <= n; i++) 
        res = min(res, arr[i]); 
    return res; 
}
//get divisors of number 
int divisors(int n){
	long long cnt = 0;
	for(int i=1;i<sqrt(n);i++){
		if(n%i==0){
			cnt++;
		}
	}
	return cnt;
}
//find if prime
bool isPrime(ll n){
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}
//display prime in faster way
void dispPrime(ll n){
	long long num = 1e6;
	bool prime[num+num+num];
	memset(prime,true,sizeof(prime));
	for(int i=2;i*i<num+num+num;i++){
		if(prime[i]){
			for(int j=i*2;j<num+num+num;j+=i){
				//cout<<"i: "<<i<<"j: "<<j<<"\n";
				prime[j] = false;
			}
		}
	}
	ll k = 2;
	ll cnt = 0;
	//ll upto = 2e6; //for summing prime upto certain number
	//ll tot = 0;
	while(true){
		if(prime[k]){
			//tot += k;
			cnt++;
			cout<<k<<" ";
		}
		if(cnt==n){break;}
		//if(k>=upto){break;}
		k++;
	}
	//cout<<tot<<"\n";
}

void solve(){
}

	//#ifndef ONLINE_JUDGE
	//freopen("leapfrog_ch__sample_input.txt","r",stdin);
	//cout<<"Case #"<<cnt<<": "<<solve()<<"\n";
	//freopen("leapfrog_ch__sample_output.txt","w",stdout);
	//#endif
int main(){
	ll t;
	double d;
	cin>>t>>d;
	ll cnt = 0;
	while(t--){
		double x1,x2;
		cin>>x1>>x2;
		if(sqrt(pow(x1,2)+pow(x2,2))<=d){
			cnt++;
		}
	}
	cout<<cnt<<"\n";
	return 0;
}






Measured memory_bytes: 3704
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;

int n,i,r,ans;
set<int> S;

int main()
{
    cin>>n;
    for (i=0;i<n;i++) 
    {
        cin>>r;
        if (S.count(r)) {S.erase(r);ans--;}
        else {S.insert(r);ans++;}
        }
    cout<<ans;
    return 0;
}


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

int main(){
    int a[25565] = {0};
    int b[25565] = {0};
    string op[25565] = {""};
    int i = 0;
    do{
        cin >> a[i] >> op[i] >> b[i];
        i++;
    }while(op[i-1] != "?");
    i = 0;
    do{
        if(op[i] == "+"){
            cout << a[i] + b[i] << endl;
        }
        if(op[i] == "-"){
            cout << a[i] - b[i] << endl;
        }
        if(op[i] == "*"){
            cout << a[i] * b[i] << endl;
        }
        if(op[i] == "/"){
            cout << a[i] / b[i] << endl;
        }
        i++;
        }while(op[i-1] != "?");
}

Measured memory_bytes: 1620
#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main(void){
 int H, W, sum = 0, sum2 = 0;
 int i,j;
  
 cin >> H >> W;
 vector<string>s(H);
 for (i = 0;i < H;++i)cin >> s[i];

  
 for (i = 0;i < H-sum;++i) {
 int count = 0; 
 for (j = 0;j < W;++j)if (s[i][j] == '.')++count;
 if (count == W) {
   s.erase(s.begin()+i);
   --i;
   ++sum;
  }
 }
 
 for (j = 0;j < W-sum2;++j) {
 int count2 = 0;
 for (i = 0;i < H-sum;++i)if (s[i][j] == '.')++count2;
 if (count2 == H-sum) {
  for (i = 0;i < H-sum;++i)s[i].erase(s[i].begin() + j); 
   --j;
   sum2++;
  }
 }
 
  
 for (int i = 0;i < s.size();++i)cout << s[i] << endl;
 
 return 0;
    
}


Measured memory_bytes: 256
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map


int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll maxval = 10e5 + 100;
	int n, W; cin >> n >> W;
	vpi wv = vpi();
	rep(i, n){
		int w, v; cin >> w >> v;
		wv.pb({w, v});
	}
	vll dp = vll(maxval+1, LLINF);
	dp[0] = 0;
	for (const auto& [w, v] : wv){
		for(int i = maxval; i >= 0; i--){
			if (i - v < 0) break;
			dp[i] = min(dp[i], dp[i-v] + w);
		}
	}
	for(int i = maxval; i >= 0; i--){
		if (dp[i] <= W){
			cout << i;
			break;
		}
	}
}

Measured memory_bytes: 11100
#include <iostream>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    bool judge = false;
    int x = A * B;
    
    for(int C = 1; C <= 3; C++){
        if(x * C % 2 != 0){
            judge = true;
            break;
        }
    }
    
    if(judge){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

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

int main(){
  long long int n,i,kotae=0;
  cin>>n;
  for(i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0){
      kotae+=i;
    }
  }
  cout<<kotae;
}
  

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

long dp[60][60][2600] = { 0 };

void solve() {
  long N, A;
  cin >> N >> A;
  vector<long> x(N);
  rep (i, N) cin >> x[i];

  dp[0][0][0] = 1;
  for (long i = 0; i < N; i++) {
    long num = x[i];
    for (long j = 0; j < N; j++) {
      for (long foo = 0; foo + num <= A * N; foo++) {
        dp[i+1][j+1][foo+num] += dp[i][j][foo];
      }
      for (long foo = 0; foo <= A * N; foo++) {
        dp[i+1][j][foo] += dp[i][j][foo];
      }
    }
  }

  long ans = 0;
  for (long n = 1; n <= N; n++) {
    ans += dp[N][n][n*A];
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 62464
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
count=0
for i in range(N):
    A=list(map(int,input().split()))
    p=C
    for j in range(M):p+=A[j]*B[j]
    if p>0:count+=1
print(count)

Measured memory_bytes: 9168
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val s = input.nextLine()
      val t = input.nextLine()

      output.println(if ((s + s).contains(t)) "Yes" else "No")
    }

  }

}


Measured memory_bytes: 25916
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>

using namespace std;

int main() {
    
    int a,b;
    
    cin >> a >> b;
    
    if(a <= b){
        cout << a;
    }else{
        cout << a-1;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
N  = int(input())
slist = [input() for _ in range(N)]
abc = 'abcdefghijklmnopqrstuvwxyz'
l = [50] * 26
ans = ''
for i in range(26):
    for s in slist:
        l[i] = min(l[i],s.count(abc[i]))
for j in range(26):
    ans = ans + (abc[j] * l[j])
print(ans)
    

Measured memory_bytes: 3060
import sys
readline=sys.stdin.readline

H,W,M = map(int,readline().split())

hcol = [[0,i] for i in range(H)]
wcol = [[0,i] for i in range(W)]

P = set()
for i in range(M):
  h,w = map(int,readline().split())
  h -= 1
  w -= 1
  hcol[h][0] += 1
  wcol[w][0] += 1
  P.add((h,w))
  
hcol = sorted(hcol, key = lambda x:x[0], reverse = True)
wcol = sorted(wcol, key = lambda x:x[0], reverse = True)

hmax = hcol[0][0]
wmax = wcol[0][0]

ans = 0
hind = 0
wind = 0

# 交点がないものがあればhmax + wmaxが答え
found = False
while hind < H:
  while wind < W:
    val = hcol[hind][0] + wcol[wind][0]
    if (hcol[hind][1],wcol[wind][1]) in P:
      val -= 1
    else:
      found = True
      ans = val
      break
    if ans < val:
      ans = val
    wind += 1
    if wind == W or wcol[wind][0] < wmax:
      wind = 0
      break
  if found:
    break
  hind += 1
  if hind == H or hcol[hind][0] < hmax:
    break
    
print(ans)


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

//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long

using namespace std;

const int NN = 1e6 + 7;
const int N = 1e6 + 7;
const int M = 20;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;

void solve1()
{
    ll x,y;
    cin >> x >> y;
    if( x == 1 || y == 1 ){
        cout << 1;
    }
    else cout << (x * y + 1) / 2;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(s[k-1])

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

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    
    int i,t = 0;
    for(i=1;;i++){
    	t += a;
    	if(i>1) t--;
    	if(t>=b) break; 
	}
	if(b==1) cout << 0 << endl;
	else cout << i << endl;
    
	return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimise("Ofast,unroll-loops,no-stack-protector,fast-math");
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")
          
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
          
using namespace std;
using namespace __gnu_pbds;
          
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
          
using matrix = vector<vector<ll>>;
template<typename T>
using kawaii_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
          
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
//#define int long long
 
void FAST_IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(20);
    #ifndef _offline
    //freopen("chess.in", "r", stdin);
    //freopen("chess.out", "w", stdout);
    #endif
}   

signed main() {
    FAST_IO();
    string s;
    ll K;
    cin >> s >> K;
    int n = s.length();
    vector<pair<char, ll>> seg;
    seg.push_back({s[0], 1});
    for (int i = 1; i < n; ++i) {
        if (s[i] != s[i - 1]) {
            seg.push_back({s[i], 1});
        }
        else {
            seg.back().second++;
        }
    }
    ll cost = 0;
    for (auto it : seg) {
        cost += it.second / 2;
    }
    if (seg[0].first == seg.back().first) {
        if ((int)seg.size() == 1) {
            ll res = (seg[0].second * K) / 2;
            cout << res << '\n';
        }
        else {
            seg[0].second += seg.back().second;
            seg.pop_back();
            ll res = 0;
            for (auto it : seg) {
                res += it.second / 2;
            }
            res *= (K - 1);
            res += cost;
            cout << res << '\n';
        }
    }   
    else {
        cost *= K;
        cout << cost << '\n';
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int Array[3005];
long long Prefix[3005] , dp[3005][3005];

void ConstructDP( int N ){
    int i , j;

    for( i = 1 ; i <= N ; ++i )
        dp[i][i] = Array[i];
    
    for( i = 2 ; i <= N ; ++i ){
        for( j = 1 ; j <= N - i + 1 ; ++j ){
            dp[j][j + i - 1] = Array[j] + Prefix[j + i - 1] - Prefix[j] - dp[j + 1][j + i - 1];
            dp[j][j + i - 1] = max( dp[j][j + i - 1] , Array[j + i - 1] + Prefix[j + i - 2] - Prefix[j - 1] - dp[j][j + i - 2] );
        }
    }
}

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

    for( i = 1 ; i <= N ; ++i ){
        scanf( "%d" , Array + i );
        Prefix[i] = Prefix[i - 1] + Array[i];
    }
    
    ConstructDP( N );
    printf( "%lld\n" , 2 * dp[1][N] - Prefix[N] );
    return 0;
}

Measured memory_bytes: 70016
n = int(input())
d = [list(map(int, input().split())) for i in range(n)]
for i in range(n-2):
    if d[i][0] == d[i][1] and d[i+1][0] == d[i+1][1] and d[i+2][0] == d[i+2][1]:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b,c,k; cin>>a>>b>>c>>k;
	while(k--){
		if(a>=b)	b*=2;
		else if(b>=c)	c*=2;
		else{
			Yes();
			return 0;
		}
	}

	if(a<b&&b<c)	Yes();
	else No();


    return 0;
}



Measured memory_bytes: 3644
import qualified Data.ByteString.Char8 as C
import Data.Maybe 
  ( fromJust )

main = do
  _  <- getLine
  as <- map (fst . fromJust . C.readInt) . C.words <$> C.getLine 
  print $ uncurry (-) $ maxMin as

maxMin :: [Int] -> (Int, Int)
maxMin = ((,) <$> maximum <*> minimum ) 

Measured memory_bytes: 508
function main(input) {
	var a = input[0].split(' ');
	if(parseInt(a[0]) < parseInt(a[1])){
		console.log("a < b")
	}else if(parseInt(a[0])==parseInt(a[1])){
		console.log("a == b")
	}else{
		console.log("a > b")
	}
}

var input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main(input);
});

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  string s;
  cin >> s;
  rep(i, s.size()) cout << "x";
  cout << endl;
  return 0;
}


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

unsigned long long popcount(unsigned long long x) {
  x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) +
      (x & 0x5555555555555555UL);
  x = ((x & 0xccccccccccccccccUL) >> 2) +
      (x & 0x3333333333333333UL);
  x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) +
      (x & 0x0f0f0f0f0f0f0f0fUL);
  x = ((x & 0xff00ff00ff00ff00UL) >> 8) +
      (x & 0x00ff00ff00ff00ffUL);
  x = ((x & 0xffff0000ffff0000UL) >> 16) +
      (x & 0x0000ffff0000ffffUL);
  x = ((x & 0xffffffff00000000UL) >> 32) +
      (x & 0x00000000ffffffffUL);
  return x;
}

int n, m;
vector<int> v, p;

int solve();

int main() {
  cin >> n >> m;
  v.assign(m, 0);
  p.resize(m);
  for(int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for(int j = 0; j < k; ++j) {
      int x;
      cin >> x;
      v[i] += (1 << (x - 1));
    }
  }
  for(int i = 0; i < m; ++i) cin >> p[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 0;
  for(int i = 0; i < (1 << n); ++i) {
    bool ch = 1;
    for(int j = 0; j < m; ++j) {
      if(popcount(i & v[j]) % 2 == p[j])
        ;
      else
        ch = 0;
    }
    if(ch) ++ans;
  }
  return ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
#define int long long
#define pb emplace_back
#define Mod 1000000007
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    map<int,bool>m;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            m[i*j] = true;
        }
    }
    if(m[n]) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

string s;

int main(){
    bool flag = true;
    cin >> s;
    char st[26];
    s.copy(st,26);
    if (s.size() < 26){
        for (char i='a';i<='z';i++){
            flag = true;
            for (auto c : st){
                if (i == c) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                cout << s << i << endl;
                return 0;
            }
        }
    } else if (s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
    } else {
        char stn[26];
        s.copy(stn,26);
        next_permutation(stn,stn+26);
        REP(i,26){
            if(st[i] == stn[i]){
                cout << st[i];
            } else{
                cout << stn[i] << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

/*================================================
	GCD function
================================================*/
ll gcd(ll a, ll b) {
	if (a < b) return gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

/*================================================
	LCM function
================================================*/
ll lcm(ll a, ll b) {
	return (a / (gcd(a, b))) * b;
}

ll a[100000];

int main()
{
	int N;
	ll M, LCM, ans = 0;

	cin >> N >> M;
	rep(i, N) cin >> a[i];
	rep(i, N) a[i] /= 2;

	if (N == 1) {
		ans = (M / a[0] + 1) / 2;
	}
	else {
		LCM = lcm(a[0], a[1]);
		if (LCM > M) ans = 0;
		else {
			repc(i, 2, N - 1) {
				LCM = lcm(LCM, a[i]);
				if (LCM > M) break;
			}
			if (LCM > M) ans = 0;
			else {
				bool ok = true;
				rep(i, N) {
					if ((LCM / a[i]) % 2 == 0) ok = false;
				}

				if (ok) ans = (M / LCM + 1) / 2;
				else ans = 0;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024