akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define pb push_back
#define BEGIN 0
#define END 201
#define x first
#define y second

using namespace std;

pair<int,int> data[105];
vector<int> gph[205],rev[205];
bitset<205> maxflowhsh;
int cost[205][205];

int updateAugmentPath(int now,int t,int limit)
{
  if (maxflowhsh[now])return INT_MIN;
  maxflowhsh[now]=true;
  if (now==t)return limit;
  for(int c=0;c<gph[now].size();c++)
  {
    if (cost[now][gph[now][c]]>0)
    {
      int tmp=updateAugmentPath(gph[now][c],t,min(limit,cost[now][gph[now][c]]));
      if (tmp!=INT_MIN)
      {
        cost[now][gph[now][c]]-=tmp;
        cost[gph[now][c]][now]+=tmp;
        return tmp;
      }
    }
  }
  for(int c=0;c<rev[now].size();c++)
  {
    if (cost[now][rev[now][c]]>0)
    {
      int tmp=updateAugmentPath(rev[now][c],t,min(limit,cost[now][rev[now][c]]));
      if (tmp!=INT_MIN)
      {
        cost[now][rev[now][c]]-=tmp;
        cost[rev[now][c]][now]+=tmp;
        return tmp;
      }
    }
  }
  return INT_MIN;
}

int maxflow(int s,int t)
{
  int r=0;

  maxflowhsh.reset();
  while(updateAugmentPath(s,t,INT_MAX)!=INT_MIN)maxflowhsh.reset();
  for(int c=0;c<rev[END].size();c++)
  {
    r+=cost[END][rev[END][c]];
  }
  return r;
}

int main()
{
  int n,ix,iy;

  scanf("%d",&n);
  for(int c=1;c<=n;c++)
  {
    scanf("%d%d",&data[c].x,&data[c].y);
    cost[100+c][END]=1;
    cost[END][100+c]=0;
    gph[100+c].pb(END);
    rev[END].pb(100+c);
  }
  for(int c=1;c<=n;c++)
  {
    scanf("%d%d",&ix,&iy);
    cost[BEGIN][c]=1;
    cost[c][BEGIN]=0;
    gph[BEGIN].pb(c);
    rev[c].pb(BEGIN);
    for(int c2=1;c2<=n;c2++)
    {
      if (ix>data[c2].x&&iy>data[c2].y)
      {
        cost[c][100+c2]=1;
        cost[100+c2][c]=0;
        gph[c].pb(100+c2);
        rev[100+c2].pb(c);
      }
    }
  }
  printf("%d\n",maxflow(BEGIN,END));
}


Measured memory_bytes: 512
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

//Tariquzzaman Faisal
//_Faisal101_
//IUT_CSE'19
//190041101

#include<iostream>
#include<stdio.h>
#include<vector>
#include<deque>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<climits>
#include<cmath>
#include<iterator>
#include<set>
#include<bitset>
#define fileOut freopen("out.txt","w",stdout)
#define fileIn freopen("in.txt","r",stdout)
#define testcases ll TC,T; cin >> TC; for(T=1; T<=TC; T++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define INFLL 9223372036854775807
#define INF 2147483647
#define pi acos(-1.0)
#define ll long long
#define endll printf("\n")
#define CASE printf("Case %lld: ",T)
#define ff first
#define ss second
#define mem(ara,n) memset(ara,n,sizeof ara)
#define ull unsigned long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mid3(a,b,c) min(max(a,b),max(b,c),max(a,b))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define endl '\n'
#define ld long double


using namespace std;

