akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main() {
	int N;
	ll r=0;
	string S,t="MARCH";
	vector<ll> p;
	map<char,ll> m;
	cin >> N;

	m['M']=0, m['A']=0, m['R']=0, m['C']=0, m['H']=0;
	rep(i,N) {
		char t;
		cin >> S;
		t = S.at(0);
		if(m.count(t))
			++m.at(t);
	}

	for(auto x : m)
		p.push_back(x.second);
	
	rep(i,p.size()-2)
		for(int j=i+1; j<p.size()-1; ++j)
			for(int k=j+1; k<p.size(); ++k)
				r += p.at(i)*p.at(j)*p.at(k);

	cout << r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		if(s=="-")break;
		int n,k;cin>>n;
		for(int i=0;i<n;i++){
			cin>>k;
			s=s.substr(k,s.length()-k)+s.substr(0,k);
		}cout<<s<<endl;
	}
	return 0;
}


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

int get_sum(int i){
    int small_sum = 0;
    while(i > 0){
        small_sum += i % 10;
        i /= 10;
    }
    return small_sum;
}

int main(){
    int N, A, B, sum = 0;
    cin >> N >> A >> B;
    for(int i = 1; i <= N; i++){
        if(get_sum(i) >= A && get_sum(i) <= B){
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
/* DSU 
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    rank[v] = 0;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}
*/ 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
 
ll mod(ll a, ll b) {return (a % b + b) % b;}
 
ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
 
using namespace std;

int main()
{
	fast;
	ll r,g,b; cin>>r>>g>>b;
	ll ans = r*100 + g*10 + b;
	if(ans % 4) cout << "NO" << endl;
	else cout << "YES" << endl;	
	return 0;
}

Measured memory_bytes: 3536
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    char a, b;
    cin >> a >> b;
    if(a == 'H'){
        if(b == 'D'){
            cout << 'D';
        }
        else{
            cout << 'H';
        }
    }
    else{
        if(b == 'H'){
            cout << 'D';
        }
        else{
            cout << 'H';
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <complex>
#include <cassert>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const int mod = 99999997;
const ll cons = 100000000000;
const double pi = 3.141592653589793;

bool chk[100002];
int cnt[100002];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);

	chk[1] = true;

	for (int i = 1; i <= n; i++)
	{
		cnt[i] = 1;
	}

	for (int i = 0; i < m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);

		cnt[u]--;
		cnt[v]++;

		if (chk[u])
		{
			chk[v] = true;
			if (cnt[u] == 0)chk[u] = false;
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (chk[i])ans++;
	}

	printf("%d\n", ans);

	return 0;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

int main()
{
	cout << setprecision(10);
	int r;
	cin >> r ;

	cout << r * r << endl;

}


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

int main(){
  int d,n;
  cin>>d>>n;
  
  if (n!=100){
    cout<<n;
    
    for (int i=0;i<2*d;i++){
      cout<<0;
    }
    
    cout<<endl;
  }
  
  if (n==100){
    cout<<101;
    
    for (int i=0;i<2*d;i++){
      cout<<0;
    }
    cout<<endl;
  }
}
  













Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int a[3][3];
    int mark[3][3];
    int temp;
    int flag=0;
    memset(mark,0,sizeof(mark));
    int n;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
            cin>>a[i][j];
    }
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        for(int x=0;x<3;x++)
        {
            for(int y=0;y<3;y++)
            {
                if(a[x][y]==temp)
                    mark[x][y]=1;
            }
        }
    }
    for(int i=0;i<3;i++)
    {
        if(mark[i][0]+mark[i][1]+mark[i][2]==3||mark[0][i]+mark[1][i]+mark[2][i]==3||mark[0][0]+mark[1][1]+mark[2][2]==3||mark[0][2]+mark[1][1]+mark[2][0]==3)
            flag=1;
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    int ans = 0;
    int cnt = 0;
    int prev = -1;
    rep(i, N) {
        int h = H[i];
        if (prev >= h) {
            cnt ++;
            ans = max(ans, cnt);
        }else{
            cnt = 0;
        }
        prev = h;
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 640
import math
import itertools

N = int(input())
x= [0]*N
y= [0]*N
for i in range(N):
  x[i], y[i] = map(int, input().split())
D = [[0]*N for i in range(N)]
for i in range(N):
  for j in range(N):
    D[i][j] = ((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
P = list(itertools.permutations(list(range(N)),N))
dist = [0]*len(P)
for j, p in enumerate(P):
  for i in range(N-1):
    dist[j] += D[p[i]][p[i+1]]
ave = sum(dist)/len(P)
print(ave)

Measured memory_bytes: 9332
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.charAt(0) != 'A') {
            System.out.println("WA");
            return;
        }
        String sub = s.substring(2, s.length()-1);
        int count = 0;
        for (int i = 0; i < sub.length(); i++) {
            if (sub.charAt(i) == 'C') count++;
        }
        if (count != 1) {
            System.out.println("WA");
            return;
        }

        int lcount = 0;
        for (int i = 0; i < s.length(); i++) {
            if (String.valueOf(s.charAt(i)).matches("[A-Z]")) lcount++;
        }
        if (lcount != 2) {
            System.out.println("WA");
        } else {
            System.out.println("AC");
        }
    }
}

Measured memory_bytes: 21844
import java.util.*;class Main{public static void main(String[]g){Scanner S=new Scanner(System.in);double t,a[]=new double[8];for(int i,b,f;S.hasNext();System.out.println(b>2||f>2?"YES":"NO")){for(i=0;i<8;)a[i++]=S.nextDouble();for(b=f=i=0;i<6;i+=2){t=a[6]*(a[i+1]-a[(i+3)%6])+a[i]*(a[(i+3)%6]-a[7])+a[(i+2)%6]*(a[7]-a[i+1]);if(t<0)b++;if(t>0)f++;}}}}


Measured memory_bytes: 32004
function Main(input) {
  input = input.trim();
  var S = input.split("");
  var Slong = S.length
  var Muki = ">";
  var Out = 1;
  var V = [];
  var Left = 0;
  var Right = 0;
  var Sum = 0;
  for(var i = 0;i<Slong;i++){
 
    if(S[i] == Muki){
      if(Muki == ">"){
        Left ++;
    }else{
      Right ++;
    }
    Out = 0;
  }else{
    if(Muki == "<"){
      V.push({L:Left,R:Right})
      Muki = ">"
      Left = 0;
      Right = 0;
      Left ++;
      Out = 1;
    }else{
      Muki = "<"
      Right ++;
      Out = 0;
    }
  }
  }
  if(Out == 0){
  V.push({L:Left,R:Right})
  }
  
//console.log(V);
for(var i=1;i<V.length;i++){
  if(V[i-1].R < V[i].L){
    V[i-1].R --; 
  }else{
    V[i].L --;
  }
}
//  console.log(V);
for(var i=0;i<V.length;i++){
    Sum += (V[i].L*(V[i].L+1))/2;
//    console.log((V[i].L*(V[i].L+1))/2);
    Sum += (V[i].R*(V[i].R+1))/2;
//    console.log((V[i].R*(V[i].R+1))/2);
  }
  console.log(Sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main()
{
    int m1, d1, m2, d2, ans;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 != m2)
    {
        ans = 1;
    }
    else
    {
        ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdio.h>

int main()
{
    int q,t,f;
    while(~scanf("%d %d %d",&q,&t,&f))
    {
        if(f>=q&&f<=q+t)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
from collections import deque
import sys
input = sys.stdin.readline

def bfs():
    depth[0] = 0
    queue = deque([])
    queue.append(0)
    
    while queue:
        current_node = queue.popleft()
        
        for next_node in adj_list[current_node]:
            if depth[next_node] == -1:
                parent[0][next_node] = current_node
                depth[next_node] = depth[current_node] + 1
                queue.append(next_node)
    
def init():
    bfs() #initialize depth and parent[0]
    
    for k in range(1, log_size):
        for v in range(N):
            if parent[k-1][v] < 0:
                parent[k][v] = -1
            else:
                parent[k][v] = parent[k-1][parent[k-1][v]]

def lca(u, v): #return lowest common ancestor when 0 is root node
    if depth[u] > depth[v]:
        u, v = v, u
    
    for k in range(log_size):
        if (depth[v]-depth[u])>>k & 1:
            v = parent[k][v]
    
    if u == v:
        return u
    
    for k in range(log_size-1, -1, -1):
        if parent[k][u] != parent[k][v]:
            u = parent[k][u]
            v = parent[k][v]
    
    return parent[0][u]
    
N = int(input())
log_size = N.bit_length() #ceil(log)
depth = [-1] * N
parent = [[-1] * N for _ in range(log_size)]
adj_list = [[] for _ in range(N)]

for i in range(N):
    kc = list(map(int, input().split()))
    
    for ci in kc[1:]:
        adj_list[i].append(ci)
        adj_list[ci].append(i)

init()
q = int(input())

for _ in range(q):
    ui, vi = map(int, input().split())
    print(lca(ui, vi))


Measured memory_bytes: 40552
#include<stdio.h>
int main(void)
{
	float a,b;
	while(scanf("%f %f",&a,&b)!=EOF){
	if(a<35.5 && b<71.0){
			printf("AAA\n");
			}
	else if(a<37.5 && b<77.0){
			printf("AA\n");
			}
	else if(a<40.0 && b<83.0){
			printf("A\n");
			}
	else if(a<43.0 && b<89.0){
			printf("B\n");
			}
	else if(a<50.0 && b<105.0){
			printf("C\n");
			}
	else if(a<55.0 && b<116.0){
			printf("D\n");
			}
	else if(a<70.0 && b<148.0){
			printf("E\n");
			}
	else{
			printf("NA\n");
			}
			}
		return 0;
}

		

Measured memory_bytes: 1032
//
//  main.c
//  ICPC Ranking
//
//  Created by x15071xx on 2016/06/16.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//

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

void swap(int team[50][4],int x,int i){
    int tmp;
    
    tmp = team[x][i];
    team[x][i] = team[x-1][i];
    team[x-1][i] = tmp;
    
}

int main(int argc, const char * argv[]) {
    
    while (1) {
        int m,t,p,r;
        int sm,st,sp,sr;
        int i,j,k,l;
        
        int team[50][4];//0,???????????°1,??£?????°2,??????3,??????
        int team_wrong[50][10];
        
        
        scanf("%d %d %d %d",&m,&t,&p,&r);
        for (i=0; i<50; i++) {
            for (j=0; j<4; j++) {
                team[i][j] = 0;
            }
        }
        for (i=0; i<50; i++) {
            for (j=0; j<10; j++) {
                team_wrong[i][j] = 0;
            }
        }

        for (i=t; i>0; i--) {
            team[t-i][0] = i;
        }
        
        if (m==0&&t==0&&p==0&&r==0) {
            break;
        }
        
        for (i=0; i<r; i++) {
            
            scanf("%d %d %d %d",&sm,&st,&sp,&sr);
            
            if (sr == 0) {
                //seikai
                team[abs(st-t)][1]++;
                team[abs(st-t)][2] += sm + (team_wrong[abs(st-t)][abs(sp-p)] * 20);
            } else {
                //huseikai
                team_wrong[abs(st-t)][abs(sp-p)]++;
            }
        }
        //seitousuu
        for (i=0; i<t-1; i++) {
            for (j=t-1; j>i; j--) {
                if (team[j][1] > team[j-1][1]) {
                    swap(team,j,0);
                    swap(team,j,1);
                    swap(team,j,2);
                    swap(team,j,3);
                }
            }
        }
        
        //zyunniduke
        for (i=0; i<t; i++) {
            if (team[i][1] != team[i+1][1]) {
                for (j=i+1; j<t; j++) {
                    team[j][3]++;
                }
            }
        }
        
        
        //??????
        for (i=0; i<t-1; i++) {
            j=0;
            while (team[i+j][1]  == team[i+j+1][1]) {
                j++;
            }
            
            for (k=0; k<i+j; k++) {
                for (l=i+j; l > k; l--) {
                    if ((team[l][2] < team[l-1][2] )&& (team[l][3] == team[l-1][3])) {
                        swap(team,l,0);
                        swap(team,l,1);
                        swap(team,l,2);
                        swap(team,l,3);
                    }
                }
            }
        }
        
        for (i=0; i<t-1; i++) {
            printf("%d",team[i][0]);
            
            if ((team[i][3] != team[i+1][3]) || (team[i][2] != team[i+1][2])) {
                printf(",");
            } else if ((team[i][3] == team[i+1][3])&&(team[i][2] == team[i+1][2])){
                printf("=");
            }
            
            if (t-2 == i) {
                printf("%d\n",team[i+1][0]);
                break;
            }
        }
        
        if (t == 1) {
            printf("%d\n",team[0][0]);
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 608
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define loop(i,start, stop) for(int i = start; i < (stop); i++)
using namespace std;

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

  if (S.size() <= K){cout << S << endl;}
  else{
    loop(i,0,K)
      cout << S[i];
    cout << "..." << endl;
  }

  return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>

#define PutChar(c) ; *p = (char)(c); ++p;

#define MAX_N (2000001)
#define MAX_Ai (10001)
#define STR_SIZE (10000010)

int getNum(void);
void putNum(int n);
void CountingSort(int A[], int B[], int k, int len);

int A[MAX_N];
int B[MAX_N];
char str[STR_SIZE];
char *p = str;

int main(void) {
	register int i;
	int n;

	fread(str, 1, STR_SIZE, stdin);
	
	n = getNum();
	for (i = 1; i <= n; ++i) {
		A[i] = getNum();
	}
	
	CountingSort(A, B, MAX_Ai, n);
	
	p = str;
	--n;
	for (i = 1; i <= n; ++i) {
		putNum(B[i]);
		PutChar(' ');
	}
	putNum(B[i]);
	PutChar('\0');
	
	puts(str);
	
	return 0;
}

int getNum(void) {
	int n = 0;
	while ((*p >= '0') && (*p <= '9')) {
		n = n * 10 + (int)(*p - '0');
		++p;
	}
	++p;
	return n;
}

void putNum(int n) {
	int d;
	if (n < 10) {
		PutChar('0' + n);
		return;
	}
	d = n / 10;
	if (d) putNum(d);
	PutChar('0' + (n - (d * 10)));
}

void CountingSort(int A[], int B[], int k, int len) {
	register int i;
	int C[MAX_Ai] = { 0 };
	for (i = 1; i <= len; ++i) {
		++C[A[i]];
	}
	for (i = 1; i <= k; ++i) {
		C[i] += C[i - 1];
	}
	for (i = 0; i <= len; ++i) {
		B[C[A[i]]] = A[i];
		--C[A[i]];
	}
}

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


int main(void) {
  ll N;
  cin >> N;


  string ans;

  while (N > 0) {
    ll r = N % 26;
    r = (r == 0) ? 26 : r;
    ans.push_back('a' + r - 1);
    N = (N - r) / 26;
  }

  reverse(ans.begin(), ans.end());

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pair<int,int> >

using namespace std;
typedef long long ll;
int maxn = 100005;
ll dp[105][100005];

int N,W;

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

    for(int i = 1; i <= N; i++){
        ll w,v;
        scanf("%lld %lld", &w, &v);
        for(int j = 0; j <= W; j++){
            if(i == 1 ){
                if(j-w >= 0)
                    dp[i][j] = v;
                continue;
            }
            if(j - w >= 0){
                dp[i][j] = max(dp[i-1][j], v+dp[i-1][j-w]);
            }
            dp[i][j] = max(dp[i-1][j],dp[i][j]);
        }
    }

    printf("%lld\n", dp[N][W]);
	return 0;
}

Measured memory_bytes: 79360
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().parse::<usize>().unwrap();
    buf.clear();
    io::stdin().read_line(&mut buf).unwrap();
    let mut xs: Vec<_> = buf
        .split_ascii_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect();
    assert!(xs.len() == n);
    xs.sort_by(|a, b| a.partial_cmp(b).unwrap());

    let mut dp = vec![None; *xs.last().unwrap() + 1];

    for x in xs.iter() {
        if dp[*x].is_some() {
            dp[*x] = Some(false);
        } else {
            dp[*x] = Some(true);
            for i in ((x + x)..dp.len()).step_by(*x) {
                dp[i] = Some(false);
            }
        }
    }

    println!(
        "{}",
        xs.iter()
            .filter(|x| dp[**x].unwrap())
            .collect::<Vec<_>>()
            .len()
    );
}


Measured memory_bytes: 7948
#include <cstdio>

#include <fstream>

#include <algorithm>

#include <cmath>

#include <deque>

#include <vector>

#include <queue>

#include <string>

#include <cstring>

#include <map>

#include <stack>

#include <set>
using namespace std;
 

int main(){
    
int n;
scanf("%d",&n);
printf("%d\n",n*n*n);


    return 0;
    }




Measured memory_bytes: 2668
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    string op;
    ll a, b;
    cin >> a >> op >> b;
    if (op == "+")
        cout << a + b << "\n";
    else
        cout << a - b << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n, a, b;

	while(scanf("%d%d%d", &n, &a, &b)==3)
	{
		int ans=min(a*n, b);

		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h> 
int main(void) { 
  int a[10000],b[10000],i,j,box;
  i=0;
  scanf("%d %d",&a[i],&b[i]);
  while(a[i] != 0 || b[i] != 0){
    if(a[i]>b[i]){
      box=b[i];
      b[i]=a[i];
      a[i]=box;
    }
    i++;
    scanf("%d %d",&a[i],&b[i]);
  }
  for(j=0;j<i;j++) printf("%d %d\n",a[j],b[j]);
  return 0;
}

Measured memory_bytes: 2532
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	set<char>ms;
	ms.insert(s[0]);
	ms.insert(s[1]);
	ms.insert(s[2]);
	if(ms.size()==1)
	{
		cout<<"No";
	}
	else
	{
		cout<<"Yes";
	}
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

void solve(long long a, long long b){
  if (a * b == 15) {
    std::cout << '*' << std::endl;
  } else if (a + b == 15){
    std::cout << '+' << std::endl;
  } else {
    std::cout << 'x' << std::endl;
  }
}

int main(){
  long long b;
  long long a;
  scanf("%lld",&a);
  scanf("%lld",&b);
  solve(a, b);
  return 0;
}


Measured memory_bytes: 256
bingo_card =list(map(int, input().split()))
for _ in range(2):
    bingo_card+=list(map(int, input().split()))

n = int(input())

for _ in range(n):
    num = int(input())
    if num in bingo_card:
        bingo_card[bingo_card.index(num)] = 'o'

if (bingo_card[0]==bingo_card[1]==bingo_card[2]) or (bingo_card[3]==bingo_card[4]==bingo_card[5]) or (bingo_card[6]==bingo_card[7]==bingo_card[8]):
    ans = 'Yes'
elif (bingo_card[0]==bingo_card[3]==bingo_card[6]) or (bingo_card[1]==bingo_card[4]==bingo_card[7]) or (bingo_card[2]==bingo_card[5]==bingo_card[8]):
    ans = 'Yes'
elif (bingo_card[0]==bingo_card[4]==bingo_card[8]) or (bingo_card[2]==bingo_card[4]==bingo_card[6]):
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

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

using namespace std;

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

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

  ll N = S.length();
  vvi v;
  ll a = 0, b = 0, c = 0;
  for (ll i = 0; i < N; i++) {
    if (b == 0) {
      a = i;
    }
    if (S[i] == 'R') {
      b += 1;
    }
    if (S[i] == 'L'){
      c += 1;
    }
    if (i == N - 1) {
      v.push_back({a, b, c});
      continue;
    }
    if (S[i] == 'L' && S[i + 1] == 'R') {
      v.push_back({a, b, c});
      a = b = c = 0;
    }
  }

  vi ans(N);
  for (vi &i: v) {
    ll a = i[0], b = i[1], c = i[2];
    ans[a + b] += b / 2;
    ans[a + b - 1] += b - b / 2;
    ans[a + b] += c - c / 2;
    ans[a + b - 1] += c / 2;
  }

  for (ll i = 0; i < N; i++) {
    cout << ans[i];
    if (i == N - 1) cout << endl;
    else cout << ' ';
  }
}


Measured memory_bytes: 4020
#include <bits/stdc++.h>
#define int long long
#define inf INT_MAX
#define f first
#define s second

using namespace std;

typedef pair<int,int> pi;

int n;
pi A[100050];
int L[100050], R[100050];
int32_t main(){
	cin >> n;
	for(int i=0; i<n; ++i) cin >> A[i].f >> A[i].s;


	int bigL = 0, smallR = inf, longest=0;
	for(int i=0; i<n; ++i) bigL = max(bigL, A[i].f), smallR = min(smallR, A[i].s);
	for(int i=0; i<n; ++i) if(A[i].f != bigL and A[i].s != smallR) longest = max(longest, A[i].s-A[i].f+1); // may needa check if multiple bigL, but only if it fails
	int ans = max(0LL, smallR-bigL+1) + longest; //first case
	
	sort(A, A+n);
	L[0] = A[0].f;
	for(int i=1; i<n; ++i) L[i] = max(L[i-1],A[i].f);
	R[n-1] = A[n-1].s;
	for(int i=n-2; i>=0; --i) R[i] = min(R[i+1],A[i].s);
	for(int i=0; i<n; ++i){
		ans = max(max(smallR-L[i]+1,0LL)+max(R[i+1]-bigL+1,0LL),ans);
	}
	cout << ans;
}


Measured memory_bytes: 3328
import copy
mod=10**9+7
def calc(nums,n):
    if n==2:
        return ((nums[0]%mod)*(nums[1]%mod))%mod
    cpy=copy.deepcopy(nums)    
    save=nums[n-2]
    nums[n-2]=nums[n-1]
    for i in range(n-3,-1,-1):
        s=nums[i]%mod
        nums[i]=(save%mod+nums[i+1]%mod)%mod
        save=s%mod
       
    ans=0  
    
    for i in range(n-1):
        ans=((ans%mod)  +  ((cpy[i]%mod)*(nums[i]%mod))%mod)%mod
    return ans       
    





n=int(input())
nums=list(map(int,input().split()))
print(calc(nums,n))


Measured memory_bytes: 31836
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <bitset>
#include <assert.h>
//defines
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
//functions


using namespace std;    



int main () {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)){
        cout << "Yes";
    }else{
        cout << "No";
    }
return 0;
}

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

int		main(void)
{
	int a, b;
	cin >> a >> b;

	int ans = a + b;
	if (ans > 24)
		ans -= 24;
	if (ans == 24)
		ans = 0;
	cout << ans << endl;
}



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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define for_each(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll cnt = n / (a + b);
    ll ans = 0;
    ans += cnt * a;
    n -= cnt * (a + b);
    ans += min(n, a);
    out(ans);
    return 0;
}


Measured memory_bytes: 256
#ABC095-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
a,b,c,x,y=IL()
c=c*2
if c<=a:
    if c<=b:
        print(c*max(x,y))
    else:
        print(c*x+max(0,(y-x)*b))
elif c<=b:
    print(c*y+max(0,(x-y)*a))
elif c<=a+b:
    if x>=y:
        print(c*y+a*(x-y))
    else:
        print(c*x+b*(y-x))
else:
    print(a*x+b*y)

Measured memory_bytes: 38384
# -*- coding: utf-8 -*-
import sys

N, *XYU = map(str, sys.stdin.read().split())

UD = {}
UR = {}
UL = {}
DU = {}
DR = {}
DL = {}
RU = {}
RD = {}
RL = {}
LU = {}
LD = {}
LR = {}

for i in range(int(N)):
  X = int(XYU[3*i])
  Y = int(XYU[3*i+1])
  U = XYU[3*i+2]
  if U == 'U':
    if X in UD.keys():
      UD[X].append(Y)
    else:
      UD[X] = [Y]
    if X+Y in UR.keys():
      UR[X+Y].append(X)
    else:
      UR[X+Y] = [X]
    if X-Y in UL.keys():
      UL[X-Y].append(X)
    else:
      UL[X-Y] = [X]
  elif U == 'D':
    if X in DU.keys():
      DU[X].append(Y)
    else:
      DU[X] = [Y]
    if X+Y in DL.keys():
      DL[X+Y].append(X)
    else:
      DL[X+Y] = [X]
    if X-Y in DR.keys():
      DR[X-Y].append(X)
    else:
      DR[X-Y] = [X]
  elif U == 'R':
    if Y in RL.keys():
      RL[Y].append(X)
    else:
      RL[Y] = [X]
    if X+Y in RU.keys():
      RU[X+Y].append(X)
    else:
      RU[X+Y] = [X]
    if X-Y in RD.keys():
      RD[X-Y].append(X)
    else:
      RD[X-Y] = [X]
  else:
    if Y in LR.keys():
      LR[Y].append(X)
    else:
      LR[Y] = [X]
    if X+Y in LD.keys():
      LD[X+Y].append(X)
    else:
      LD[X+Y] = [X]
    if X-Y in LU.keys():
      LU[X-Y].append(X)
    else:
      LU[X-Y] = [X]

def dist(X,Y):
  minimum = -1
  X_len = len(X)
  X_index = 0
  Y_len = len(Y)
  Y_index = 0
  while X_index<X_len and Y_index<Y_len:
    x = X[X_index]
    y = Y[Y_index]
    if x<y:
      if minimum == -1:
        minimum = y-x
      else:
        minimum = min(minimum, y-x)
      X_index += 1
    else:
      Y_index += 1
  return minimum

second = -1

for x in UD.keys():
  if x in DU.keys():
    distance = dist(sorted(UD[x]),sorted(DU[x]))
    if distance>0:
      if second == -1:
        second = 5*distance
      else:
        second = min(second,5*distance)

for x in RL.keys():
  if x in LR.keys():
    distance = dist(sorted(RL[x]),sorted(LR[x]))
    if distance>0:
      if second == -1:
        second = 5*distance
      else:
        second = min(second,5*distance)

for x in UR.keys():
  if x in RU.keys():
    distance = dist(sorted(RU[x]),sorted(UR[x]))
    if distance>0:
      if second == -1:
        second = 10*distance
      else:
        second = min(second,10*distance)

for x in UL.keys():
  if x in LU.keys():
    distance = dist(sorted(UL[x]),sorted(LU[x]))
    if distance>0:
      if second == -1:
        second = 10*distance
      else:
        second = min(second,10*distance)

for x in RD.keys():
  if x in DR.keys():
    distance = dist(sorted(RD[x]),sorted(DR[x]))
    if distance>0:
      if second == -1:
        second = 10*distance
      else:
        second = min(second,10*distance)

for x in LD.keys():
  if x in DL.keys():
    distance = dist(sorted(DL[x]),sorted(LD[x]))
    if distance>0:
      if second == -1:
        second = 10*distance
      else:
        second = min(second,10*distance)

if second == -1:
  print('SAFE')
else:
  print(second)

Measured memory_bytes: 141560
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;

int h[(int)1e5+5];
int dp[(int)1e5+5];

int main() {
	IOS
	int n;
	cin >> n;
	for(int i=0; i<n; i++) cin >> h[i];
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i=2; i<n; i++) {
		dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]));
	}
	cout << dp[n-1];
 	return 0;
}


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

int N, M;
int a[50];
int b[50];

int sum[51][51][51][51];
int dp[2][3][51][51][51][51];

const int INF = 1e9;

int calc(int p, int ai, int an, int bi, int bn) {
	int& s = sum[ai][an][bi][bn];
	//if(s != INF) return s;
	s = 0;
	int at = ai - 1, bt = bi - 1;
	p = 1 - p;
	bool ng0 = false, ng1 = false;
	while(at >= ai - an || bt >= bi - bn) {
		if(p == 0) {
			if(a[at] == -1) ng1 = true;
			else if(!ng0) s += a[at];
			at--;
		}
		else {
			if(b[bt] == -1) ng0 = true;
			else if(!ng1) s -= b[bt];
			bt--;
		}
		p = 1 - p;
	}
	return s;
}

int f(int p, int pass, int ai, int an, int bi, int bn) {
	int& d = dp[p][pass][ai][an][bi][bn];
	if(d != INF) return d;
	// pass
	int s = calc(p, ai, an, bi, bn);
	int npass = pass;
	if(an == 0 && bn == 0) npass++;

	if(p == 0) {
		d = -INF;
		if(npass == 2) {
			d = max(d, s);
		}
		else {
			d = max(d, s + f(1 - p, npass, ai, 0, bi, 0));
		}
		// put
		if(ai < N) {
			d = max(d, f(1 - p, 0, ai + 1, an + 1, bi, bn));
		}
	}
	else {
		d = INF;
		if(npass == 2) {
			d = min(d, s);
		}
		else {
			d = min(d, s + f(1 - p, npass, ai, 0, bi, 0));
		}
		// put
		if(bi < M) {
			d = min(d, f(1 - p, 0, ai, an, bi + 1, bn + 1));
		}
	}
	return d;
}

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

	while(cin >> N >> M) {
		for(int i = 0; i < N; i++) {
			cin >> a[i];
		}
		for(int i = 0; i < M; i++) {
			cin >> b[i];
		}
		//reverse(a, a + N);
		//reverse(b, b + M);
		fill((int*)begin(dp), (int*)end(dp), INF);
		cout << f(0, 0, 0, 0, 0, 0) << endl;
	}
}

Measured memory_bytes: 174436
#include <stdio.h>

int main(){
  char line[1201];
  char *string_ptr;
  int i, j;
  i=0;
  int count[26];
  for(i=0; i<26; ++i){
	count[i]=0;
  }
  while(fgets(line, sizeof(line), stdin)!=NULL){
	i=0;
	while(line[i]!='\n'){
	  for(j=0; j<26; ++j){
		if((line[i]==('a'+j))||(line[i]==('A'+j)))
		  ++count[j];
	  }
	  ++i;
	}
  }

  for(i=0; i<26; ++i){
	printf("%c : %d\n", 'a'+i, count[i]);
  }
 
  return 0;
}



Measured memory_bytes: 2044
#include<iostream>
using namespace std;
int main()
{
    while(1)
    {
        int dp[31]={1,1,2,4};
        int n;
        cin>>n;if(!n)return 0;
        for(int i=4;i<=n;++i){
            dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
        }
        cout<<((dp[n]-1)/3650)+1<<endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int main()
{
    int n, w, h; cin >> n >> w >> h;

    vector<int> W(w+1), H(h+1);
    loop (n, i) {
        int x, y, p; cin >> x >> y >> p;
        W[max(x-p, 0)] += 1;
        W[min(x+p, w)] += -1;
        H[max(y-p, 0)] += 1;
        H[min(y+p, h)] += -1;
    }
    loop (w, i) W[i+1] += W[i];
    loop (h, i) H[i+1] += H[i];
    int ok = 1;
    loop (w, i) ok = ok && W[i];
    if (!ok) {
        ok = 1;
        loop (h, i) ok = ok && H[i];
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  vector<ll> t(n+1);
  vector<ll> x(n+1);
  vector<ll> y(n+1);
  t[0] = 0, x[0] = 0, y[0] = 0;
  rep(i, 1, n+1) cin >> t[i] >> x[i] >> y[i];

  bool ans = true;
  rep(i, 0, n) {
    ll distance = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    ll time = t[i+1]-t[i];
    if(distance > time) {
      ans = false;
      break;
    }
    else if((time - distance) %2 == 1) {
      ans = false;
      break;
    }
  }  
  cout << ( ans ?"Yes" :"No") << "\n";
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long long>A(N), count(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		count[A[i] - 1]++;
	}
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		ans += count[i] * (count[i] - 1) / 2;
	}
	for (int i = 0; i < N; i++) {
		long long tmp = ans - count[A[i] - 1] + 1;
		//tmp += (count[A[i] - 1] - 1)*(count[A[i] - 1] - 2) / 2;
		cout << tmp << endl;
	}
	return 0;
}

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

//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
   vector<int> a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int n;
   cin>>n;
   cout<<a.at(n-1)<<endl;
}
  



Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int d;
ll c[26], s[370][26], last[370][26], t[370];


ll calc(){
	ll score = 0;
        REP(i, 1, d+1){
                REP(j, 0, 26){
                        if(j==t[i]-1){
                                score += s[i][j];
                                last[i][j] = i;
                        }else last[i][j] = last[i-1][j];
                        score -= c[j] * (i - last[i][j]);
                }
        }
	return score;
};

int main(){
        scanf("%d", &d);
        REP(i, 0, 26) scanf("%ld", &c[i]);
        REP(i, 1, d+1) REP(j, 0, 26) scanf("%ld", &s[i][j]);
        REP(i, 1, d+1) t[i] = 0;
        REP(i, 0, 1+d) REP(j, 0, 26) last[i][j] = 0;
	
	ll score = calc();

	ll limit = 0;
	REP(i, 1, d+1) REP(j, 0, 26) {
		ll prev = t[i];
		t[i] = j;
		ll newscore = calc();
		if(newscore > score and limit%2) score = newscore;
		else t[i] = prev;
		if(limit++>1500000) break;
	}
	
	REP(i, 1, d+1) printf("%ld\n", t[i]);
	return 0;
}



Measured memory_bytes: 3952
#include<iostream>
using namespace std;
int main(){
    long long h,n,a,b;
    cin>>h>>n;
    long long dp[h+1];
    for(long long i=0LL;i<h+1LL;i++)dp[i]=10000000000LL;
    dp[h]=0LL;
    for(long long i=1LL;i<=n;i++){
        cin>>a>>b;
        for(long long j=h;j>=0LL;j--){
            dp[j]=min(dp[j],dp[min(h,j+a)]+b);
        }
    }
    cout<<dp[0]<<endl;
    return 0;
}

Measured memory_bytes: 384
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool is_parindrome(string s)
{
  ulong len = s.length;
  for (int i = 0; i < len / 2; ++i) {
    if (s[i] != s[len - 1 - i]) {
      return false;
    }
  }
  return true;
}

void main()
{
  string str = readln.chomp;
  string dst = "";
  int[] index;
  foreach (int i, c; str) {
    if (c == 'x') {
      continue;
    }
    dst ~= c;
    index ~= i;
  }
  if (!dst.is_parindrome) {
    writeln = -1;
    return;
  }
  if (dst.length == 0) {
    writeln = 0;
    return;
  }
  int right;
  int left;
  if (dst.length % 2 == 1) {
    right = index[dst.length / 2] + 1;
    left = index[dst.length / 2] - 1;
  } else {
    right = index[dst.length / 2];
    left = index[dst.length / 2 - 1];
  }
  // stderr.writeln(left, " ", right);
  int cnt = 0;
  while (0 <= left && right < str.length) {
    if (str[left] == str[right]) {
      --left;
      ++right;
      continue;
    }
    if (str[left] == 'x') {
      ++cnt;
      --left;
    }
    else if (str[right] == 'x') {
      ++cnt;
      ++right;
    }
    else {
      writeln = -1;
      return;
    }
  }
  cnt += left + 1 + str.length - right;
  bool dame = false;
  for (; 0 <= left; --left) {
    dame |= str[left] != 'x';
  }
  for (; right < str.length; ++right) {
    dame |= str[right] != 'x';
  }
  if (dame) {
    writeln = -1;
    return;
  }
  cnt.writeln;
}


Measured memory_bytes: 3864
from itertools import combinations_with_replacement
n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split()))for _ in range(q)]
ans = 0
for x in combinations_with_replacement(range(1, m+1), n):
    cnt = 0
    for a, b, c, d in abcd:
        if x[b-1]-x[a-1] == c:
            cnt += d
    if ans < cnt:
        ans = cnt

print(ans)


Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main(void) {
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double hSp = PI / 360.0, mSp = PI / 30.0;
  int t = 60 * h + m;  //経過時間(分)
  double ang = abs((double)(mSp - hSp) * t);
  double ans = sqrt(a * a + b * b - 2.0 * a * b * cos(ang));
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 4228
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N;
int A[MAX_N];

int main(void)
{
  cin >> N;
  REP(i, N) cin >> A[i];

  int zero = 0;
  int minus = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] < 0) minus++;
    if (A[i] == 0) zero++;
  }

  ll ans = 0;
  if (minus % 2 == 0 || zero > 0) {
    // Add all
    for (int i = 0; i < N; i++) ans += abs(A[i]);
  }
  else {
    int mi = 1000000001;
    for (int i = 0; i < N; i++) {
      mi = min(mi, abs(A[i]));
    }
    for (int i = 0; i < N; i++) ans += abs(A[i]);
    ans -= 2 * mi;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
A=[]
b=[]
c=[[0,0,0],[0,0,0],[0,0,0]]
d=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
    x,y,z=map(int,input().split())
    A.append([x,y,z])

N = int(input())

for i in range(N):
    b.append(int(input()))

for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            c[i][j] = 1
            d[j][i] = 1

if [1,1,1] in c:
    print('Yes')
elif [1,1,1] in d:
    print('Yes')
elif (c[0][0]+c[1][1]+c[2][2] == 3) or (c[0][2]+c[1][1]+c[2][0] == 3):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint R; cin >> R;
    cout << 2 * M_PI * R << "\n";
}

