akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    ($x:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        $x = buf.trim().parse().unwrap();
    };

    ($x:expr, $($y:expr), +) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        input_iter!(buf.split_whitespace(), $x, $($y), +);
    };

    ($v:expr; $size:expr) => {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        for v in buf.split_whitespace() {
            $v.push(v.parse().unwrap());
        }
    };

    ($v:expr; $h_size:expr, $w_size:expr) => {
        for _ in 0..$h_size {
            let mut part_vec = Vec::new();
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).ok();
            for v in buf.split_whitespace() {
                part_vec.push(v.parse().unwrap());
            }
            $v.push(part_vec);
        }
    };
}

#[allow(unused_macros)]
macro_rules! input_iter {
    ($iter:expr, $x:expr) => {
        $x = $iter.next().unwrap().parse().unwrap();
    };

    ($iter:expr, $x:expr, $($y:expr), +) => {
        let mut iter = $iter;
        $x = iter.next().unwrap().parse().unwrap();
        input_iter!(iter, $($y), *);
    };
}

use std::collections::*;
use std::collections::hash_map::Entry::*;

fn main() {
    let (n, m): (usize, usize);
    input!(n, m);
    let mut works = vec![vec![]; m + 1];
    for _ in 0..n {
        let (a, b): (usize, usize);
        input!(a, b);
        if a <= m {
            works[a].push(b);
        }
    }
    let mut candidates = BinaryHeap::new();
    let mut ans = 0;
    for i in 1..(m + 1) {
        for work in &works[i] {
            candidates.push(work);
        }
        ans += match candidates.pop(){
            Some(x) => *x,
            None => 0,
        };
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;



signed main(){
    ll n,k;
    double ans=0;
    cin>>n>>k;

    for(int i=1;i <= n;i++)
    {
        ll x=i,cnt=0;
        while(x<k){
              x*=2;
              cnt++;
        }
        ans+=1/(double)(n*1ll<<cnt);
    }

    cout << setprecision(13) << ans << endl;
}




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

int main() {

    ll n; cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0 && i % 5 == 0) {}
        else if (i % 3 == 0) {}
        else if (i % 5 == 0) {}
        else ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
use std::cmp::Ordering;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<(usize, f64)> = (0..n).map(|i| (i, read())).collect();
    let arv_a: f64 = a.iter().map(|x| x.1).sum::<f64>() / a.len() as f64;
    let mut a: Vec<(usize, f64)> = a.iter().map(|&(f, x)| (f, (arv_a - x).abs())).collect();
    a.sort_by(|&(f1, x1), &(f2, x2)| match cmp_f64(&x1, &x2) {
        Ordering::Greater => Ordering::Greater,
        Ordering::Less => Ordering::Less,
        Ordering::Equal => f1.cmp(&f2),
    });
    println!("{}", a[0].0);
}

fn cmp_f64(a: &f64, b: &f64) -> Ordering {
    if a.is_nan() {
        return Ordering::Greater;
    }
    if b.is_nan() {
        return Ordering::Less;
    }
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    return Ordering::Equal;
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
///
// File:  0004.cpp
// Author: ymiyamoto
//
// Created on Wed Nov  8 21:45:53 2017
//

#include <cstdint>
#include <iomanip>
#include <iostream>

using namespace std;

int32_t main()
{
  while (true) {
    double a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    if (cin.eof()) break;

    double x = (e * c - b * f) / (a * e - b * d);
    double y = (a * f - d * c) / (a * e - b * d);
    cout << fixed;
    cout << setprecision(3) << x + 0.0 << " " << y + 0.0 << endl;
  }

  return 0;
}

Measured memory_bytes: 3204
<?php
$num =trim(fgets(STDIN));
$array = str_split($num);
$str="";

for ($i=0;$i<3;$i++){
    
    if ($array[$i]==1){
     $array[$i]=9;
    }elseif($array[$i]==9){
     $array[$i]=1;    
    }
    $str.=$array[$i];
}

echo $str;
?>

Measured memory_bytes: 4728
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  vector<int> x(n); REP(i, n) cin >> x[i];

  int ans = 1e9;
  for (int right = k-1; right <= n-1; ++right) {
    ans = min({ans, abs(x[right-k+1])+abs(x[right]-x[right-k+1]), abs(x[right])+abs(x[right-k+1]-x[right])});
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 640
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;
typedef long long ll;

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

int main(){
int K,N;
cin>>K;
cin>>N;
int A[N];
rep(i,N)cin>>A[i];
int B[N];
for(int i =1;i<N;i++)B[i]=A[i]-A[i-1];
B[0]=K-A[N-1]+A[0];
sort(B,B+N,greater<int>());
int max = B[0];
int ans = 0;

ans = K - max;
cout<<ans<<endl;

return 0;

}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
#define MAXN 2005
#define INF 1000000007


int main()
{ 
	FIN;
	
	#ifdef input
		//freopen("test1.txt", "r", stdin);
	#endif
	
	vector <int> v(5);
	forn(i,5) cin >> v[i];
	int ans = -1;
	forn(i,5) if(v[i]==0) ans=i+1;
	cout << ans << endl;
	
	
	
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int h,w; cin>>h>>w;
    string S[h];
    rep(i,0,h)cin>>S[i];
    int cntw=0;
    rep(i,0,h){
        rep(j,0,w){
            if(S[i][j]=='.')cntw++;
        }
    }
    int wayx[]={-1,0,0,1};
    int wayy[]={0,1,-1,0};
    vector<vb> is_visited(h,vb (w,false));
    queue<pii> q;
    pii s=make_pair(0,0);
    q.emplace(s);
    vector<vi> res(h,vi (w,1<<30));
    res[0][0]=1;
    int cnt=0;
    is_visited[0][0]=true;
    while(!q.empty()){
        pii t=q.front();q.pop();
        int y=t.first; int x=t.second;
        rep(way,0,4){
            int nx=x+wayx[way],ny=y+wayy[way];
            if(nx>=0&&nx<w&&ny<h&&ny>=0){
                if(is_visited[ny][nx]==false&&S[ny][nx]=='.'){
                    chmin(res[ny][nx],res[y][x]+1);
                    q.emplace(ny,nx);
                    is_visited[ny][nx]=true;
                }
            }

        }
    }
    if(res[h-1][w-1]==1<<30)cout<<-1<<endl;
    else {
        cout<<cntw-res[h-1][w-1]<<endl;
    }
    return 0;
}




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

int main(){
  int n,m;
  cin >>n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  double criteria =0;
  int s = 0;
  rep(i,n) s+= a[i];
  criteria=s/(4*m*1.0);
  if(criteria<=a[n-m]){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
ll dx[6]={-1,0,0,1,0,0},dy[6]={0,-1,0,0,1,0},dz[6]={0,0,-1,0,0,1};
ll a,b,c,n;
set<PP> s;

ll calc(ll x,ll y,ll z) {
  if(s.count(PP(x,P(y,z)))>0)return -1;
  if(x<0||x>=a||y<0||y>=b||z<0||z>=c) return -1;
  return 1;
}

int main() {
  cin >> a >> b >> c >> n;
  ll ans=(a*b+b*c+c*a)*2;
  while(n--) {
    ll xx,yy,zz;
    cin >> xx >> yy >> zz;
    if(s.count(PP(xx,P(yy,zz)))) continue;
    for(ll i=0; i<6; i++) {
      ll x=xx+dx[i],y=yy+dy[i],z=zz+dz[i];
      ans+=calc(x,y,z);
    }
    s.insert(PP(xx,P(yy,zz)));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1248
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int ans = 0;
    for(int u = 0; u < (n - 1); u++) {
      String str = s.substring(u);
      int t = str.length();
      int[] z = new int[t];
      z[0] = t;
      int i = 1;
      int j = 0;
      while(i < t) {
        while(((i + j) < t) && (str.charAt(j) == str.charAt(i + j))) j++;
        z[i] = j;
        if(j == 0) {
          i++;
          continue;
        }
        int k = 1;
        while((k < j) && ((k + z[k]) < j)) {
          z[i + k] = z[k];
          k++;
        }
        i += k;
        j -= k;
      }
      for(int y = 1; y < t; y++) {
        ans = Math.max(ans, Math.min(z[y], y));
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 60024
N = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

ts = [a, b, c, d, e]

smallest = 10 ** 15
bottle = 0
for i in range(5):
    if ts[i] < smallest:
        bottle = i
        smallest = ts[i]

total = bottle + N // smallest
if N % smallest != 0:
    total += 1
total += 4 - bottle
print(total)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++){
		cin >> p[i];
		p[i]--;
	}
	vector<int> a(N, 0);
	for (int i = 0; i < N; i++){
		a[i] += N * i;
	}
	for (int i = 0; i < N; i++){
		a[p[i]] += i;
	}
	vector<int> b(N, 0);
	for (int i = 0; i < N; i++){
		b[i] += N * (N - 1 - i);
	}
	for (int i = 0; i < N; i++){
		b[p[i]] += i;
	}
	for (int i = 0; i < N; i++){
		cout << a[i] + 1;
		if (i < N - 1){
			cout << ' ';
		}
	}
	cout << endl;
	for (int i = 0; i < N; i++){
		cout << b[i] + 1;
		if (i < N - 1){
			cout << ' ';
		}
	}
	cout << endl;
}

Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int N, K;
    cin >> N >> K;
    ll ans = pow(N/K, 3);
    if (K % 2 == 0) {
        ans += pow((2*N/K+1)/2, 3);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y;
  cin >> x >> y;
  if (x==y) cout << "Yes" << endl;
  else if ((x==4||x==6||x==9||x==11) && (y==4||y==6||y==9||y==11)) cout << "Yes" << endl;
  else if ((x==1||x==3||x==5||x==7||x==8||x==10||x==12) && (y==1||y==3||y==5||y==7||y==8||y==10||y==12)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(void)
{
	char str[101];
	int i, num, f, len;
	
	num = 0;
	
	while (scanf("%s", str) != EOF){
		f = 1;
		len = strlen(str);
		
		for (i = 0; i < len / 2; i++){
			if (str[i] != str[len - 1 - i]){
				f = 0;
				break;
			}
		}
		
		if (f == 1){
			num++;
		}
	}
	
	printf("%d\n", num);
	
	return (0);
}

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

int main(){
  int N;
  cin >> N;
  int64_t L=0;
  vector<int64_t> S(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i);
    L+=S.at(i);
  }
  int64_t Now=0;
  int64_t Dif=4200000000;
  for(int i=0; i<N; i++){
    Now+=S.at(i);
    Dif=min(Dif, abs(2*Now-L));
  }
  cout << Dif << endl;
}
    

Measured memory_bytes: 1792
H, W = map(int, input().split())
S = [input().split() for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == 'snuke':
            print(chr(65 + j) + str(i + 1))
            break
    else:
        continue
    break

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

int main() {
    ll x, ans=0, tmp, it;
    cin >> x;
    
    for(ll i=-1e3; i<1e3; i++){
	tmp = -(x-i*i*i*i*i);
	if (tmp<=0) {
	    for(ll j=0; ; j--){
		ll a=j*j*j*j*j;
		if(a ==tmp){
		    cout << i << " " <<j<< endl;
		    return 0;
		}
		if(a<tmp)
		    break;
	    }
	}
	else{
	    for(ll j=0; ; j++){
		ll a=j*j*j*j*j;
		if(a ==tmp){
		    cout << i << " " <<j<< endl;
		    return 0;
		}
		if(a>tmp)
		    break;
	    }
	}

    }
    cout << x/0 << endl;

} 




Measured memory_bytes: 3636
import sys
input = lambda: sys.stdin.readline().rstrip()

n, k = map(int, input().split())
x = [int(c) for c in input().split()]

ans = 1001001001
for i in range(n - k + 1):
    xl = x[i]
    xr = x[i + k - 1]
    ans = min(ans, min(abs(xl) + abs(xr - xl), abs(xr) + abs(xr - xl)))
print(ans)


Measured memory_bytes: 14480
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a = 0, w = 0, t = 0, r = 0;
    while(n--){
        string s;
        cin >> s;
        if(s == "AC")
            a++;
        else if(s == "WA")
            w++;
        else if(s == "TLE")
            t++;
        else r++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
    return 0; 
}

Measured memory_bytes: 3604
// AOJ 2534: Dictionary
// 2017.10.7 bal4u@uu

#include <stdio.h>
#include <string.h>

#define SIZE 26

char wd[502][12];
char mk[SIZE][SIZE];

int  q[SIZE], top, tail;
int  count[SIZE];

void push(int n) { q[tail++] = n; }
int  pop(int *n) { if (top == tail) return 0; *n = q[top++]; return 1; }
int topological_sort(int size)
{
    int i, j, k;

    memset(count, 0, sizeof(count));
    top = tail = 0;
    for (i = 0; i < size; i++) for (j = 0; j < size; j++)
        if (mk[i][j]) count[j]++;

    for (i = 0; i < size; i++) {
        if (count[i] == 0) push(i);
    }

    k = 0;
    while (pop(&i)) {
        for (j = 0; j < size; j++) if (mk[i][j])
			if (--count[j] == 0) push(j);
		k++;
    }
	return k;
}

int main()
{
	int n, i, a, b;
	char *p, *q;

	while (scanf("%d", &n) && n > 0) {
		memset(mk, 0, sizeof(mk));
		for (i = 0; i < n; i++) scanf("%s", wd[i]);
		if (n == 1) { puts("yes"); continue; }
		for (i = 1; i < n; i++) {
			q = wd[i-1], p = wd[i];
			while (*p && *q == *p) q++, p++;
			if (!*q) continue;
			if (!*p) goto NO;
			a = *p - 'a', b = *q - 'a';
			if (mk[b][a]) goto NO;
			mk[a][b] = 1;
		}

		if (topological_sort(SIZE) == SIZE) puts("yes");
		else {
NO:			puts("no");
		}
	}
	return 0;
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool used[100005];
vector<int> ki[100005];
int ans[100005];
int N;
int cnt;
void dfs(int now) {
    cnt--;
    ans[now] = cnt;
    for(int x:ki[now]) {
        if(!used[x]) {
            used[x] = true;
            dfs(x);
        }
    }
}
signed main() {
    cin >> N;
    vector<int>a(N-1),b(N-1);
    vector<int>c(N);
    for(int i = 0; i < N-1; i++) {
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        ki[a[i]].push_back(b[i]);
        ki[b[i]].push_back(a[i]);
    }
    for(int i = 0; i < N; i++) {
        cin >> c[i];
    }
    sort(c.begin(),c.end());
    int M = 0;
    for(int i = 0; i < N-1; i++) {
        M += c[i];
    }
    cnt = N;
    used[0] = true;
    dfs(0);
    cout << M << endl;
    for(int i = 0; i < N; i++) {
        if(i) cout << " ";
        cout << c[ans[i]];
    }
    cout << endl;
}


Measured memory_bytes: 6812
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

using namespace std;

long long N, P;
const long long NUM = 1e6 + 10;
vector<long long> prime(NUM, 1);
vector<long long> pa;

int main()
{
    cin >> N >> P;

    if(N == 1)
    {
        cout << P << endl;
        return 0;
    }

    long long i, j;
    double sqNUM = sqrt(NUM);
    prime[0] = 0LL;

    for (i = 2; i < sqNUM; i++)
    {
        if (prime[i] == 1) 
        {
            for (j = 2; i * j <= NUM; j++)
            {
                prime[i * j] = 0;
            }
        }
    }

    for (i = 2; i < NUM;i++)
    {
        if(prime[i] == 1)
        {
            pa.push_back(i);
        }
    }

    long long ans = 1LL;
    long long tp = P;

    for (i = 0; i < pa.size();i++)
    {
        long long p = pa[i];
        long long cnt = 0LL;
        while(tp % p == 0LL)
        {
            cnt++;
            tp /= p;
            if (cnt >= N)
            {
                ans *= p;
                cnt = 0LL;
            }
        }   
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9840
w, h, n = gets.chomp.split.map(&:to_i)
lx = 0
ux = w
ly = 0
uy = h
n.times do |_|
  x, y, a = gets.chomp.split.map(&:to_i)
  case a
  when 1
    lx = [lx, x].max
  when 2
    ux = [ux, x].min
  when 3
    ly = [ly, y].max
  when 4
    uy = [uy, y].min
  end
  break if lx >= ux || ly >= uy
end
puts [0, ux - lx].max * [0, uy - ly].max

Measured memory_bytes: 1788
n=int(input())
n_list=[input() for _ in range(n)]

m=int(input())
m_list=[input() for _ in range(m)]

max_count=0
for word in set(n_list):
    count=n_list.count(word)-m_list.count(word)
    if max_count<count:
        max_count=count
print(max_count if max_count>0 else 0)

Measured memory_bytes: 3064
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N = gete(int)
    a = [0]*(N+1)
    b, c = a[:], a[:]

    for i in range(N):
        av, bv, cv = geta(int)
        a[i+1] = max(av + b[i], av + c[i])
        b[i+1] = max(bv + c[i], bv + a[i])
        c[i+1] = max(cv + a[i], cv + b[i])

    print(max(a[-1], b[-1], c[-1]))

if __name__ == "__main__":
    main()

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int x = 0, y = 0, score = 0;
    rep(i, n-1) if (s[i] == s[i+1]) ++score;
    rep(i, n-1) if (s[i]=='R' && s[i+1]=='L') ++x;
    if ((s[0]=='L') == (s[n-1]=='R')) {
        ++y;
        if (s[0] != 'L') --x;
    }
    score += min(x, k) * 2;
    k -= x;
    if (k > 0) score += y;
    cout << score << endl;
    return 0;
}


Measured memory_bytes: 3764
use std::io::{stdout, Write};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let out = stdout();
    let mut out = out.lock();

    input!{
        n: i32,
        s: chars,
    };

    let mut r = 0;
    let mut g = 0;
    let mut b = 0;

    for c in s.iter() {
        match c {
            'R' => r += 1,
            'G' => g += 1,
            'B' => b += 1,
            _ => unreachable!(),
        }
    }

    let mut ans: u64 = r * g * b;
    for i in 0..n as usize {
        for j in (i+1)..n as usize {
            let k = 2 * i - j;
            if k < n as usize && s[k] != s[i] && s[k] != s[j] && s[j] != s[i] {
                ans -= 1;
            }
        }
    }

    writeln!(out, "{}", ans).unwrap()
}

Measured memory_bytes: 2172
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		long n = sc.nextLong();
		int count = 0;
		long s = 1;
		while(true) {
			if(s > n) break;
			s *= 2;
			count++;
			
			
		}
		System.out.println(count);
	}
	
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        int n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

Measured memory_bytes: 24316
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
using namespace std;

int main(void){
    int h, w, ans1, ans2;
    string s;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 'A'; j < 'A' + w; j++) {
            cin >> s;
            if (s == "snuke") {
                ans1 = i + 1;
                ans2 = j;
            }
        }
    }
    cout << char(ans2) << ans1;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class DP {
    static void Main(string[] args) {
        var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = st[0];
        int W = st[1];
        var w = new int[N];
        var v = new int[N];
        for (int i = 0; i < N; i++) {
            var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            w[i] = x[0];
            v[i] = x[1];
        }

        //少し大きめに配列を確保
        var dp = new long[N + 2, W + 2];

        for (int i = 0; i < N; i++) {
            dp[i, 0] = 0;
        }

        for (int j = 0; j <= W; j++) {
            if (j >= w[0]) {
                dp[0, j] = v[0];
            } else {
                dp[0, j] = 0;
            }
        }

        for (int i = 0; i < N - 1; i++) {
            for (int j = 0; j <= W; j++) {
                long kari = 0;
                if (j - w[i + 1] >= 0) {
                    kari = Math.Max(kari, dp[i, j - w[i + 1]] + v[i + 1]);
                }
                kari = Math.Max(kari, dp[i, j]);
                dp[i + 1, j] = kari;
            }
        }

        Console.WriteLine(dp[N - 1, W]);
    }
}

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

#define NOT_FOUND -1

class Array {
public:
    Array();
    ~Array();

    int length, *p;

    void print();
};

Array a[2];

int linersearch(const int);

int main() {
    

    for(int i=0; i<2; ++i) {
        cin >> a[i].length;
        a[i].p = new int[a[i].length+1];
        for(int j=0; j<a[i].length; ++j) {
            cin >> a[i].p[j];
        }         
    }

    //a[0].print();
    //a[1].print();

    int y = 0;
    for(int i=0; i<a[1].length; ++i) {
        if(linersearch(a[1].p[i]) != NOT_FOUND) ++y;
    }
    cout << y << endl;

    return 0;
}

Array::Array() {
    length = 0;
    p = nullptr;
}

Array::~Array() {
    //cout << "ARRAY DELETED" << endl;
    delete [] p;
}

void Array::print() {
    for(int i=0; i<length; ++i) {
        if(i) cout << " ";
        cout << p[i];
    }
    cout << endl;
}

int linersearch(const int key) {
    int i = 0;
    a[0].p[a[0].length] = key;
    while(a[0].p[i] != key) {
        ++i;
    }

    if(i == a[0].length)
        return (NOT_FOUND);

    return (i);
}


Measured memory_bytes: 3136
mod = 1000000000 + 7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n = int(input())
dat = [0] * 2000 # 約数として求められたある数の合計

# N! の各要素の素因数分解をする
res = 1
for i in range(1, n + 1):
    d = factorization(i)
    for j in range(len(d)):
        dat[d[j][0]] += d[j][1]

for i in range(2, n + 1):
    res *= (dat[i] + 1)
    res %= mod

print(res)

Measured memory_bytes: 9492
#include <iostream>

const int N_MAX = 1e5 + 5;

using namespace std;

int main() {
    int N, Q;
    string S;

    cin >> N >> Q >> S;

    int tot_ac[N_MAX];

    tot_ac[0] = 0;
    // cout << endl << tot_ac[0];
    for (int i = 1; i < N; i++) {
        tot_ac[i] = tot_ac[i - 1];
        if (S[i] == 'C' && S[i - 1] == 'A') {
            tot_ac[i]++;
        }
        // cout << tot_ac[i];
    }

    // cout << endl << "------ ans ---------" << endl;

    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << tot_ac[r] - tot_ac[l] << endl;
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

int main() {
  int n,a;
  cin>>n>>a;
  vector<int>x(n);
  
  rep(i,n){
    cin>>x.at(i);
  }
  vector<vector<vector<long>>> ans(n+1, vector<vector<long>>(n+1, vector<long>(2501)));
  rep(i,n+1){
    rep(j,n+1){
      rep(k,2501){
        if(i==0&&j==0&&k==0){
          ans[i][j][k]=1;
        }
        else if(i>=1&&k<x[i-1]){
          ans[i][j][k]=ans[i-1][j][k];
        }
        else if(i>=1&&j>=1&&k>=x[i-1]){
          ans[i][j][k]=ans[i-1][j][k]+ans[i-1][j-1][k-x[i-1]];
        }
        else{
          ans[i][j][k]=0;
        }
      }
    }
  }
  long to=0;
  rep2(j,1,n+1){
    to+=ans[n][j][j*a];
  }
   
  cout<<to<<endl;
}




Measured memory_bytes: 52224
/******************************************************************************

                              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>
#define ll long long
#define vr vector<ll>
#define pb push_back

using namespace std;

main ()
{
  string s;
  cin >> s;
  int n = s.length ();
  if (s[n - 1] == 's')
    {
      cout << s << "es";
    }
  else
    {
      cout << s << "s";
    }

  return 0;
}


Measured memory_bytes: 3592
while True:
    i = input()
    H,W  = map(int, i.split())

    if H == 0 and W == 0:
        break
    
    for i in range(H):
        if i%2 == 0:
            for i in range(W):
                if i%2 == 0:
                    print('#', end = '')
                else:
                    print('.', end = '')
            print()
        else:
            for i in range(W):
                if i%2 == 0:
                    print('.', end = '')
                else:
                    print('#', end = '')
            print()
    print()


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

using namespace std;

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

#define F first
#define S second

const int MAXN = 1e5 + 10;

int n, m, a[MAXN], b[MAXN], sec[MAXN];
vector<int> adj[MAXN];
int par[MAXN];
ll ans[MAXN], sumB[MAXN];
pair<ll, ll> gec[MAXN];

bool cmp(int u, int v){return a[u]-b[u] < a[v]-b[v];}

int getPar(int v){return par[v]==v? v: par[v]=getPar(par[v]);}

bool mark[MAXN];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i], a[i] = max(a[i], b[i]);
	while (m--){
		int u, v; cin >> u >> v, u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	iota(sec, sec + n, 0);
	sort(sec, sec + n, cmp);

	iota(par, par + n, 0);
	for (int i = 0; i < n; i++){
		int v = sec[i];
		mark[v] = true;
		sumB[v] = b[v];

		int tt = 0;
		for (int u:adj[v]){
			if (!mark[u]) continue;
			int pu = getPar(u);
			if (pu == v) continue;

			gec[tt++] = {ans[pu], sumB[pu]};
			par[pu] = v;
			sumB[v] += sumB[pu];
		}

		ans[v] = sumB[v] + (a[v] - b[v]);
		for (int j = 0; j < tt; j++){
			auto x = gec[j];
			ans[v] = min(ans[v], max((ll)a[v], x.F+b[v]) + (sumB[v] - b[v] - x.S));
		}
	}

	cout << ans[sec[n-1]] << "\n";
	return 0;
}


Measured memory_bytes: 9724
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let a: Vec<usize> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };

    let mut ans = 0;
    for i in 0..n {
        if i % 2 == 0 && a[i] % 2 == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2128
[n,k,s]=list(map(int,input().split()))
ans=[]
if s==10**9:
    for i in range(k):
        ans.append(s)
    for i in range(n-k):
        ans.append(1)
else:
    for i in range(k):
        ans.append(s)
    for i in range(n-k):
        ans.append(s+1)

for i in range(n):
    print(ans[i],end=" ",)
print("\n")
        

Measured memory_bytes: 8028
Scanf.scanf "%s" (fun ss ->
    let nn = String.length ss in
    let rec loop i n w s e =
        if i = nn then ((n = 0) = (s = 0) && (w = 0) = (e = 0)) else
            match ss.[i] with
            | 'N' -> loop (i + 1) (n + 1) w s e
            | 'W' -> loop (i + 1) n (w + 1) s e
            | 'S' -> loop (i + 1) n w (s + 1) e
            | 'E' -> loop (i + 1) n w s (e + 1)
            | _ -> failwith "??"
    in
    print_endline @@ if loop 0 0 0 0 0 then "Yes" else "No"
)

Measured memory_bytes: 384
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        int count=0;
        for(int x=a; x<=b;x++){
            if((c % x)== 0)count++;
            
        }
        System.out.printf("%d\n",count);
    }
}


Measured memory_bytes: 26496
#include <stdio.h>

#define MD 1000000007

int power(int a, int b) {
	int p;

	if (b == 0)
		return 1;
	p = power(a, b / 2);
	p = (long long) p * p % MD;
	if (b % 2)
		p = (long long) p * a % MD;
	return p;
}

int choose(int n, int k) {
	return k == 0 ? 1 : (long long) choose(n - 1, k - 1) * n % MD * power(k, MD - 2) % MD;
}

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

	scanf("%d%d%d", &n, &a, &b);
	ans = power(2, n) - 1 - choose(n, a) - choose(n, b);
	while (ans < 0)
		ans += MD;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 6400
#include <stdio.h>
int main(int argc, const char * argv[])
{
    int n, i, debt = 100000;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        debt *= 1.05;
        if (debt % 1000 != 0){
            debt = debt - (debt % 1000) + 1000;
        }
    }
    printf("%d\n", debt);
    return 0;
}

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

int n, res[(int)1e5], mx;
vector<pair<int, int>> adj[(int)1e5 + 1];
bool vis[(int)1e5 + 1];

void color(int vtx, int pre){
	vis[vtx] = true;
	int col = 1;
	for(auto i : adj[vtx])
		if(!vis[i.first]){
			if(col == pre) col++;
			res[i.second] = col, mx = max(mx, col);
			color(i.first, col++);
		}
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i < n; i++){
    	int a, b;
    	cin >> a >> b;
    	adj[a].push_back({b, i});
    	adj[b].push_back({a, i});
    }
    color(1, 0);
    cout << mx << "\n";
    for(int i = 1; i <= n - 1; i++) cout << res[i] << "\n";
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);


int main() {
  int64_t N, K;
  cin >> N >> K;

  if(N == 0) {
    cout << 0 << endl;
    return 0;
  }

  int64_t r = N % K;
  if(r > abs(r - K)) {
    cout << abs(r - K) << endl;
  } else {
    cout << r << endl;
  }
}


// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}


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

main() {
  int group[]{0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
  int x, y; cin >> x >> y;
  x--; y--;
  cout << ( (group[x] == group[y]) ? "Yes" : "No" ) << endl;
}


Measured memory_bytes: 256
use std::io;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    n.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn str_join<T: std::string::ToString>(s: &Vec<T>) -> String {
    s.iter()
        .map(|i| i.to_string())
        .collect::<Vec<_>>()
        .join(" ")
}

fn main() {
    loop {
        let score: Vec<i32> = read_vec();
        if score[0] == -1 && score[1] == -1 && score[2] == -1 {
            break;
        }
        let grade = match (score[0], score[1]) {
            (-1, _) | (_, -1) => "F",
            (x, y) if x + y >= 80 => "A",
            (x, y) if x + y < 80 && x + y >= 65 => "B",
            (x, y) if x + y < 65 && x + y >= 50 => "C",
            (x, y) if x + y < 50 && x + y >= 30 => {
                if score[2] >= 50 {
                    "C"
                } else {
                    "D"
                }
            }
            _ => "F",
        };
        println!("{}", grade);
    }
}



Measured memory_bytes: 5020
from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
if n == 1 and m == 0:
    print(0)
    quit()
c = [None] * n
for i in range(m):
    a,b = inpl()
    if n != 1 and a == 1 and b == 0:
        print(-1)
        quit()
    if c[a-1] == None:
        c[a-1] = b
    elif c[a-1] != b:
        print(-1)
        quit()
res = ''
for j,i in enumerate(c):
    if j == 0:
        if i == None: res += '1'
        else: res += str(i)
        continue
    if i == None:
        res += '0'
    else:
        res += str(i)
print(int(res))

Measured memory_bytes: 5164
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int r,g,b;
		r = sc.nextInt();
		g = sc.nextInt();
		b = sc.nextInt();
		
		int sum = (r*100)+(g*10)+b;
		if(sum%4==0)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

Measured memory_bytes: 21716
a = 1
b = 1
op = ''
i = 0
while op!='?':
	a,op,b = [i for i in input().split()]
	a = int(a)
	b = int(b)
	if op!='?':
		if op=='+':
			print(a+b)
		elif op=='-':
			print(a-b)
		elif op=='*':
			print(a*b)
		elif op=='/':
			print(a//b)

Measured memory_bytes: 7556
#include<iostream>
#include<memory.h>
#include<iomanip>
#include<string>
using namespace std;
int main()
{
	int l,t;
	string s,r;
	cin>>s;
	r=s;
	l=s.length();
	t=l-1;
	for(int i=0;i<l;i++)
	{
		s[i]=r[t];
		t--;
	}
	for(int i=0;i<l;i++)
	{
		if(s[i]=='b')s[i]='d';
			else if(s[i]=='d')s[i]='b';
				    else if(s[i]=='p')s[i]='q';
						    else if(s[i]=='q')s[i]='p';
	}
	if(s==r)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define db long double
#define pii pair<int,int>
#define pli pair<ll,int>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<vi>
#define lb lower_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<a.size();++i)
#define gc() getchar()
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
inline ll rd()
{
	ll x=0,w=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();
	if(c=='-')c=gc(),w=-1;while(isdigit(c))x=x*10+c-48,c=gc();return x*w;
}
int n;string S,T,ans;
vector<string>V;
string sol(string s)
{
	int m=s.size();string res="";vi p1,p2;
	rep0(i,0,m)if(s[i]=='a')p1.pb(i);else p2.pb(i);
	if(s[0]=='a')
	{
		int lst=-1;
		fore(i,p1)if(p1[i]>lst)lst=p2[i],res+="ab";
		return res;
	}
	fore(i,p1)
	{
		int x=i,y=i;string t="";
		while(true)
		{
			if(x<p1.size()&&(y==p2.size()||p1[x]<p2[y]))t+="a",x++;
			else if(y<p2.size())t+="b",y++;
			else break;
		}
		res=max(res,t);
	}
	return res;
}
int main()
{
	n=rd();cin>>S;int c=0;T="";ans="";
	rep0(i,0,n*2)
	{
		if(S[i]=='a')c++;else c--;
		T+=S[i];if(!c){V.pb(T);T="";}
	}
	fore(i,V)V[i]=sol(V[i]);
	per(i,V.size()-1,0)ans=max(ans,V[i]+ans);
	cout<<ans<<endl;return 0;
}
 

Measured memory_bytes: 384
import numpy as np
import itertools

N,M,Q=map(int,input().split())
abcd=[]

for q in range(Q):
  array=list(map(int,input().split()))
  abcd.append(array)

all = list(itertools.combinations_with_replacement(range(1,M+1), N))

MAX=[]

for al in all:
  sum=0
  for a,b,c,d in abcd:
    if al[b-1] - al[a-1] == c:
      sum += d
  MAX.append(sum)
  
print(max(MAX))

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; long long k; cin >> n >> k;
    vector<long long> p(n+1, 0);
    for (int i = 0; i < n; i++) cin >> p[i+1];
    for (int i = 0; i < n; i++) p[i+1] += p[i];
    long long ans = 0;
    for (int i = 0; i <= n-k; i++) {
        ans = max(ans, p[k+i] - p[i] + k);
    }
    if (ans % 2) cout << ans / 2 << ".5\n";
    else cout << ans / 2 << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
  int x,i,j,key,A[100],k,count = 0,flag = 1;
  scanf("%d",&x);
  
  for(i = 0; i < x; i++)
    scanf("%d",&A[i]);

  while(flag == 1)
    {
      flag = 0;
      for(j = x-1; j>0; j--)
	{	    
	  if(A[j] < A[j-1])
	    {
	      key = A[j];
	      A[j] = A[j-1];
	      A[j-1] = key;
	      flag = 1;
	      count++;
	    }	  	  
	}
    }

  for(k = 0; k < x; k++)
    {
      printf("%d",A[k]);
      if(k < x-1)
	printf(" ");
    }
  printf("\n%d\n",count);
  return 0;  
}


Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main()
{
    int n, k, x, y;
    int ans = 0;

    cin >> n >> k >> x >> y;

    if (n <= k) {
        ans += n * x;
    } else {
        ans += k * x;
        ans += (n - k) * y;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back


int MOD=1000000007;
int K,X;
int ans=0;
signed main(){
    scanf("%lld %lld",&K,&X);
    int left=max((int)-1000000,X-K+1);
    int right=min(X+K-1,(int)1000000);
    for(int i=left;i<=right;i++){
         if(i==right)printf("%lld\n",i);
         else printf("%lld ",i);
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] array = sc.next().toCharArray();
Set<String> set = new HashSet<>();


for(int i=0; i<array.length; i++){
set.add(String.valueOf(array[i]));
}

if(set.size() == array.length) System.out.println("yes");
else System.out.println("no");
    }

}


Measured memory_bytes: 24020
n, k = map(int, input().split())
x = list(map(int, input().split()))

fst = 0
las = k-1
dis = []
while las < n:
	dis.append(x[las]-x[fst] + min(abs(x[las]), abs(x[fst])))
	fst += 1
	las += 1
print(min(dis))

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

int main() {
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  ans = (ll)(n - 2) * (m - 2);
  if(m == 1) ans = n-2;
  if(n == 1)ans = m-2;
  if(n == 1&& m == 1)ans = 1;
  cout << ans << endl;
}

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

void getprime(vector<int> &prime,int n) {
    prime.push_back(3);
    prime.push_back(5);
    for(int i=11;i<=n;i+=2) {
        int k=0;
        if((((i+1)/2)%2) == 0) {
            k = 1;
        } else {
            for(int j=3;j<=sqrt(i);j+=2) {
                if(i%j==0) {
                    k = 1;
                    break;
                }
                if((((i+1)/2)%j) == 0) {
                    k = 1;
                    break;
                }
            }
        }
        if(k == 0) prime.push_back(i);
    }
}

int main(void) {
    vector<int> prime;
    getprime(prime,(int)1e5);
    
    int Q,l,r;
    cin >> Q;
    vector<int> ans(Q);
    for(int i=0;i<Q;i++) {
        cin >> l >> r;
        vector<int>::iterator itl = lower_bound(prime.begin(), prime.end(), l);
        vector<int>::iterator itr = upper_bound(itl, prime.end(), r);
//        if((*itl) == l) {
            ans[i] =  distance(itl,itr);
//        } else {
//            ans[i] = distance(itl,itr) - 1;
//        }
    }

    for(int i=0;i<Q;i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
import itertools


def main():
    N = int(input())
    A = list(map(int, input().split()))
    X = [(A[i], i) for i in range(N)]
    X.sort(reverse=True)
    l = 0
    r = N-1
    ans = 0
    dp = [[0] * (i+1) for i in range(N+1)]
    for i in range(N):
        cost, prev = X[i]
        dp[i+1][0] = dp[i][0] + cost * abs(prev - (N - 1 - i))
        dp[i+1][i+1] = dp[i][i] + cost * abs(prev - i)
        for j in range(1, i+1):
            pos1 = N - 1 - i + j
            pos2 = j - 1
            dp[i+1][j] = max(dp[i][j] + cost * abs(prev - pos1),
                             dp[i][j-1] + cost * abs(prev - pos2))
    print(max(dp[N]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 84784