bitset <2000009> dp;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	dp[0] = 1;
	int n;
	cin >> n;
	int total = 0, x;
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		total += x;
		dp |= dp << x;
	}
	for (int i = total / 2; i >= 0; --i)
	{
		if (dp[i]) {
			cout << total - i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a[4];
    while(cin>>a[0]>>a[1]>>a[2]){
        sort(a,a+3);
        if(a[0]==5&&a[1]==5&&a[2]==7)cout<<"YES"<<endl;\
        else cout<<"NO"<<endl;
    }
    return 0;
}


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

void solve(long long N, long long M, std::vector<long long> A){
    priority_queue<ll> pq;
    for(int i=0;i<N;i++){
        pq.push(A[i]);
    }
    for(int i=0;i<M;i++){
        ll t = pq.top();
        pq.pop();
        t /=2;
        pq.push(t);
    }
    ll ans =0;
    for(int i=0;i<N;i++){
        ll t = pq.top();
        pq.pop();
        ans += t;
    }
    cout << ans << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 2168
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	gateL := make([]int, m)
	gateR := make([]int, m)

	for i := 0; i < m; i++ {
		fmt.Scan(&gateL[i], &gateR[i])
	}

	sort.Ints(gateL)
	sort.Ints(gateR)

	maxL := gateL[m-1]
	minR := gateR[0]

	if minR < maxL {
		fmt.Println(0)
		return
	}

	fmt.Println(minR - maxL + 1)
}


Measured memory_bytes: 5504
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<functional>
#include<math.h>

using namespace std;

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

	int x;
	cin >> x;

	int limit = sqrt(x);

	int max=1;
	for(int i=2;i<=limit;i++){
		int num=i;
		while(1){
			if(num*i <= x)num*=i;
			else break;
		}
		if(max < num) max=num;
	}
	cout << max << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=2000;


int main() {
  ll N,c=1;
  cin>>N;
  ll a[N];
  ll b[2*N];
  ll ac[N+1];
  ll ad[N+1];
  ll bd[N+1];
  ll bc[N+1];
  rep(i,N+1){
    ac[i]=0;bc[i]=0;
  }
  rep(i,N){
    cin>>a[i];
    ac[a[i]]++;
    ad[a[i]]=1;
  }
  rep(i,N){
    cin>>b[i];
    b[i+N]=b[i];
    bc[b[i]]++;
    bd[b[i]]=1;
  }
  ll x=0;
  rep(i,N+1){
    if(ac[i]+bc[i]>N){
      c=0;
    }
    if(i){
      ac[i]+=ac[i-1];
      bc[i]+=bc[i-1];
    }
  }
  for(int i=1;i<N+1;i++){
    if(ad[i]==1&&bd[i]==1){
      x=max(x,ac[i]-bc[i-1]);
     // cout<<ac[i]<<" "<<bc[i-1]<<"/";
    }
  }
  if(c){
    cout<<"Yes"<<endl;
    for(int i=N-x;i<2*N-x;i++){
      cout<<b[i]<<" ";
    }
  }
  else{
    cout<<"No";
  }
}



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

int main(){
    string s; cin>>s;
    int a=0,b=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1')a++;
        else b++;
    }
    cout<<2*min(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <ctime>
#include <queue>
#include <sstream>
#include <utility>
#include <bitset>

using namespace std;

#define MP make_pair 
#define PB push_back 
#define INF (1000000007) 
#define eps 1e-8

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

int n,p;
ll ans[2];
int a[100005];
vector<int> v[2];
ll c[105][105];

int main()
{
	cin>>n>>p;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		a[i]%=2;
		v[a[i]].PB(i);
	}
	c[0][0]=1;
	c[1][0]=c[1][1]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			c[i][j]=c[i-1][j]+c[i-1][j-1];
		}
	}
	int q1=v[0].size(),q2=v[1].size();
	ll a1=0,a2=0;
	for(int i=0;i<=q1;i++)
	{
		for(int j=0;j<=q2;j++)
		{
//			cout<<c[q1][i]<<" "<<c[q2][j]<<endl;
			if(j%2) ans[1]+=c[q1][i]*c[q2][j];
			else ans[0]+=c[q1][i]*c[q2][j];
		}
	}
	cout<<ans[p];
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int[] answer = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            int A = scanner.nextInt();
            answer[A] = i;
        }

        for (int i = 1 ; i <= N ; i++) {
            System.out.printf("%d ", answer[i]);
        }
        System.out.println();
    }
}


Measured memory_bytes: 64836
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=0;4*i<=n;++i)
        if((n-4*i)%7==0)
        {
            cout<<"Yes";
            return 0;
        }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
l = input()
k = 0
while 2 ** (k + 1) <= l:
	k += 1
n = k + 1
e = []
for i in range(k):
	e.append((i + 1, i + 2, 0))
	e.append((i + 1, i + 2, 2 ** i))

for i in range(k):
	if l >> i & 1:
		e.append((i + 1, n, (l - 1) >> (i + 1) << (i + 1)))

print n, len(e)
for x, y, z in e:
	print x, y, z

Measured memory_bytes: 2692
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    long long n, a[100001], b[100001], i, ans=0;

    cin >> n;
    for(i=0;i<=n;i++){
        cin >>a[i];
    }
    for(i=0;i<n;i++){
        cin >> b[i];
    }

    for(i=0;i<n;i++){
        ans=ans+min(a[i], b[i]);
        b[i]=b[i]-a[i];
        if(b[i]>0){
            ans=ans+min(a[i+1], b[i]);
            if(a[i+1]-b[i]>=0) a[i+1]=a[i+1]-b[i];
            else a[i+1]=0;
        }
    }

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


Measured memory_bytes: 1792
N,A,B = map(int,input().split())
 
if (A-B)%2 == 0:
  Ans=abs(A-B)//2
  print(Ans)