Measured memory_bytes: 3824
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
cnt_A = Counter(A)

A_ = sorted([[k, v] for k, v in cnt_A.items() if v >= 2], reverse=True)

if len(A_) == 0:
    print(0)
elif A_[0][1] >= 4:
    print(A_[0][0] ** 2)
else:
    print(A_[0][0] * A_[1][0])

Measured memory_bytes: 22216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> p;


int main(){
    int N; cin >> N;
    vector<Int> A(N), B(N);
    rep(i,N){
        cin >> A[i];
        B[i] = A[i]+i;
    }

    map<Int,int> cnt;
    rep(i,N){
        cnt[B[i]]++;
    }
    
    Int ans = 0;
    rep(i,N) ans += cnt[i-A[i]];
    cout << ans << endl;
}


Measured memory_bytes: 28884
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
const int INF = (int)1e9 + 7;
template<class T> inline bool chmin(T &a, T b) { return a > b ? (a = b, 1) : 0; }
using pii = pair<int, int>;
pii operator+(pii a, pii b) { return {a.first + b.first, a.second + b.second}; }

int main() {
    int n; cin >> n;
    int ma, mb; cin >> ma >> mb;
    vector<pair<int, int>> ps(n);
    for (auto &p: ps) {
        int a, b, c; cin >> a >> b >> c;
        p = {a * mb - b * ma, c};
    }
    int n1 = n / 2, n2 = n - n1;
    map<int, int> mp1, mp2;
    for (int mask = 1; mask < 1 << n1; mask++) {
        pair<int, int> sum;
        for (int i = 0; i < n1; i++) if (mask >> i & 1) sum = sum + ps[i];
        int diff = sum.first, cost = sum.second;
        if (mp1.count(diff)) chmin(mp1[diff], cost);
        else mp1[diff] = cost;
    }
    for (int mask = 1; mask < 1 << n2; mask++) {
        pair<int, int> sum;
        for (int i = 0; i < n2; i++) if (mask >> i & 1) sum = sum + ps[i + n1];
        int diff = sum.first, cost = sum.second;
        if (mp2.count(diff)) chmin(mp2[diff], cost);
        else mp2[diff] = cost;
    }
    int mi = INF;
    for (auto &p: mp1) {
        if (p.first == 0) chmin(mi, p.second);
        else if (mp2.count(-p.first)) chmin(mi, p.second + mp2[-p.first]);
    }
    for (auto &p: mp2) {
        if (p.first == 0) chmin(mi, p.second);
    }
    cout << (mi == INF ? -1 : mi) << endl;
    return 0;
}


Measured memory_bytes: 384