akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main() {
	string A, B, C;
	cin >> A >> B >> C;
	queue<char>Card_A, Card_B, Card_C;
	for (int i = 0; i < A.size(); i++) {
		Card_A.push(A.at(i));
	}
	for (int i = 0; i < B.size(); i++) {
		Card_B.push(B.at(i));
	}
	for (int i = 0; i < C.size(); i++) {
		Card_C.push(C.at(i));
	}
	char ch = 'a';
	while (!Card_A.empty() || !Card_B.empty() || !Card_C.empty()) {
		if (ch == 'a') {
			if (Card_A.empty()) {
				cout << 'A' << endl;
				return 0;
			}
			else {
				ch = Card_A.front();
				Card_A.pop();
			}
		}
		else if (ch == 'b') {
			if (Card_B.empty()) {
				cout << 'B' << endl;
				return 0;
			}
			else {
				ch = Card_B.front();
				Card_B.pop();
			}
		}
		else {
			if (Card_C.empty()) {
				cout << 'C' << endl;
				return 0;
			}
			else {
				ch = Card_C.front();
				Card_C.pop();
			}
		}
	}
}


Measured memory_bytes: 256
import java.util.*;

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

        String key = "keyence";
        
        // if(s.subSequence(0, 7).equals(key)){
        //     System.out.println("YES");
        //     return;
        // }
        // if(s.subSequence(s.length()-7, s.length()).equals(key)){
        //     System.out.println("YES");
        //     return;
        // }

        int lnum = 0;
        int rnum = 0;
        for(int i=0; i<7; i++){
            if(s.charAt(i) == key.charAt(i)){
                lnum++;
            }else{
                break;
            }
        }
        for(int i=0; i<7; i++){
            if(s.charAt(s.length()-1-i) == key.charAt(key.length()-1-i)){
                rnum++;
            }else{
                break;
            }
        }

        if(lnum + rnum >= 7){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21460
#include <stdio.h>

int main(void){
	int n, k;
	unsigned count = 0;

	scanf("%d%d", &n, &k);

	count = k;
	for(int i=1; i < n; i++) {
		count *= k-1;
		if(count >= 1<<31) {
			count /= k-1;
			break;
		}
	}
	printf("%u", count);

	return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int main() {
    char w[101];
    scanf("%s", w);

    for (char c='a'; c<='z'; ++c)
        if (count(w, w+strlen(w), c) & 1) {
            printf("No\n");
            return 0;
        }

    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

double dp[3001][3001];

double compute(double *p, int i, int x){
    if(x == 0)  return 1;
    if(i == 0)  return 0;

    if(dp[i][x] > -0.9) return dp[i][x];

    return dp[i][x] = p[i]*compute(p, i-1, x-1) + (1-p[i])*compute(p, i-1, x);
}

void solve(){
    int n;  cin>>n;
    mk(p, n+1, double);  forI(i, 1, n) cin>>p[i];
    memset(dp, -1, sizeof dp);
    cout<<ps(compute(p, n, (n+1)/2), 10);
}

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

Measured memory_bytes: 74356
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(a >= k) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

typedef long long ll;

int main()
{
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    
    
    long long sum=0;
    
    if(k<=a)
    {
        sum+=k;
    }
    else if(k<=(a+b))
    {
        sum+=a;
    }
    else 
    {
        sum+=a;
        k-=(a+b);
        sum-=k;
    }
    
    cout<<sum;

    return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
using namespace std;

int m,n,map[90][90],ans;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

void dfs(int x,int y,int z) {
	map[x][y]=0;
	for(int i=0;i<4;i++) {
		int nx=x+dx[i],ny=y+dy[i];
		if(0<=nx&&nx<m&&0<=ny&&ny<n&&map[nx][ny]) dfs(nx,ny,z+1);
	}
	map[x][y]=1;
	ans=max(ans,z);
}

int main() {
	while(1) {
		ans=0;
		scanf("%d",&m);
		scanf("%d",&n);
		if(m==0&&n==0) break;
		for(int j=0;j<n;j++) {
			for(int i=0;i<m;i++) {
				scanf("%d",&map[i][j]);
			}
		}
		for(int j=0;j<n;j++) {
			for(int i=0;i<m;i++) {
				if(map[i][j]) dfs(i,j,1);
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1060
def calc(X, Y):
    if Y % 2 == 1:
        return 'No'
    elif Y >= 2 * X and Y <= 4 * X:
        return 'Yes'
    else:
        return 'No'

    

(X, Y) = tuple([int(s) for s in input().split()])
print(calc(X, Y))

Measured memory_bytes: 61808
input_line = input().split()

if int(input_line[0]) + int(input_line[1]) + int(input_line[2]) != 17:
    print("NO")
    pass
elif input_line[0] == input_line[1] == "5":
    print("YES")
    pass
elif input_line[1] == input_line[2] == "5":
    print("YES")
    pass
elif input_line[0] == input_line[2] == "5":
    print("YES")
    
else:
    print("NO")



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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    ll a, b, c; cin >> a >> b >> c;
    if (c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = [x-i-1 for i,x in enumerate(a)]

a = sorted(a)

med1 = a[len(a)//2]
med2 = a[len(a)//2 - 1]



sum1 = sum([abs(x - med1) for x in a])
sum2 = sum([abs(x - med2) for x in a])
print(min(sum1, sum2))


Measured memory_bytes: 25200
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int t[101];

int main()
{
  int n, m;
  int sumInit;

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    sumInit += t[i];
  }

  cin >> m;
  int ans[m];

  for (int i = 1; i <= m; i++) {
    int x, p, sum;
    cin >> x >> p;
    sum = sumInit + p - t[x];
    ans[i] = sum;
  }

  for (int i = 1; i <= m; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long H, W, ans = long.MaxValue, sa = 0, sb = 0, sc = 0;
            string[] s = Console.ReadLine().Split(' ');
            H = int.Parse(s[0]);
            W = int.Parse(s[1]);

            ans = Math.Min(ans, H);
            ans = Math.Min(ans, W);

            if (H % 3 == 0 || W % 3 == 0)
            {
                ans = 0;
            }
            else
            {
                for(int i = 1; i < H; i++)
                {
                    sa = i * W;
                    if(W % 2 == 0)
                    {
                        sb = (H - i) * (W / 2);
                        sc = sb;
                    }
                    else
                    {
                        sb = (H - i) * ((W + 1) / 2);
                        sc = (H - i) * ((W - 1) / 2);
                    }
                    long a = Math.Max(sa, Math.Max(sb, sc)) - Math.Min(sa, Math.Min(sb, sc));
                    ans = Math.Min(ans, a);
                }


                for (uint i = 1; i < W; i++)
                {
                    sa = i * H;
                    if (H % 2 == 0)
                    {
                        sb = (W - i) * (H / 2);
                        sc = sb;
                    }
                    else
                    {
                        sb = (W - i) * ((H + 1) / 2);
                        sc = (W - i) * ((H - 1) / 2);
                    }
                    long a = Math.Max(sa, Math.Max(sb, sc)) - Math.Min(sa, Math.Min(sb, sc));
                    ans = Math.Min(ans, a);
                }
            }
            
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
N,x=map(int,input().split())
t=list(map(int,input().split()))
if x > sum(t):
    print(N-1)
else:
    cnt=0
    total=0
    t=sorted(t)
    for T in t:
        total+=T
        if total <= x:
            cnt+=1
        else:
            break
    print(cnt)

Measured memory_bytes: 3060
s = int(input())

mod = 10**9 + 7
dp = [0]*(s+1)
dp[0] = 1
for i in range(1,s+1):
    for j in range((i-3)+1):
        dp[i] +=dp[j]
        dp[i] %=mod
        
print(dp[s])

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend()))

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

    map <char,int> l,r;
    
    vector<int> dp(n+1);

    for (int i=0;i<n;i++) {
        r[s[i]]++;
    }
    
    dp[0]=0;
    for (int i=0;i<n;i++) {
        r[s[i]]--;
        if (r[s[i]]>0 && l[s[i]]>0) {
            dp[i+1]=dp[i];
        }
        else if (r[s[i]]>0 && l[s[i]]==0) {
            dp[i+1]=dp[i]+1;
        }
        else if (r[s[i]]==0 && l[s[i]]==0) {
            dp[i+1]=dp[i];
        }
        else if (r[s[i]]==0 && l[s[i]]>0) {
            dp[i+1]=dp[i]-1;
        }
        l[s[i]]++;
    }
    int mx=-1;
    rep(i,n) {
        mx=max(mx,dp[i]);
    }
    cout<<mx<<endl;

}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<ll,ll> Q;

const int MAX_N = 3 * 100000;

class SegmentTree{
public:
    SegmentTree(){}
    SegmentTree(int n)
    {init(n);}
    void init(int n){
        size = 1;
        while(size < n){
            size *= 2;
        }

        memset(data, 0, sizeof(data));
    }
    void add(int index, int v){
        index += size;
        data[index][0] = v;
        data[index][1] = index - size;
        
        while(index > 0){
            int parent = (index - 1) / 2,
                cl = parent * 2 + 1, cr = parent * 2 + 2;

            if(data[cl][0] > data[cr][0]){
                data[parent][0] = data[cl][0];
                data[parent][1] = data[cl][1];
            }else{
                data[parent][0] = data[cr][0];
                data[parent][1] = data[cr][1];
            }

            index = parent;
        }
    }
    Q root(){
        return mp(data[0][0], data[0][1]);
    }
    ll query(int a, int b){
        return _query(a, b, 0, 0, size);
    }
private:
    ll _query(int a, int b, int v, int l, int r){
        if(b <= l || r <= a){return 0;}
        if(a <= l && r <= b){return data[v][0];}

        return std::max(_query(a, b, 2*v+1, l, (l+r)/2), _query(a, b, 2*v+2, (l+r)/2, r));
    }

    ll data[MAX_N*4][2];
    int size;
};

int N;
std::vector<P> B;
SegmentTree st;

bool compareP(const P& lp, const P& rp){
    if(lp.second == rp.second){
        return lp.first < rp.first;
    }
    return lp.second > rp.second;
}


bool can(int n){
    st.init(n);

    ll foo = 0ll;
    REP(i, n-1){
        foo += B[i].first;
        st.add(i, B[i].first);
    }

    FOR(i, n-1, N){
        if(i == n-1){
            foo += B[i].first;
            st.add(i, B[i].first);
        }else{
            Q root = st.root();
            
            if(root.first > B[i].first){
                foo = foo - root.first + B[i].first;
                st.add(root.second, B[i].first);
            }
        }

        if(foo <= (ll)n*B[i].second){return true;}
    }
    return false;
}

int main(){
    std::cin >> N;

    B.resize(N);
    REP(i, N){
        std::cin >> B[i].first >> B[i].second;
    }

    std::sort(B.begin(), B.end(), compareP);

    int lb = 0, ub = N+1;
    while(ub-lb > 1){
        int mid = (ub+lb) / 2;
        if(can(mid)){
            lb = mid;
        }else{
            ub = mid;
        }

        //printf("[%d, %d)\n", lb, ub);
    }

    std::cout << lb << std::endl;
}

Measured memory_bytes: 22108
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int a = 5000, b = 5000;
                for (int i = 0; i < 3; i++) {
                        a = Math.min(a, sc.nextInt());
                }
                for (int i = 0; i < 2; i++) {
                        b = Math.min(b, sc.nextInt());
                }
                System.out.println(a + b - 50);


        }
}

Measured memory_bytes: 26080
#include<stdio.h>
#include<stdlib.h>
#define N 100000
void quicksort(char *,int *,int,int);
int partition(char *,int *,int,int);
int main(){
  int cnt=0,n,i,j,num[N],cnum[N],flag=0;
  char cstr[N],str[N],*check;
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf(" %c %d",&str[i],&num[i]);
    cnum[i]=num[i];
    cstr[i]=str[i];
  }
  quicksort(str,num,0,n-1);
  for(j=0;j<n;j++){
    cnt=0;
    for(;j<n;j++){
      cnt++;
      if(j!=n-1){
      if(num[j]!=num[j+1])
	break;
      }
    }
    for(i=0;i<n;i++){
      if(num[j]==cnum[i]&&str[j-(cnt-1)]!=cstr[i]){
	flag=1;
	//	printf("%d %d a%c b%c\n",num[j],cnum[i],str[j-(cnt-1)],cstr[i]);
	break;
      }
      else if(num[j]==cnum[i])
       cnt--;
      if(cnt==0)
	break;
    }
    if(flag==1)
      break;
      
  }
  if(flag==1)
    printf("Not stable\n");

  else
    printf("Stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",str[i],num[i]);
  }
  
  return 0;
}
int partition(char str[],int A[],int p,int r){
int x,i,j,hoge;
 char foo; 
x=A[r];
i=p-1;
for(j=p;j<=r-1;j++){
if(A[j]<=x){
i=i+1;
hoge=A[i];
A[i]=A[j];
A[j]=hoge;
 foo=str[i];
 str[i]=str[j];
 str[j]=foo;
}
  
}
hoge=A[i+1];
A[i+1]=A[r];
A[r]=hoge;
  foo=str[i+1];
 str[i+1]=str[r];
 str[r]=foo;
return i+1;
}
void quicksort(char str[],int A[],int p,int r ){
  int q;
  if(p<r){
    q=partition(str,A,p,r);
    quicksort(str,A,p,q-1);
    quicksort(str,A,q+1,r);
  }

}



Measured memory_bytes: 2776
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;

int main() {
int n,k;
cin>>n>>k;
if(k==1)
{
	cout<<"0";
	return 0;
}
int mn=1;
n-=k;
cout<<n<<endl;

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int a = 0;
        if(N > 1 && M > 1){
            for(int i = 1; i < N; i++){
                for(int j = i; j < N; j++){
                    a++;
                }
            }
            for(int i = 1; i < M; i++){
                for(int j = i; j < M; j++){
                    a++;
                }
            }
        }else if(N > 1 && M <= 1){
            for(int i = 1; i < N; i++){
                for(int j = i; j < N; j++){
                    a++;
                }
            }
        }else if(M > 1 && N <= 1){
            for(int i = 1; i < M; i++){
                for(int j = i; j < M; j++){
                    a++;
                }
            }
        }else{
            a = 0;
        }
        System.out.println(a);
    }
}

Measured memory_bytes: 21716
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

static int
calc(int L, int R)
{
  if (L <= R / 2019 * 2019)
  {
    return 0;
  }
  L %= 2019;
  R %= 2019;
  int minval = 2019;
  for (int i = L; i < R; i++)
  {
    for (int j = i + 1; j <= R; j++)
    {
      int newval = (i * j) % 2019;
      if (newval < minval)
      {
        minval = newval;
      }
    }
  }
  return minval;
}

int
main()
{
  int L, R;
  cin >> L >> R;
  cout << calc(L, R) << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace aoj9d
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(Console.ReadLine());
            
            for(int i = 0; i < n; i++)
            {
                string line = Console.ReadLine();
                string[] command = line.Split(' ');
                switch (command[0])
                {
                    case "print":
                        print(str,line);
                        break;

                    case "replace":
                        str = replace(str, line);
                        break;

                    case "reverse":
                        str = reverse(str, line);
                        break;
                }
            }
        }

        private static string reverse(string str, string line)
        {
            string[] command = line.Split(' ');
            int a = int.Parse(command[1]);
            int b = int.Parse(command[2]);
            char[] ch = str.ToCharArray();  //ch???a???????????????b?????????????????¢????????????
            char[] dummy = str.ToCharArray();


            for (int i = 0; i <= (b - a);i++)
            {
                ch[a + i] = dummy[ b - i];
            }

            string returnstr = new string(ch);
            return returnstr;
        }

        private static string replace(string str, string line)
        {
            string[] command = line.Split(' ');
            /*????????????????±????????????????command[3]*/
            int a = int.Parse(command[1]);

            string returnstr = str.Substring(0,a);       //?????????????????´??????????????§????????????
            returnstr += command[3];                    //?????????????????????????????£???
            str = str.Substring(a + command[3].Length);
            returnstr += str;
            return returnstr;
        }

        private static void print(string str, string line)
        {
            string[] command = line.Split(' ');
            int a = int.Parse(command[1]);
            int b = int.Parse(command[2]);
            string printstr = str.Substring(a,b-a+1);
            Console.WriteLine(printstr);
        }
    }
}

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  int a[n+1];
  for(int i=1;i<=n;++i) cin>>a[i];
  int x=1,cnt=0;
  bool flag = false;
   for(int i=0;i<n;++i){
     x = a[x];
     cnt++;
     if(x==2){
       flag=true;
       break;
     }
   }
   if(flag) cout<<cnt<<endl;
   else cout<<-1<<endl;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    vector<pair<int, int>> sums(N);
    int prev_w = 0;
    int prev_e = 0;
    for(int i = 0; i < N; i++) {
        if(S.at(i) == 'W') {
            prev_w++;
        } else {
            prev_e++;
        }
        sums.at(i).first = prev_w;
        sums.at(i).second = prev_e;
    }

    int ans = N;
    int e_total = sums.at(N - 1).second;
    for(int i = 0; i < N; i++) {
        int c = 0;
        if(i > 0) {
            c += sums.at(i - 1).first;
        }
        if(i < N - 1) {
            c += (e_total - sums.at(i).second);
        }
        ans = min(c, ans);
    }
    cout << ans << endl;
    return 0;
}

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

struct city{
  int pref;
  int year;
  int id_head;
  int id_tail;
  int num;
};

int main(){
  int n,m,pref,year,buf;
  array<city,100000> c; 
  
  cin >> n >> m ;
  for(int i=0; i<m; i++){
    cin >> c[i].pref >> c[i].year ;
    c[i].num = i;
  }
  
  sort(c.begin(),c.begin()+m,
      [](const city& x, const city& y) { return x.pref == y.pref ? x.year < y.year : x.pref < y.pref;});
  
  for(int i=0,pref=0,year=1; i<m; i++){
    c[i].id_head = c[i].pref;
    if(pref == c[i].pref) year++;
    else                { pref=c[i].pref; year=1;}
    c[i].id_tail = year; 
  }
  
  sort(c.begin(),c.begin()+m,
      [](const city& x, const city& y) { return x.num < y.num;});
  
  for(int i=0; i<m; i++){
    printf("%06d%06d\n",c[i].id_head,c[i].id_tail);
  }
  
  return 0;
}

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

int main()
{
	int n;
	string s;
	cin>>n>>s;
	long long r=0,g=0,b=0;
	for (int i = 0; i < n; ++i)
	{
		if(s[i]=='R')
			r++;
		if(s[i]=='B')
			b++;
		if(s[i]=='G')
			g++;
	}
	long long ans = r*g*b,sub=0;

	for (int i = 0; i < n; ++i)
	{
		for(int j = i+1; j < n ;j++)
		{
			int k = 2*j-i;
			if(k<n)
			{
				if(s[i]!= s[j] && s[j]!=s[k] && s[i]!=s[k])
					sub++;
			}
		}
	}

	cout<<ans-sub<<endl;

	
	return 0;
}

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

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ll long long
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
//#define end "\n"
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=998244353;
const ll inf=1e18;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;


ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}

ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n>>=1;
        a=(a*a)%MOD;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}