else:
  if N%2 == 0:
    N_center =N//2
    if abs(A-N_center) >= abs(B-N_center):
      #Aの方が中心から遠い(早くゴールに着く)
      if A >= N_center:
        #A,BがN側に向かう場合(Aが先)
        A_reach = N - A
        B_reach = N - B
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + (B_nokori - 1)//2
        print(Ans)
      else:
        #A,Bが1側に向かう場合(Aが先)
        A_reach = A - 1
        B_reach = B - 1
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + (B_nokori - 1)//2
        print(Ans)
    else:
      #Bの方が中心から遠い(早くゴールに着く)
      if B >= N_center:
        #A,BがN側に向かう場合(Bが先)
        A_reach = N - A
        B_reach = N - B
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + (A_nokori - 1)//2
        print(Ans)
      else:
        #A,Bが1側に向かう場合(Bが先)
        A_reach = A - 1
        B_reach = B - 1
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + (A_nokori - 1)//2
        print(Ans)
  else:
    N_center = N//2 + 1
    if abs(A-N_center) >= abs(B-N_center):
      #Aの方が中心から遠い(早くゴールに着く)
      if A >= N_center:
        #A,BがN側に向かう場合(Aが先)
        A_reach = N - A
        B_reach = N - B
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + (B_nokori - 1)//2
        print(Ans)
      else:
        #A,Bが1側に向かう場合(Aが先)
        A_reach = A - 1
        B_reach = B - 1
        B_nokori = B_reach - A_reach
        Ans = A_reach + 1 + (B_nokori - 1)//2
        print(Ans)
    else:
      #Bの方が中心から遠い(早くゴールに着く)
      if B >= N_center:
        #A,BがN側に向かう場合(Bが先)
        A_reach = N - A
        B_reach = N - B
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + (A_nokori - 1)//2
        print(Ans)
      else:
        #A,Bが1側に向かう場合(Bが先)
        A_reach = A - 1
        B_reach = B - 1
        A_nokori = A_reach - B_reach
        Ans = B_reach + 1 + (A_nokori - 1)//2
        print(Ans)

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

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

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	vector<lint> dp1(n+1); // dp1[i] = ([0, i] について, i から始めて i で終わるときの最小コスト)
	vector<lint> dp2(n+1); // dp2[i] = ([0, i] について, i から始めて i より左で終わるときの最小コスト)
	vector<lint> dp3(n+1); // dp3[i] = ([i, n] について, i から始めて i で終わるときの最小コスト)
	vector<lint> dp4(n+1); // dp4[i] = ([i, n] について, i から始めて i より右で終わるときの最小コスト)
	lint sum=0;
	rep(i,n){
		sum+=a[i];
		dp1[i+1]=min(dp1[i]+(a[i]==0?2:a[i]%2),sum);
		dp2[i+1]=min(dp1[i],dp2[i])+(a[i]+1)%2;
	}
	sum=0;
	for(int i=n-1;i>=0;i--){
		sum+=a[i];
		dp3[i]=min(dp3[i+1]+(a[i]==0?2:a[i]%2),sum);
		dp4[i]=min(dp3[i+1],dp4[i+1])+(a[i]+1)%2;
	}

	lint ans=INF;
	rep(i,n+1) ans=min({ans,dp1[i]+dp3[i],dp1[i]+dp4[i],dp2[i]+dp3[i]});
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 8064
let as_num_list s =
  let splitted = String.split_on_char ' ' s in
  List.map int_of_string splitted

(* 累積和を作る *)
let rec make_cumulative_sum sum_a a_list = match a_list with
    [] -> []
  | first :: rest ->
     let sumMinusFirst = sum_a - first in
     let nextSum = if sumMinusFirst < 0
                   then sumMinusFirst + 1000000007
                   else sumMinusFirst in
     nextSum :: make_cumulative_sum nextSum rest
  
let find_sum_of_product_of_pairs a_list cumulative_sum =
  List.fold_left2
    (fun acc x y -> (acc + x * y) mod 1000000007)
    0
    a_list
    cumulative_sum

let main () =
  let _ = Scanf.sscanf (read_line ()) "%d" (fun x -> x) in (* nは飛ばす *)
  let as_str = read_line () in
  let a_list = as_num_list as_str in
  let sum_a = List.fold_left (fun acc x -> (x + acc) mod 1000000007) 0 a_list in
  let cumulative_sum = make_cumulative_sum sum_a a_list in
  let ans = find_sum_of_product_of_pairs a_list cumulative_sum in
  (
    Printf.printf "%d" ans;
    print_newline ()
  )

let _ = main ()


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

using namespace std;

int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(x==y)printf("Draw");
    else if(x==1)printf("Alice");
    else if(y==1)printf("Bob");
    else if(x>y)printf("Alice");
    else if(x<y)printf("Bob");
    return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define zeroes(x) memset(x,0,sizeof(x))
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;
ll check=0,ans=0;
pair<pair<ll,ll>,ll> edge[5010];
void BellmanFord( ll src,ll n,ll m) 
{   ll V=n,E=m;
    ll dist[V]; 
  
    // Step 1: Initialize distances from src to all other vertices 
    // as INFINITE 
    for (ll i = 0; i < V; i++) 
        dist[i] = INT_MAX; 
    dist[src] = 0; 
  
    // Step 2: Relax all edges |V| - 1 times. A simple shortest 
    // path from src to any other vertex can have at-most |V| - 1 
    // edges 
    for (ll i = 1; i <= V - 1; i++) { 
        for (ll j = 0; j < E; j++) { 
            ll u = edge[j].ff.ff; 
            ll v = edge[j].ff.ss; 
            ll weight = edge[j].ss; 
            if (dist[u] != INT_MAX && dist[u] + weight < dist[v]) 
                dist[v] = dist[u] + weight; 
        } 
    }

    ll temp=dist[n-1];  
    for (ll i = 1; i <= V - 1; i++) { 
        for (ll j = 0; j < E; j++) { 
            ll u = edge[j].ff.ff; 
            ll v = edge[j].ff.ss; 
            ll weight = edge[j].ss; 
            if (dist[u] != INT_MAX && dist[u] + weight < dist[v]) 
                dist[v] = dist[u] + weight; 
        } 
    } 
    if(temp!=dist[n-1])
    {
        check=-1;
        return ;
    }
    ans=dist[V-1];
    return ;
  
     
} 
int main()
{		
	
    
    IOS
    ll n,m,p;
    cin>>n>>m>>p;

    for(ll i=0;i<m;i++)
    {
        cin>>edge[i].ff.ff>>edge[i].ff.ss>>edge[i].ss;
        edge[i].ff.ff--;
        edge[i].ff.ss--;
        edge[i].ss-=p;  
        edge[i].ss*=(-1);      
    }

    BellmanFord(0,n,m);
    if(check==-1)
    {
        cout<<-1;
    }
    else
    {
        cout<<max(-ans,0LL);
    }





}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

struct process {
	char name[20];
	int time;
	int consume;
};

int head, tail, MAX;
process queue[100000];

void initialize(int max) {
	MAX = max + 1;

	head = 0;
	tail = 0;
}

void enqueue(process p) {
	queue[tail] = p;
	tail += 1;
	if (tail == MAX) {
		tail = 0;
	}
}

process dequeue() {
	process p = queue[head];
	head += 1;
	if (head == MAX) {
		head = 0;
	}
	return p;
}

bool isEmpty() {
	return head == tail;
}

int main() {
	int n, q;

	cin >> n;
	cin >> q;

	initialize(n);

	for (int i = 0; i < n; i++) {
		process tmp;
		cin >> tmp.name; 
		cin >> tmp.time; 
		enqueue(tmp);
	}
	
	int consumed = 0;

	while (!isEmpty()) {
		process p = dequeue();
		
		if (p.time <= q) {
			consumed += p.time;
			cout << p.name << " " << consumed << endl;
		} else {
			consumed += q;
			p.time -= q;
			enqueue(p);
		}
	}
}

Measured memory_bytes: 4352
import sys    #インタプリタや実行環境に関する情報を扱うためのライブラリ
import os     #フォルダやファイルを操作
import math

N=int(input())
count=0

for i in range(N+1):
    if i==0:
        continue
    if i<10:
        count +=1
    if i<100:
        continue
    elif i<1000:
        count +=1
    elif i<10000:
        continue
    elif i<100000:
        count+=1

print(count)

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

class Main {

    public static int[] sieve( int max ) {
	boolean[] prime = new boolean[max + 1];
	Arrays.fill( prime, true );
	final int lim = ( int )Math.ceil( Math.sqrt( max ) );
	prime[0] = prime[1] = false;
	int index = 2;
	while ( index <= lim ) {
	    for ( int i = 2 * index; i <= max; i += index ){
		prime[i] = false;
	    }
	    while ( !prime[++index] && index <= lim );
	}
	final int count = count( prime, true );
	final int[] answer = new int[count];
	index = 0;
	for (int i = 0; i < prime.length; i++ ) {
	    if ( prime[i] ) {
		answer[index] = i;
		index++;
	    }
	}
	return answer;
    }

    private static int count( boolean[] array, boolean val ) {
	int count = 0;
	for ( boolean b : array ) {
	    if ( val == b ) {
		count++;
	    }
	}
	return count;
    }
    
    public static void main( String[] args ) {

	final int[] primes = sieve( 10000 );
	final Scanner stdin = new Scanner( System.in );

	while ( stdin.hasNext() ) {
	    final int n = stdin.nextInt();
	    if ( n == 0 ) {
		break;
	    }

	    final int insertPoint = Arrays.binarySearch( primes, n );
	    int index = insertPoint >= 0 ? insertPoint : (- insertPoint - 1);
	    index = Math.max( 0, Math.min( primes.length - 1, index ) );
	    while ( index >= 0 && primes[index] > n ) {
		index--;
	    }
	    while (index > 0 && primes[index] - primes[index - 1] != 2) {
		index--;
	    }
	    System.out.println(primes[index - 1] + " " + primes[index]);
	}
	
    }
    
}

Measured memory_bytes: 35492
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

K = int(input())
S = input()

if len(S) <= K:
    print(S)
else:
    print(S[:K] + "...")

Measured memory_bytes: 9180
from collections import deque
MOD = 10**9 + 7
n, k = [int(item) for item in input().split()]
edge = [[] for _ in range(n)]

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

dq = deque()
dq.append([-1, 0, 0])

ans = 1
while(dq):
    prev, n, d = dq.popleft()
    if d == 0:
        ans *= k
        ans %= MOD
        same_dim = 0
        for item in edge[n]:
            if item == prev:
                continue
            ans *= k - 1 - same_dim
            ans %= MOD
            same_dim += 1
            dq.append([n, item, d+1])
    elif d == 1:
        same_dim = 0
        for item in edge[n]:
            if item == prev:
                continue
            ans *= k - 2 - same_dim
            ans %= MOD
            same_dim += 1
            dq.append([n, item, d+1])
    else:
        same_dim = 0
        for item in edge[n]:
            if item == prev:
                continue
            ans *= k - 2 - same_dim
            ans %= MOD
            same_dim += 1
            dq.append([n, item, d+1])
print(ans)