const long sz=1e5+10;

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}


int main()
{
    fast;
    ll t;
   // cin>>t;
    t=1;
    while(t--){
        ll n;
        cin>>n;
        cout<<3*n*n;
    }
    return 0;
}


Measured memory_bytes: 256
import math

def ncr(n,r):
    if r> n: return 0;
    return math.factorial(n)//(math.factorial(r)*math.factorial(n-r))

def solve(n,m):
    print(ncr(n,2)+ ncr(m,2))

N,M = map(int,input().split())
solve(N,M)


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

int atama(int a){
  int b,c=a;
  while(c>0){
    b=c%10;
    c=c/10;
  }
  return b;
}

void IntToString(char *str, int number)
{
  sprintf(str, "%d", number);
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  int K,flg=0;
  char Schar[100];
  cin>>S>>K;

  //IntToString(Schar, S);

  if(K==1){  //まず自明な場合の処理
    cout<<S[0];
  }else{
    for(int i=0;i<K;i++){ //先頭からK番目の数字を調べる
      if(i>=100){
        break;
      }
      if(S[i]!='1'){
        flg=1;
        cout<<S[i];
        break;
      }

    }
    if(flg==0){
      cout<<"1";
    }
  }


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
	int a[25],n,sum=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 1; i < n - 1; i++)
	{
		if ((a[i] > a[i - 1] && a[i] < a[i + 1]) || (a[i] < a[i - 1] && a[i] > a[i + 1])) { sum++; }
	}
	cout << sum << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define N_MAX 100005