Measured memory_bytes: 73888
#include <stdio.h>
#include <float.h>
int main(void){
    int a=0;
    scanf("%d",&a);
    int c[a];
    for(int i=0;i<a;i++){
        c[i]=0;
        scanf("%d",&c[i]);
    }
    int max=0;
    int maxnum=0;
    for(int i=0;i<a;i++){
        if(c[i]>max){
            max=c[i];
            maxnum=i;
        }
    }
    int sum=0;
    for(int i=0;i<a;i++){
        sum=sum+c[i];
    }
    if(sum>(2*max)){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

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

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

  vector<int> v;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] % 10) v.push_back(s[i]);
    ans += s[i];
  }

  if (ans % 10 == 0) {
    sort(v.begin(), v.end());
    if (v.size()) ans -= v.front();
    else ans = 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a;
    int b;
    int c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    if(a<b && b<c && a<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <queue>
#include <functional>

using P = std::pair<int, std::pair<int, int>>;

constexpr int MAX_N = 5000, INF = (int)1e9;

int n, k;
int C[MAX_N], R[MAX_N];

std::vector<int> G[MAX_N];

int d[MAX_N][MAX_N];

int dijkstra(int s, int g) {
	std::priority_queue<P, std::vector<P>, std::greater<P>> que;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			d[i][j] = INF;
	}
	d[s][0] = 0;
	que.push({ d[s][0],{ 0,s } });

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second.second;

		if (v == g)
			return p.first;

		for (int i = 0; i < G[v].size(); ++i){
			if (p.second.first) {
				if (d[G[v][i]][p.second.first - 1]>d[v][p.second.first]) {
					d[G[v][i]][p.second.first - 1] = d[v][p.second.first];
					que.push(P(d[G[v][i]][p.second.first - 1], std::make_pair(p.second.first - 1, G[v][i])));
				}
			}
			if (d[G[v][i]][R[v] - 1] > d[v][p.second.first] + C[v]) {
				d[G[v][i]][R[v] - 1] = d[v][p.second.first] + C[v];
				que.push(P(d[G[v][i]][R[v] - 1], std::make_pair(R[v] - 1, G[v][i])));
			}
		}
	}
	return -1;
}

int main() {
	std::cin >> n >> k;

	for (int i = 0; i < n; ++i)
		std::cin >> C[i] >> R[i];
	int a, b;
	for (int i = 0; i < k; ++i) {
		std::cin >> a >> b;
		--a;
		--b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	std::cout << dijkstra(0, n - 1) << std::endl;

	return 0;
}

Measured memory_bytes: 101196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;


const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ok = 0, ng = n/2+1;
    rolling_hash rh(s);
    while(ng-ok>1){
        int len = (ok+ng)/2;
        map<pair<ll,ll>,int> mp;
        bool can = false;
        rep(i,n-len+1){
            pair<ll,ll> hash = {rh.hash(i,i+len,0),rh.hash(i,i+len,1)};
            if(mp.count(hash)&&mp[hash]+len<=i){
                can=true;
                break;
            }
            else if(mp.count(hash))continue;
            else mp[hash]=i;
        }
        if(can)ok=len;
        else ng = len;
    }
    cout<<ok<<endl;
    return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
int main(void){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A+B+C==17 && (A==5 || A==7) && (B==5 || B==7) && A+B!=14){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

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

using namespace std;

#define INP "solve"
#define OUT "solve"

const int QQ = 3e5 + 10;
const int maxN = 6e5 + 10;
const int maxM = 1e5 + 100;
const int oo = 1e9 + 100;
const int MOD = 1e9 + 7;
const int Base = 311;
const long double du = 1e-9;
const string YES = "YES";
const string NO = "NO";
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

void doc() {
    freopen(INP ".inp","r",stdin);
    freopen(OUT ".out","w",stdout);
}

void solve() {
    int w, h, n;
    cin >> w >> h >> n;
    if (w < h) swap(w, h);
    cout << (n + w - 1) / w;
}
int main(int argc,char *argv[]) {
    ///srand(time(nullptr));
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
   /// doc();
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, i, j, k, ans, x, y, aa, bb;
	cin >> n;
	vector<long long> a(n + 1), s(n + 1, 0);
	vector<long long>::iterator it, it2;
	for (i = 1; i <= n; i++) {
		cin >> a[i];
		s[i] = s[i - 1] + a[i];
	}
	ans = s[n];

	vector<long long> v(4);
	for (i = 2; i <= n - 2; i++) {
		x = s[i] / 2;
		it = lower_bound(s.begin() + 1, s.begin() + i - 1, x);
		it2 = it - 1;
		if (it == s.begin() + i) v[0] = *it2;
		else if (it2 == s.begin()) v[0] = *it;
		else {
			aa = *it; bb = *it2;
			if (abs(s[i] - aa - aa) <= abs(s[i] - bb - bb)) v[0] = aa;
			else v[0] = bb;
		}
		v[1] = s[i] - v[0];

		y = s[i] + (s[n] - s[i]) / 2;
		it = lower_bound(s.begin() + i + 1, s.begin() + n - 1, y);
		it2 = it - 1;
		if (it == s.begin() + n) v[2] = *it2 - s[i];
		else if (it2 == s.begin() + i) v[2] = *it - s[i];
		else {
			aa = *it; bb = *it2;
			if (abs(s[n] - aa - (aa - s[i])) <= abs(s[n] - bb - (bb - s[i]))) v[2] = aa - s[i];
			else v[2] = bb - s[i];
		}
		v[1] = s[i] - v[0];
		v[3] = s[n] - s[i] - v[2];
		sort(v.begin(), v.end());
		ans = min(ans, v[3] - v[0]);
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3328
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int a;
  std::string s;
  cin>>a>>s;
  if(a>=3200){
    cout<<s<<endl;
  }else{
    cout<<"red"<<endl;
  }



  return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<stack>
#include<queue>
using namespace std;

int main(){
	int n;
	cin >> n;
	if (n / 100 == n % 10)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
x,n = (map(int,input().split()))
if n == 0:
    p = input()
    print(x)
else:
    p = sorted(list(map(int,input().split())))
    zn,zp = x,x
    zn_point,zp_point = bisect_left(p,x),bisect_left(p,x)
    while zn_point>=0 and zn==p[zn_point]:
        zn-=1
        zn_point -=1 
    while zp_point<len(p) and zp==p[zp_point]:
        zp+=1
        zp_point +=1 
    if abs(zn-x)<=abs(zp-x):
        print(zn)
    else:
        print(zp)


Measured memory_bytes: 9020
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int	    int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,ans=0,w[101],v[101],m;
int is[3001][3001];
double dp[3001][3001];
double a[3001];
double f(int pos, int head){
	if(pos==n){
		if(head>n-head){
			return 1.0;
		}
		else return 0.0l;
	}
	if(is[pos][head]!=-1)
		return dp[pos][head];
	is[pos][head] = 1;
	return dp[pos][head] = (1.0l*a[pos]*f(pos+1,head+1)) + (1.0l*(1.0l-a[pos])*f(pos+1,head));
}
void solve(){
	memset(is,-1,sizeof is);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cout<<fixed<<setprecision(10)<<f(0,0)<<endl;
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
    	solve();
    }
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	while(n--) {
		int a, b, c;
		cin >> a >> b >> c;
		a = a * a;
		b = b * b;
		c = c * c;
		cout << ((a == b + c || b == a + c || c == a + b) ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;


int main(){
  int a[3];
  rep(i,3)cin>>a[i];
  sort(a,a+3);
  if(a[0]==5&&a[1]==5&&a[2]==7)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
a = int(input())
als = [0]*(100000)
for i in range(0,10**6+2):
    als[a] = 1
    if a%2 == 0:
        a = a//2
    else:
        a = 3*a+1
    if als[a] == 1:
        print(i+2)
        exit()

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

int main()
{
  int N, M;
  cin >> N >> M;
  long long int MOD = 1000000007;
  vector<int> oks(N + 1, true);
  for (int i = 0; i < M; i++)
  {
    int a;
    cin >> a;
    oks[a] = false;
  }

  vector<long long int> dp(N + 1);
  dp[0] = 1;
  for (int now = 0; now < N; now++)
  {
    for (int next = now + 1; next <= min(now + 2, N); next++)
    {
      if (oks[next])
      {
        dp[next] += dp[now];
        dp[next] %= MOD;
      }
      else
        dp[next] = 0;
    }
  }
  cout << dp[N] << endl;
}


Measured memory_bytes: 1408
N = int(input())
XY = [list(map(int,input().split())) for i in range(N)]
L = [i for i in range(N)]

import itertools
ans = 0
def kaijou(n):
    if n==1:
        return 1
    else:
        return n*kaijou(n-1)


for v in itertools.permutations(L, N):
    for i in range(N-1):
        ans += ((XY[v[i]][0]-XY[v[i+1]][0])**2 + (XY[v[i]][1]-XY[v[i+1]][1])**2)**0.5
ans /= 1.0*kaijou(N)
print(ans)

Measured memory_bytes: 41324
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include <cstdlib>

using namespace std;
int main(){
  int n, d, x;
  int a[110] = {0};

  cin >> n;
  cin >> d >> x;
  for(int i=0; i < n; i++) cin >> a[i];

  int c = 0;
  for(int i=0; i < n; i++){
    int j=0;
    while(j*a[i]+1 <= d){
      j++;
      c++;
    }
  }
  cout << x + c << endl;
  return 0;
}


Measured memory_bytes: 256
# import bisect

N, M = [int(v) for v in input().split()]
A = [int(input()) for _ in range(M)]

# for i in range(N - 1):
#     idx = bisect.bisect_left(A, i)
#     if idx < N and A[idx + 1] == i:

p = [0] * (N + 1)
p[0] = 1
for i in A:
    p[i] = -1

for i in range(N):
    if p[i] < 0: continue
    if p[i + 1] >= 0:
        p[i + 1] += p[i]
    if i < N - 1 and p[i + 2] >= 0:
        p[i + 2] += p[i]
    # print(p)

print(p[-1] % 1000000007)


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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define inf 1000000100

int main()
{
    ll x, y;
    cin >> x >> y;
    if(abs(x-y) > 1)
    {
        cout << "Alice" << endl;
    }
    else 
    {
        cout << "Brown" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= n; i++)
#define all(v) v.begin(), v.end()

int main(){
    int n;
    cin >> n;
    vector<long long> fn(n, 0);
    rep(i, 100){
        rep(j, 100){
            rep(k, 100){
                int temp = pow((i + j), 2) + pow((j + k), 2) + pow((k + i), 2);
                if (temp %2 == 0 and temp/2 <= n)fn[temp/2 - 1]++;
            }
        }
    }
    rep(i, n){
        cout << fn[i - 1] << endl;
    }
}

Measured memory_bytes: 3576
A,B,C,D = map(int,input().split())

a = list(range(A,B+1))
b = list(range(C,D+1))
#print(set(a) &set(b))

x = set(a) &set(b)
if len(x) == 0 :
  print(0)
else :
  print(max(x)-min(x))



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

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

    int n, w; cin>>n>>w;
    vector<int> wt(n), val(n);
    for(int i = 0; i<n; i++) cin>>wt[i]>>val[i];

    long long t[n+1][w+1];
    memset(t, -1, sizeof(t));

    for(int i = 0; i<=n; i++) t[i][0] = 0;
    for(int j = 0; j<=w; j++) t[0][j] = 0;

    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=w; j++){
            if(wt[i-1]<=j) t[i][j] = max(val[i-1] + t[i-1][j-wt[i-1]], t[i-1][j]);
            else t[i][j] = t[i-1][j];
        }
    }
    cout<<t[n][w]<<"\n";
    return 0;
}

Measured memory_bytes: 82552
#include <math.h>
#include <iostream>
#include<string>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#include <stdlib.h>
using namespace std;

int main()
{
int A,B,C,X,Y;
int ans=1000000000;
cin >> A >> B >> C >> X >> Y;
for(int i=0;i<2*max(X,Y)+1;i++)
{
int a=X-i/2;int b=Y-i/2;
if(i%2==1){a++;b++;}
if(a<0)a=0;if(b<0)b=0;
ans=min(ans,i*C+a*A+b*B);
}
cout << ans;
}


Measured memory_bytes: 256
// -D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define pi 3.1415926535
#define print(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl
#define fastio ios_base::sync_with_stdio(false);
#define rep(a,b,in) for(int i=a;i<b;i+=in)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define flush cin.tie(NULL);
using ll = long long int;
#define mod 1000000007
#define S Second
#define F first
#define mp make_pair
#define pb push_back
#define set0(a) memset(a,0,sizeof(a))
using namespace std;

int32_t main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<(min(n*a,b))<<endl;	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(Math.max(a*b,c*d ));
	}
}


Measured memory_bytes: 9804
n,k = gets.split.map(&:to_i)

s = gets.chomp.each_char.map{|c|c=="L"}
#Lがtrue,Rがfalse

happy = 0
tgl = 0
prev = s[0]
s[1..-1].each{|x|
  if prev==x
    happy += 1
  else
    tgl += 1
  end
  prev = x
}

p [happy+[tgl,k].min*2, n-1].min

Measured memory_bytes: 3068
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,x,n) for(int i=x;i<n;i++)
#define breps(i,x,n) for(int i=x;i>=n;i--)
#define exrep(x,vec) for(auto&& x : vec);
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

/**
* ------------- ここからコード -------------
*/

int main(void) {

	ll X, K, D;
	cin >> X >> K >> D;
	X = abs(X);

	ll ans;
	if (K > X / D) {
		ll tmp = X / D;
		X -= tmp * D;
		K -= tmp;
		ans = (K % 2 == 0 ? X : abs(X - D));
	}
	else {
		ans = X - K * D;
	}

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


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main(){
  vi a(3); rep(i, 3) cin >> a[i];
  if(a[0] * a[1] * a[2] % 2 == 0) cout << 0 << endl;
  else{
    sort(all(a));
    cout << a[0] * a[1] << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
    n = 0; int f = 1; register int ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
    n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind() {double x; scanf("%lf", &x); return x;}

///*....Bitmask....*///
int set_1(int n, int pos) {return n = (n | (1 << pos));}
int reset_0(int n, int pos) {return n = n & ~(1 << pos);}
bool check_bit(int n, int pos) {return n = n & (1 << pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;

std::map<char, int> m;
int main()
{
    int t = 1, te = 0;
    //Int(t);
    while (t--) {
        int n;
        Int(n);

        string s;
        cin >> s;

        m['R'] = 1, m['G'] = 2, m['B'] = 3;
        ll res=0ll;
        for (int i = 1; i < sz(s) - 1; ++i) {
            std::vector<int> cnt(6, 0);
            for (int j = 0; j < i; ++j) {
                cnt[m[s[j]]]++;
            }

            for (int k = i + 1; k < sz(s); ++k) {
                if (s[i] != s[k]) {
                    for (int l = 1; l <= 3; ++l) {
                        if (l != m[s[i]] and l != m[s[k]]) {
                            res+=(ll)cnt[l];

                            int in = i - (k-i);
 // error(res);
                            if(in>=0){
                                if(m[s[in]]==l)res-=1ll;
                            }

                            break;
                        }
                    }
                }
            }
        }
        printf("%lld\n", res);

        //printf("Case %d: ",++te);
    }
    return 0;
}



Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    string s;
    cin>>s;
    vector <int> ans;
    int cntR=0;//RLsetのR側の最終値
    int cntL=0;
    int last_data=1;//直前がR=0,L=1
    int RL=0;//RL部分のRの位置座標
    int flg=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R'){
            if(last_data==1){
                if(!ans.empty()){
                    ans[RL]=cntR;
                    ans[RL+1]=cntL;
                }
                cntR=1;
                cntL=0;
                flg=0;
            }
            else{
                //交換
                cntR=cntR+cntL;
                cntL=cntR-cntL;
                cntR=cntR-cntL;
                //R側が増える
                cntR++;
                //一個前のところに0を入れる
                ans.push_back(0);
            }
            last_data=0;
        }
        else{
            if(last_data==0){
                cntL++;
                RL=i-1;
                ans.push_back(0);
                ans.push_back(0);
            }
            else{
                if(flg==1){
                    cntL++;
                    flg=0;
                }else{
                    cntR++;
                    flg=1;
                }
                ans.push_back(0);
            }
            last_data=1;
        }
    }
    ans[RL]=cntR;
    ans[RL+1]=cntL;
    for(int i=0;i<s.size();i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void) {

	int D, T, S;
	cin >> D >> T >> S;

	if (D <= T*S) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}

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

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

const int INF = 2e9;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
   int n, m; cin >> n >> m;
   vector<int> c(m,0);
   vector<int> a(m);
   for(int i = 0; i < m; i++){
       int bt; cin >> a[i] >> bt;
       for(int j = 0; j < bt; j++){
           int ct; cin >> ct;
           ct--;
           c[i] += (1 << ct);
       }
   }

   int maxP = (1 << n);
   vector<int> dp(maxP,INF);
   dp[0] = 0;

    for(int j = 0; j < m; j++){
        for(int k = 0; k < maxP; k++){
            int cur = k|c[j];
            dp[cur] = min(dp[cur], dp[k]+a[j]);
       }
   }

   if(dp[maxP-1] == INF) cout << -1 << endl;
   else cout << dp[maxP-1] << endl;

   return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> sc(M);
    REP(i, M) {
        cin >> sc[i].first >> sc[i].second;
    }
    for(int i = N == 1 ? 0 : pow(10, N - 1);i < pow(10, N);i++) {
        bool judge = true;
        REP(j, M) {
            if(N - sc[j].first < 0) {
                cout << -1 << endl;
                return 0;
            }
            int p = pow(10, N - sc[j].first);
            judge = judge && (i/p)%10 == sc[j].second;
        }
        if(judge) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 384
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	Al := make([]int, N)
	for i := range Al {
		fmt.Scan(&Al[i])
	}

	isEven := func(x int) int {
		if x%2 == 0 {
			return 0
		} else {
			return 1
		}
	}

	areAllEven := func(l []int) bool {
		evenCount := 0
		for _, v := range l {
			evenCount += isEven(v)
		}
		if evenCount == 0 {
			return true
		} else {
			return false
		}
	}

	divide2 := func(l []int) []int {
		var nl []int
		for _, v := range l {
			nl = append(nl, v/2)
		}
		return nl
	}

	divedeNum := 0
	l := Al
	for {
		if areAllEven(l) == true {
			l = divide2(l)
			divedeNum += 1
		} else {
			break
		}
	}

	fmt.Println(divedeNum)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for (int i=0;i<3;i++){
if(s.at(i)=='1'){s.at(i)='9';
                }
    else if(s.at(i)=='9'){s.at(i)='1';
                        }
  }
  cout<<s<<endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    vector<string> C(8);
    for (int i = 0; i < 8; i++){
      cin >> C[i];
    }
    if (!cin){
      break;
    }
    sort(C.begin(), C.end());
    set<vector<string>> st;
    while (1){
      vector<string> D = C;
      vector<string> tmp = D;
      for (int i = 0; i < 4; i++){
        for (int j = 0; j < 4; j++){
          for (int k = 0; k < 4; k++){
            tie(D[0], D[1], D[3], D[2]) = make_tuple(D[2], D[0], D[1], D[3]);
            tie(D[4], D[5], D[7], D[6]) = make_tuple(D[6], D[4], D[5], D[7]);
            tmp = min(tmp, D);
          }
          tie(D[0], D[1], D[5], D[4]) = make_tuple(D[4], D[0], D[1], D[5]);
          tie(D[2], D[3], D[7], D[6]) = make_tuple(D[6], D[2], D[3], D[7]);
        }
        tie(D[0], D[2], D[6], D[4]) = make_tuple(D[4], D[0], D[2], D[6]);
        tie(D[1], D[3], D[7], D[5]) = make_tuple(D[5], D[1], D[3], D[7]);
      }
      st.insert(tmp);
      if (!next_permutation(C.begin(), C.end())){
        break;
      }
    }
    cout << st.size() << endl;
  }
}


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

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

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

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

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


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

    cout << (n-1)*(m-1) << endl;
}


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

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

  int cnt[101010] = {0};
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    for (int j = max(0, a - 1); j <= a + 1; ++j) {
      cnt[j]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < 101010; ++i) {
    ans = max(ans, cnt[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 640