bool used[N_MAX];
vector<int> G[N_MAX];
int dep[N_MAX];
int deg[N_MAX];

void dfs(int v = 0, int p = -1, int d = 0){
	used[v] = true;
  	dep[v] = d;
  	for(int i = 0; i < G[v].size(); i++){
    	int to = G[v][i];
      	if(to != p){
        	if(!used[to]) dfs(to, v, d+1);
          	else if(dep[to] < dep[v]){
            	cout << v+1 << ' ' << to + 1 << endl;
              	deg[v]++;
            }
        }
    }
  	if(p!=-1){
    	if(deg[v]%2 != 0){
        	cout << v+1 << ' ' << p+1 << endl;
          	deg[v]++;
        } else {
        	cout << p+1 << ' ' << v+1 << endl;
        	deg[p]++;
        }
    }
}

int main(){
	int N, M;
  	cin >> N >> M;
  	for(int i = 0; i < M; i++){
    	int a, b;
      	cin >> a >> b;
      	a--; b--;
      	G[a].push_back(b);
      	G[b].push_back(a);
    }
  	if(M%2 != 0){
    	cout << -1 << endl;
      	return 0;
    }
	dfs();
  	return 0;
}

Measured memory_bytes: 17152
#include <stdio.h>

int main()
{
  int x,y,tmp;
  while(1)
  {
    scanf("%d%d",&x,&y);
    if(y==0&&x==0)break;
    if(x>y)
    {
      tmp=x;
      x=y;
      y=tmp;
    }
    printf("%d %d\n",x,y);
  }
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

#define int ll

string s;
int n;

signed main(){
    cin>>s>>n;
    rep(i,0,s.size()){
        if(i!=s.size()-1){
            if(s[i]=='a')continue;
            int x=26-(s[i]-'a');
            if(x<=n){
                n-=x;
                s[i]='a';
            }
        }else{
            int v=s[i]-'a';
            v+=n;
            v%=26;
            //cout<<n<<endl;
            //cout<<s[i]<<endl;
            s[i]=v+'a';
        }
    }
    cout<<s<<endl;
    
    
    
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 123;
const ll LINF = (ll) 1e18 + 123;
const ld EPS = (ld) 1e-8;
//const ll MOD = (ll) 1e9 + 7;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; i++)
#define per(i, f, t) for (auto i = f; i >= t; i--)

ll power(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

inline void add(ll &x, ll y, ll mod) {
    x += y;
    if (x >= mod) x -= mod;
    if (x < 0) x += mod;
}

inline ll sum(ll x, ll y, ll mod) {
    add(x, y, mod);
    return x;
}

template<typename A, typename B> inline bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> inline bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

template<typename T> inline void read(T first, T last) {
    while (first != last) {
        cin >> *(first++);
    }
}

template<typename T> inline void print(T first, T last) {
    while (first != last) {
        cout << *(first++) << " ";
    }
    cout << "\n";
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(15);
    run();
    return 0;
}

// == SOLUTION == //

void run() {
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    pair<int, int> ans = {0, 0};
    for (int i = 0; 100 * a * i <= f; i++) {
        for (int j = 0; 100 * b * j + 100 * a * i <= f; j++) {
            int have = 100 * b * j + 100 * a * i;
            int rest = min(f - have, e * have / 100);
            assert(rest >= 0);
            for (int x = 0; x * c <= rest; x++) {
                int y = (rest - x * c) / d;
                int sugar = x * c + y * d;
                if (ans == mp(0, 0) || (sugar * (ans.first + ans.second) >= ans.first * (sugar + have))) {
                    ans = {sugar, have};
                }
            }
        }
    }
    cout << ans.first + ans.second << " " << ans.first << "\n";
}


Measured memory_bytes: 256
while(1):
    l = [0 for  i in range(10)]
    m = [0 for  i in range(10)]
    try:
        l[0],l[1],l[2],l[3],l[4],l[5],l[6],l[7],l[8],l[9],v1,v2 = [int(i) for i in input().split(",")] 
        for i in range(10):
            if i != 0:
                m[i] = m[i-1] + l[i]
            else:
                m[i] = l[i]
        leng = m[9]
        p = leng*v1/(v1+v2)
        for i in range(10):
            if p < m[i]:
                print(i+1)
                break
            elif abs(p - m[i]) < 10**-10:
                print(i+1
                )
                break

    except EOFError:
        break



Measured memory_bytes: 5628
h, w = map(int, input().split())
ls_a = [[_ for _ in input()] for _ in range(h)]

memo = []

for i in range(h):
    if ls_a[i] != ["."] * w:
        memo.append(ls_a[i])

ls = [["" for _ in range(len(memo))] for _ in range(w)]

for i in range(w):
    for j in range(len(memo)):
        ls[i][j] = memo[j][i]

memo = []

for i in range(w):
    if ls[i] != ["."] * len(ls[i]):
        memo.append(ls[i])

ans = [["" for _ in range(len(memo))] for _ in range(len(memo[0]))]

for i in range(len(memo[0])):
    for j in range(len(memo)):
        ans[i][j] = memo[j][i]


for i in range(len(ans)):
    print("".join(ans[i]))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


struct Edge {
    int to, id;
    Edge(int to, int id) : to(to), id(id) {}

};

vector<Edge> g[55];

vector<int> es;
bool dfs(int v, int tv, int p=-1) {
    if (v == tv) {
        es = vector<int>();
        return true;
    }
    for(auto e: g[v]) {
        if (e.to == p) continue;

        if(dfs(e.to, tv, v)) {
            es.push_back(e.id);
            return true;
        }
    }
    return false;
}

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

    int n, m;
    cin >> n;
    rep(i, n-1){
        int a, b; 
        cin >> a >> b; --a; --b;
        g[a].push_back(Edge(b, i));
        g[b].push_back(Edge(a, i));
    }

    cin >> m;
    // i 番目の要求について，u[i] - v[i] 上のパスに含まれる id をビットで管理する 
    vector<ll> eset(m);
    rep(i, m) {
        int a, b; cin >> a >> b; --a; --b;
        dfs(a, b);
        for(int e:es) {
            eset[i] |= 1LL<<e;
        }
    }

    ll ans = 0;
    rep(bit, 1<<m) {
        ll mask = 0;
        rep(i, m) if (bit>>i&1) mask |= eset[i];
        int white = __builtin_popcountll(mask);
        ll now = 1LL<<(n-1-white);
        if (__builtin_popcount(bit)%2 == 0) ans += now;
        else ans -= now;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = 1000000007;
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int n, m;
ll res = 1;

int main(int argc, char *argv[]){
    cin >> n >> m;
    vec A(m);
    vector<ll> dp(n + 2);
    rep(i, m){
        cin >> A[i];
        dp[A[i]] = -1;
    }
    dp[0] = 1;
    rep(i, n){
        if(dp[i] == -1) continue;
        if(dp[i + 1] != -1){
            dp[i + 1] += dp[i];
            dp[i + 1] %= MOD;
        }
        if(dp[i + 2] != -1){
            dp[i + 2] += dp[i];
            dp[i + 2] %= MOD;
        }
    }
    cout << dp[n] << endl;
    // int a = 0;
    // int i = 0;
    // while(1){
    //     if(i == n - 1){
    //         res = res + 1 % MOD;
    //         cout << res << endl;
    //         return 0;
    //     }
    //     if(i + 1 != A[a] && i + 1 != A[a]){
    //         if(res)
    //             res = res * 2 % MOD;
    //         else
    //             res = 1;
    //         i++;
    //     }else if(i + 1 == A[a] && i + 2 != A[a + 1]){
    //         res++;
    //         a++;
    //         i += 2;
    //     }else if(i + 1 == A[a] && i + 2 == A[a + 1]){
    //         cout << 0 << endl;
    //         return 0;
    //     }
    // }
    // vector<ll> dp(n + 1, true);
    // vector<ll> dp2(n + 1, true);
    // rep(i, m) dp[A[i]] = false;
    // dp2[0] = 1;
    // rep(i, n){
    //     rfor(j, i + 1, min(n, i + 2) + 1){
    //         if(dp[j]){
    //             dp2[j] += dp2[i];
    //             dp2[j] %= MOD;
    //         }
    //     }
    // }
    // cout << dp2[n] << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll a,b,k;
	cin >> a >> b >> k;
	if(a+b<k) cout << 0 << " " << 0 << endl;
	else cout << max(0LL,a-k) << " " << b-max(0LL,k-a) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;


int BubbleSort(int*Array, const int Num) {
	bool loop = false;
	int SortNum = 0;

	do {
		loop = false;

		for (int i = 1; i < Num; i++) {
			if (*(Array + i - 1) > *(Array + i)) {
				int tmp = *(Array + i - 1);
				*(Array + i - 1) = *(Array + i);
				*(Array + i) = tmp;
				loop = true;
				SortNum++;
			}
		}
	} while (loop);

	return SortNum;
}

int main() {
	int N;
	int Array[200000];
	int SortNum;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> Array[i];
	}

	SortNum = BubbleSort(Array, N);

	cout << Array[0];
	for (int i = 1; i < N; i++)cout << " " << Array[i];
	cout << endl;
	cout << SortNum << endl;

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int deli_sum = 0;
  int deli_sq_sum = 0;
  for (int i=0; i<n;i++){
    int d;
    cin >> d;
    deli_sum += d;
    deli_sq_sum += d*d;
  }
  cout << (deli_sum*deli_sum-deli_sq_sum)/2 << endl;
}

Measured memory_bytes: 256
def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while visitct!=n:
    ct+=1
    for i in range(len(next)):
      distance[next[i]]=ct
      visited[next[i]]=1
      visitct+=1
      for j in range(len(connection[next[i]])):
        if visited[connection[next[i]][j]]==-1:
          next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
    
  return distance

n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

f=bfs(0);s=bfs(n-1)
ctf=0;cts=0
for i in range(n):
  if f[i]<=s[i]:
    ctf+=1
  else:
    cts+=1

if ctf>cts:
  print('Fennec')
else:
  print('Snuke')

Measured memory_bytes: 82388
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge {ll from;ll to;ll cost;};

ll V, E, d[1010];
edge es[2010];


bool find_negative_loop() {
    for (ll i = 0; i < V; i++) {
        for (ll j = 0; j < E; j++) {
            edge e = es[j];
            if (d[e.from]!=INF&&d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (e.to== V - 1) {
                    return true;
                }
            }
        }
    }
    return false;
}
void shortest_path(ll s){
  rep(i,V)d[i]=INF;
  d[s]=0;
  rep(j,V){
    bool update=false;
    rep(i,E){
      edge e=es[i];
      if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        update=true;
      }
    }
    if(!update)break;
    return;
  }
}
int main(){
  cin>>V>>E;
  rep(i,E){
    ll f,t,c;
    cin>>f>>t>>c;
    es[i].from=f-1;
    es[i].to=t-1;
    es[i].cost=-c;
  }
  shortest_path(0);
  if(find_negative_loop()){
    cout<<"inf"<<endl;
    return 0;
  }
  cout<<-d[V-1]<<endl;
  
}
  


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) for(int i=0; i<n; i++)

typedef long long int ll;

int main(){
  int n,m,a,b;
  scanf("%d %d",&n,&m);
  vector<pair<int,int>> edge(m);
  REP(i,m){
    scanf("%d %d",&a,&b);
    edge[i] = make_pair(a,b);
  }
  vector<int> perm(n-1);
  REP(i,n-1)perm[i]=i+2;
  int sum=0;
  int flag;
  do{
    if(count(edge.begin(),edge.end(),make_pair(1,perm[0]))==1){
      flag = 0;
      REP(i,n-2){
        if(count(edge.begin(),edge.end(),make_pair(perm[i],perm[i+1]))==1 || count(edge.begin(),edge.end(),make_pair(perm[i+1],perm[i]))==1) flag++;
      }
      if(flag==n-2) sum++;
    }
  }while(next_permutation(perm.begin(), perm.end()));

  printf("%d",sum);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;

int main() {
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int u=(h2-h1)*60+(60+m2-m1)%60;
    if (m1>m2) u-=60;
    cout << u-k << endl;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAX_N 7
#define MAX_M 11

struct P{
  int l, r, s;
};

int N, X, M;
P p[MAX_M];

bool check(int lion[]){
  for(int i = 0 ; i < M ; i++){
    int sum = 0;
    for(int j = p[i].l-1 ; j < p[i].r ; j++){
      sum += lion[j];
    }
    if(sum != p[i].s) return false;
  }
  return true;
}

void print(int lion[]){
  for(int i = 0 ; i < N ; i++){
    printf("%d%c",lion[i], i != N-1 ? ' ' : '\n');
  }
}

bool rec(int pos, int lion[]){
  if(pos == N){
    if(check(lion)){
      return true;
    }else{
      return false;
    }
  }

  for(int i = X ; i >= 0 ; i--){
    lion[pos] = i;
    if(rec(pos+1, lion)){
      return true;
    }
  }
  return false;
}

void solve(){
  int lion[MAX_N];
  memset(lion, 0, sizeof(lion));

  if(rec(0, lion)){
    print(lion);
  }else{
    printf("-1\n");
  }
}

int main(){
  scanf("%d%d%d" ,&N ,&X, &M);
  for(int i = 0 ; i < M ; i++){
    scanf("%d%d%d" ,&p[i].l , &p[i].r, &p[i].s);
  }
  solve();

  return 0;
}

Measured memory_bytes: 1032
var lines =[];

var readline = require("readline");
var rl = readline.createInterface({
  input:  process.stdin,
  output: process.stdout
});

rl.on('line',function(x){
  lines.push(x);
});

rl.on('close',function(){
  var tmp = lines.shift();
  var n = Number(tmp.split(" ")[0]);
  var m = Number(tmp.split(" ")[1]);
  var likeMenu =[] ;
  var result = 0;

  for(var i=0;i<m;i++){
    likeMenu[i]=0;
  }

  for(var i=0;i<n;i++){
    tmp = lines[i].split(" ");
    loop= Number(tmp.shift());

    for(var k=0; k<loop;k++){
      likeMenu[Number(tmp[k]-1)]++;
      }
    }

  for(var i=0;i<m;i++){
    if(likeMenu[i]===n){result++;}
  }

    console.log(result);
});


Measured memory_bytes: 21320
sa = gets.chomp
sb = gets.chomp
sc = gets.chomp

tmp = sa
while tmp.size > 0 do
  c = tmp.slice!(0)
  case c
  when "a"
    tmp = sa
  when "b"
    tmp = sb
  when "c"
    tmp = sc
  end
end

puts c.upcase



Measured memory_bytes: 1788
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), K = sc.nextInt();
		int A[] = new int[N];
		for(int i=0;i<N;i++)A[i]=sc.nextInt();
		sc.close();
		
		int sum[] = new int[N+1];
		sum[0]=0;
		for(int i=0;i<N;i++)sum[i+1]=(int)((long)sum[i]+A[i])%K;
		
		int T[] = new int[N+1];
		for(int i=0;i<N+1;i++) {
			T[i]=(sum[i]-i)%K;
			if(T[i]<0)T[i]+=K; //負数をmodでプラスにするにはこの計算するしかない？
		}
		Map<Integer,Integer> map = new HashMap();
		long ans = 0;
		Queue<Integer> q = new ArrayDeque();
		for(int j=0;j<N+1;j++) {
			int cnt = 0;
			if(map.containsKey(T[j])) {
				cnt = map.get(T[j]);
				ans += cnt;
			}
			map.put(T[j],++cnt);
			q.offer(T[j]);
			while(q.size()>=K) {
				int rm = q.poll();
				map.put(rm,map.get(rm)-1);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 81436
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    ll A, B, K;
    cin >> A >> B >> K;

    if(A > K) {
        A = A - K;
    } else if(A <= K && K < A + B) {
        B = B - (K - A);
        A = 0;
    } else {
        A = 0;
        B = 0;
    }

    cout << A << " " << B << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,k;
    cin >> n >> k;
    int a[n];
    rep(i,n){
        cin >> a[i];
    }

    cout << ceil((n-1)*1.0/(k-1)) << endl;
    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N);
  int s = 0;
  rep(i, N) {
    cin >> a[i];
    s += a[i];
  }

  int cnt = 0;
  rep(i, N) {
    if (a[i] * 4 * M >= s) {
      cnt++;
    }
  }

  cout << (cnt >= M ? "Yes" : "No") << endl;

  return 0;
}

Measured memory_bytes: 3576