akhauriyash/Code-Regression huggingface dataset:
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll n, q;
vector<ll> a;
vector<ll> sum;
vector<ll> evensum;
vector<ll> oddsum;
bool check(ll mid, ll x){
    ll diff = a[mid] - x;
    ll l = lower_bound(a.begin(), a.end(), x - diff) - a.begin();
    ll asize = mid - l + 1;
    if(n - asize <= mid) return false;
    return true;
}
ll solve(ll x){
    auto itr = upper_bound(a.begin(), a.end(), x);
    ll l = itr - a.begin() - 1;
    if(l >= n - 1){
        if(n % 2 != 0){
            return oddsum[n];
        } else {
            return evensum[n];
        }
    }
    ll left = l;
    ll right = n;
    while(abs(left - right) > 1){
        ll mid = (left + right) / 2;
        if(check(mid, x)){
            left = mid;
        } else {
            right = mid;
        }

        //cout << "LR " << left << " " << right << endl;
    }

    left++;
    ll res = 0;
    ll s = n - left;
    ll t = sum[n] - sum[left];
    res += t;
    if((max(0LL,left - s)) % 2 == 0){
        res += evensum[max(0LL,left - s)];
    } else {
        res += oddsum[max(0LL,left - s)];
    }

    //cout << left << " " << right <<" " << s << " " << t << endl;

    return res;
}
int main(void){
    cin >> n >> q;
    a.resize(n);
    sum.resize(n + 1, 0);
    evensum.resize(n + 1, 0);
    oddsum.resize(n + 1, 0);
    for(int i = 0; i < n; i++) cin >> a[i];

    
    vector<ll> X(q);
    for(int i = 0; i < q; i++){
        cin >> X[i];
    }

    for(int i = 0; i < n; i++){
        sum[i + 1] = sum[i] + a[i];
    }

    for(int i = 0; i < n; i++){
        if(i % 2 == 1){
            evensum[i + 1] = evensum[i] + a[i];
            oddsum[i + 1] = oddsum[i];
        } else {
            evensum[i + 1] = evensum[i];
            oddsum[i + 1] = oddsum[i] + a[i];
        }
    }

    // for(int i = 0; i <= n; i++){
    //     cout << i << " " << evensum[i] << " " << oddsum[i] << endl;
    // }


    for(int i = 0; i < q; i++){
        cout << solve(X[i]) << endl;
    }
}   

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

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

using namespace std;
using ll = long long;
const ll INF = 100000000;

int main() {
    int n;
    cin >> n;
    int x, y, z;
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        if (i < 6) {
            cout << 0 << endl;
            continue;
        }

        for (int j = 1; 2 < i - j * j - 2 * j; ++j) {
            for (int k = 1; k <= j; ++k) {
                for (int l = 1; l <= k; ++l) {
                    if (i == (j + k + l) * (j + k + l) - (j * k + j * l + k * l)) {
                        if(j==k && j==l && k==l){
                            res++;
                        } else if(j==k || j==l || k==l){
                            res+=3;
                        } else{
                            res+=6;
                        }
                        break;
                    }
                }
            }
        }
        cout << res << endl;
        res = 0;
    }
    return 0;
}

Measured memory_bytes: 3516
n=int(input())
dic={}
for i in range(n):
    ph=input()
    if ph not in dic:
        dic[ph]=1
    else:
        dic[ph]+=1

i=0
q1=-1
for p,q in sorted(dic.items(),key=lambda x: (-x[1],x[0])):
    if i>0 and q1!=q:
        break
    else:
        print(p)
        i+=1
        q1=q


Measured memory_bytes: 59228
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    ll q;
    cin >> q;

    while(q--) {

        ll a, b;
        cin >> a >> b;

        if (a == b || a + 1 == b) {
            cout << 2 * a - 2 << endl;
        } else {
            ll p = a * b;
            ll res = (sqrt(p));
            if(res * res == p)res--;
            if (res * (res + 1) >= p)cout << 2 * res - 2 << endl;
            else cout << 2 * res - 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  ll n; cin >> n;
  ll sum = 0;
  FOR(i,1,n){
    if(i%3==0) continue;
    if(i%5==0) continue;
    sum += i;
  }
  cout << sum << "\n";

}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int ans = S.size();
    for (int i; i < 2; i++)
    {
        int cnt = 0;
        for (int j = 0; j < S.size(); j++)
        {
            if (j % 2 != 0 ^ S[j] == char(i + '0'))
            {
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  string s;

  cin >> s;

  if (s.at(0) == s.at(2)) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    if len(s) > 3:
        for i in range(3, len(s)):
            t = s[i-3:i]
            t = collections.Counter(t)
            if len(t) == 1 or len(t) == 2:
                print(i-2, i)
                exit()
        print(-1, -1)
    elif len(s) == 3:
        s = collections.Counter(s)
        if len(s) == 1 or len(s) == 2:
            print(1, 3)
        else:
            print(-1, -1)
    elif len(s) == 2:
        s = collections.Counter(s)
        if len(s) == 1:
            print(1, 2)
        else:
            print(-1, -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 42856
#include <stdio.h>

#define MAX 100005
#define NIL -1

typedef struct {int p, l, r;} Node;

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if( T[u].p == NIL ) printf("root, ");
  else if( T[u].l == NIL ) printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0, c=T[u].l; c != NIL; i++, c=T[c].r) {
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

void rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r,p);
  if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void) {
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p = T[i].l = T[i].r = NIL;
  for(i=0;i<n;i++) {
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++) {
      scanf("%d",&c);
      if(j==0) T[v].l=c;
      else T[l].r =c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++) {
    if(T[i].p == NIL) r = i;
  }
  
  rec(r,0);
  
  for(i=0;i<n;i++) print(i);
  
  return 0;
}


Measured memory_bytes: 6408
#include "bits/stdc++.h"
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define ll long long


signed main() {
	int N; ll D; cin >> N >> D;
	vector<ll>X(N), Y(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
	}
	two_sat ts(N);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (abs(X[i] - X[j]) < D) {
				ts.add_clause(i, false, j, false);
			}
			if (abs(X[i] - Y[j]) < D) {
				ts.add_clause(i, false, j, true);
			}
			if (abs(Y[i] - X[j]) < D) {
				ts.add_clause(i, true, j, false);
			}
			if (abs(Y[i] - Y[j]) < D) {
				ts.add_clause(i, true, j, true);
			}
		}
	}
	if (!ts.satisfiable()) {
		cout << "No" << endl; return 0;
	}
	cout << "Yes" << endl;
	auto ans = ts.answer();
	for (int i = 0; i < N; i++) {
		if (ans[i])cout << X[i] << endl;
		else cout << Y[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
 
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define rep2nd(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
 
using namespace std;

int main(){
  string a,b;
  cin >> a >> b;
  if((a[0] == b[2])&&(a[1] == b[1])&&(a[2] == b[0])) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3628
s = input().split()
p = int(s[0])
q = int(s[1])
r = int(s[2])

a = p + q
b = q + r
c = r + p

mini = 0

if a < b:
    mini = a
else:
    mini = b

if c < mini:
    mini = c

print(mini)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>

int main()
{
    int i;
    char x[20];
    double yokin, interest=0.01, target, initial=100.0;

    std::cin >> x;
    yokin = initial;
    target = atof(x);
    for( i = 1 ; yokin < target ; i++){
        yokin = floor(yokin * (1.0 + interest));
    }

    std::cout << i-1 << std::endl;

    return 0;
}

Measured memory_bytes: 3688
MOD=1000000007
N,M=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
XX=[x2-x1 for x2,x1 in zip(X[1:],X[:-1])]
YY=[x2-x1 for x2,x1 in zip(Y[1:],Y[:-1])]

xs = [((i+1)*(N-i-1)*XX[i])%MOD for i in range(N-1)]
totaly=0
for j in range(M-1):
    tmp = ((j+1)*(M-j-1)*YY[j])%MOD
    totaly = (totaly+tmp)%MOD
ans = 0
for x in xs:
    tmp = (totaly*x)%MOD
    ans = (ans+tmp)%MOD

print(ans)


Measured memory_bytes: 91108
use std::io::*;
use std::str::FromStr;

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

use std::cmp::{max, min};

fn main() {
  let n = read::<i64>();
  let mut a = vec![];
  for _ in 0..n {
    a.push(read::<i64>());
  }

  a.push(0);
  a.insert(0, 0);
  let mut total = 0;

  for i in 1..n + 2 {
    let idx = i as usize;
    let pred = a[idx - 1];
    let now = a[idx];
    total += (pred - now).abs();
  }

  for i in 1..n + 1 {
    let idx = i as usize;
    let pred = a[idx - 1];
    let now = a[idx];
    let next = a[idx + 1];

    println!(
      "{}",
      total - (pred - now).abs() - (now - next).abs() + (pred - next).abs()
    );
  }
}



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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
    int n, k;
    cin >> n >> k;
    int ans = n - k + 1;
    vi P(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> P[i];
    }
    P[n] = -1;
    if (n == k) {
        cout << 1 << endl;
        return 0;
    }
    vi A(n - k + 1, 0);
    for (int i = 0; i < k - 1; i++) {
        if (P[i] < P[i + 1]) {
            A[0] += 1;
        }
    }
    for (int i = 1; i <= n - k; i++) {
        A[i] = A[i - 1];
        if (P[i - 1] < P[i]) {
            A[i] -= 1;
        }
        if (P[k + i - 2] < P[k + i - 1]) {
            A[i] += 1;
        }
    }
    int tmp = 0;
    for (int i = 0; i < n - k + 1; i++) {
        if (A[i] == k - 1) {
            tmp += 1;
        }
    }
    if (tmp > 1) {
        ans -= (tmp - 1);
    }

    set<int> s;
    for (int i = 1; i < k; i++) {
        s.insert(P[i]);
    }
    if (A[0] != k - 1) {
        if ((*s.begin()) > P[0] && (*s.rbegin()) < P[k]) {
            ans -= 1;
        }
    }
    for (int i = 1; i <= n - k; i++) {
        s.insert(P[i + k - 1]);
        s.erase(P[i]);
        if (A[i] != k - 1) {
            if ((*s.begin()) > P[i] && (*s.rbegin()) < P[k + i]) {
                ans -= 1;
            }
        }
    }
    cout << ans << endl;
}


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

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

  int strengths[3 * N];
  for (int i = 0; i < 3 * N; i++) cin >> strengths[i];

  // 5 2 8 5 1 5 → 8 5 5 5 2 1 に並び替える
  // (8, 5, ?), (5, 5, ?) のように強いカードを 2 枚ずつ消費する
  long int sum = 0;
  sort(strengths, strengths + 3 * N, greater<>());
  for (int i = 0; i < 2 * N; i++) {
    // 中央の値を加算する
    if (i % 2 == 1) sum += strengths[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 4812
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    double W,H,x,y;
    cin>>W>>H>>x>>y;
    cout<<fixed<<setprecision(10);
    if(x == W/2 && y == H/2) {
        cout<<(1.0*W*H)/2.0<<" "<<1<<endl;
    } else {
        cout<<(1.0*W*H)/2.0<<" "<<0<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int[] n=new int[31];
        int j=0;
        while(true){
            n[j]=scan.nextInt();
            if(n[j]==0) break;
            j++;
        }
        j=0;
        while(true){
            if(n[j]==0) break;
            int[] dp=new int[n[j]+1];
            dp[0]=1;
            for(int i=0;i<n[j];i++){
                if(i==0) dp[i+1]=dp[i];
                else if(i==1) dp[i+1]=dp[i]+dp[i-1];
                else dp[i+1]=dp[i]+dp[i-1]+dp[i-2];
            }
            int ans=0;
            //sSystem.out.println(":"+dp[n]+":"+n);
            if(dp[n[j]]<=3650) System.out.println(1);
            else if((dp[n[j]]%3650)==0) System.out.println(dp[n[j]]/3650);
            else System.out.println((dp[n[j]]/3650)+1);
            j++;
        }
    }
}


Measured memory_bytes: 26044
#include <iostream>
#include <queue>
#include <cstring>
#include <string>
#include <map>
using namespace std;

int sx,sy;
char mas[8][8];
queue <pair<int,int> > que;
 
void check(int x,int y){
  mas[y][x] = '0';
  for(int i=1;i<=3;i++){
    if(mas[y+i][x] == '1' && y+i < 8){
      mas[y+i][x] = '0'; que.push(make_pair(x,y+i));
    }
    if(mas[y][x+i] == '1' && x+i < 8){
      mas[y][x+i] = '0'; que.push(make_pair(x+i,y));
    }
    if(y-i >= 0 && mas[y-i][x] == '1'){
      mas[y-i][x] = '0'; que.push(make_pair(x,y-i));
    }
    if(x-i >= 0 && mas[y][x-i] == '1'){
      mas[y][x-i] = '0'; que.push(make_pair(x-i,y));
    }
  }
}
    
int main(){
  int n; string trash;
  cin >> n;
  for(int k=0;k<n;k++){
    getline(cin,trash);
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++) cin >> mas[i][j];
    }
    cin >> sx >> sy; que.push(make_pair(--sx,--sy));
    while(!que.empty()){
      pair<int,int> p = que.front(); que.pop();
      check(p.first,p.second);
    }
    cout << "Data " << k+1 << ":\n"; 
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++) cout << mas[i][j];
      cout << endl;
    }
  }
}

Measured memory_bytes: 1208
function main(arg) {
    var half_mojisuu = parseInt(arg.split("\n")[0])/2;
    var kurikaesi_ver = arg.split("\n")[1].substr(0,half_mojisuu)+arg.split("\n")[1].substr(0,half_mojisuu);
    if(kurikaesi_ver==arg.split("\n")[1]){
        console.log("Yes");
    }else{
        console.log("No");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
from collections import deque

def dfs():
    q = deque([])
    q.append(0)
    color[0] = 1
    
    while q:
        p = q.pop()
        for u in edge[p]:
            if color[u] == -1:
                color[u] = (color[p] + 1) % 2
                q.append(u)
            else:
                if color[u] == color[p]:
                    return False
    return True

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
color = [-1] * n

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


if dfs():
    B = 0
    W = 0
    for i in range(n):
        if color[i] == 1:
            B += 1
        else:
            W += 1
    print(B*W - m)
else:
    print(n * (n-1) // 2 - m)



Measured memory_bytes: 22424
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n;
long long a[N];
long long ball[N];

void run_case() {

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
      int x;
      cin >> x;
      ball[i] = x;
      a[x]++;
    }
    long long res = 0;
    for(int i = 1; i <= n ;i++){
      res += a[i] * (a[i] - 1) / 2;
    }
//    cout << res << "\n";
    for(int i = 1; i <= n; i++){
      cout << res - (a[ball[i]] - 1) << "\n";
    }
}

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

    int tests = 1;
//    cin >> tests;

    while (tests-- > 0)
        run_case();
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define LL long long
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define fd(i,a,b) for(int i=(a);i>=(b);--i)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define TASK "C - Vacation"
using namespace std;
///---------------------------------------------------
const int N = 1e5 + 5;
int n, a[N], b[N], c[N], F[5][N];
///---------------------------------------------------
void nhap(){
    cin>>n;
    fo(i,1,n) cin>>a[i]>>b[i]>>c[i];
}
///---------------------------------------------------
void solve(){
    fo(i,1,n){
        F[1][i] = max(F[2][i-1], F[3][i-1])+a[i];
        F[2][i] = max(F[1][i-1], F[3][i-1])+b[i];
        F[3][i] = max(F[1][i-1], F[2][i-1])+c[i];
    }
    cout<<max(F[1][n], max(F[2][n], F[3][n]));
}
///---------------------------------------------------
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    nhap();
    solve();
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string str;
string target = "keyence";
int main(){
	cin>>str;
	if(str == target){
		puts("YES");
		return 0;
	}
	int n = str.size();
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			//delete [i,j]
			string S = "";
			for(int k=0;k<n;k++){
				if(i<=k && k<=j){
					continue;
				}
				else S.push_back(str[k]);
			}
			if(S == target){
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
}


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

int N, ans;
string s, t;

int main() {
  cin >> N;
  cin >> s;
  cin >> t;

  ans = 2 * N;

  if (s == t) {
    cout << N << endl;
    return 0;
  }
  
  for (int i = 1; i <= N; ++i) {
    if (s.substr(N - i, i) == t.substr(0, i)) ans = 2 * N - i;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <vector>
using namespace std;

int q;
string strs[310];
int memo[1010][1010];

void initMemo(int l1, int l2) {
    for (int i = 0; i <= l1; i++) {
        memo[0][i] = 0;
    }

    for (int i = 0; i <= l2; i++) {
        memo[i][0] = 0;
    }
}

void store() {
    cin >> q;
    for (int i = 0; i < 2 * q; i++) {
        cin >> strs[i];
    }
}

// Longest Common Subsequence
void LCS(string s1, string s2) {
    int l1 = s1.length();
    int l2 = s2.length();
    initMemo(l1, l2);

    for (int i = 1; i <= l1; i++) {
        for (int j = 1; j <= l2; j++) {
            if (s1[i - 1] == s2[j - 1]) {
                memo[i][j] = memo[i - 1][j - 1] + 1;
            } else {
                memo[i][j] = max(memo[i - 1][j], memo[i][j - 1]);
            }            
        }
    }

    cout << memo[l1][l2] << endl;
}

void AllLCS() {
    for (int i = 0; i < 2 * q; i += 2) {
        LCS(strs[i], strs[i + 1]);
    }
}


int main() {
    store();
    AllLCS();

    return 0;
}


Measured memory_bytes: 7184
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, k] <- getIntList
    print $ foldl' (\x y -> (x+y) `mod` 1000000007) 0 [(n-i+1) * i + 1| i <- [k..n+1]]


Measured memory_bytes: 3796
def check(a):
  for i in range(1,len(a)):
    if a[i-1]>a[i]:
      return False
  return True
n=int(input())
a=list(map(int,input().split()))
if check(a):
  print('YES')
  exit()
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[i],a[j]=a[j],a[i]
    if check(a):
      print('YES')
      exit()
    a[i],a[j]=a[j],a[i]
print('NO')

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 10001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define int long long
const double PI = acos(-1);
typedef pair<int, int> P;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void)
{
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i)
        {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}
vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i - 1);
            if (i * i != n)
            {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main()
{
    int X;
    cin >> X;
    int A = 0;
    while (true)
    {
        int a = (int)pow(A, 5);
        int ans = a - X;
        int B = 0;
        while (true)
        {
            int b = (int)pow(B, 5);
            if (ans == b)
            {
                cout << A << " " << B << endl;
                return 0;
            }
            b *= -1;
            if (ans == b)
            {
                cout << A << " " << -B << endl;
                return 0;
            }
            if(abs(ans) < abs(b)){
                break;
            }
            B++;
        }
        A++;
    }
}

Measured memory_bytes: 4108
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int i,j;

int min (int x,int y)
{
    int k;
    if(x>y)
    {
        k=y;
    }else{
        k=x;
    }
    return k;
}

int main (void)
{
    int X,Y,A,B,C;
    int sum=0;
    scanf("%d\t%d\t%d\t%d\t%d",&A,&B,&C,&X,&Y);
    if(A/2+B/2<C)
    {
        sum=A*X+B*Y;
    }else{
        sum=min(X,Y)*2*C;
        if(min(X,Y)==X)
        {
            sum+=min(B,2*C)*(Y-X);
        }else{
            sum+=min(A,2*C)*(X-Y);
        }
    }
    printf("%d",sum);
    return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<string> S(N); cin >> S;
        vector<int> chars('z'- 'a' + 1, INF);
        rep(i, N) {
            vector<int> chars2('z'- 'a' + 1, 0);
            rep(j, S[i].size()) chars2[S[i][j] - 'a']++;
            rep(j, chars.size()) set_min(chars[j], chars2[j]);
        }
        string ret = "";
        rep(i, chars.size()) {
            int e = chars[i] >= INF ? 0 : chars[i];
            rep(j, e) {
                ret.push_back(i + 'a');
            }
        }
        cout << ret << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
w, h, x, y = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# k = int(input())
#L = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#ab = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
print(w*h/2, end=" ")
if x == w/2 and y == h/2:
    print(1)
else:
    print(0)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int n = 1e5+3;
char x[n];
int main(void){
char b;
cin>>b;
pair<char,char>x[2];
x[0]=make_pair('A','T');
x[1]=make_pair('C','G');
for(int i=0;i<2;i++)
{
    if(x[i].first==b)
        cout<<x[i].second<<endl;
    else if(x[i].second==b)
        cout<<x[i].first<<endl;
}
return 0;}


Measured memory_bytes: 3576
def main():
    N = int(input())
    S = input()
    M = [{'o': 0, 'x': 1}, {'o': 1, 'x': 0}]
    for s1, sn in [(0, 0), (0, 1), (1, 0), (1, 1)]:
        T = [s1]
        p, pp = s1, sn
        for s in S:
            pp, p = p, M[p ^ pp][s]
            T.append(p)
        if (s1, sn) == (p, pp):
            return T[:-1]
    return None

T = main()
if not T:
    print(-1)
else:
    print(''.join('S' if s == 0 else 'W' for s in T))


Measured memory_bytes: 10488
/* #region template */
#![allow(unused_imports)]
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 1024;

unsafe fn solve(io: &mut Io) {
    let n = io.ru();
    let mut a = io.c::<usize>(n);
    let r = a.len() - 1;
    let q = partition(&mut a, 0, r);

    io.wn(a[0]);
    for i in 1..q {
        io.wn(' ');
        io.wn(a[i]);
    }
    io.wn(" [");
    io.wn(a[q]);
    io.wn("]");
    for i in q + 1..n {
        io.wn(' ');
        io.wn(a[i]);
    }
    io.wn('\n');
}

fn partition(a: &mut [usize], p: usize, r: usize) -> usize {
    let x = a[r];
    let mut i = p;
    for j in p..r {
        if a[j] <= x {
            a.swap(i, j);
            i += 1;
        }
    }
    a.swap(i, r);
    i
}



Measured memory_bytes: 5036
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int N;
long long dp[100010];
int h[100010];

int main(){
    cin >> N;
    for(int i = 0;i < 100010;i++){
        dp[i] = 1LL << 60;
    }   
    for(int i = 0;i < N;i++){
        cin >> h[i];
    }
    dp[0] = 0;
    for(int i = 0;i <= N;i++){
        chmin(dp[i + 1],dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2],dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[N - 1] << '\n';
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int cnt[100001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		a--;
		cnt[a]++;
	}
	int r1=0,r2=0;
	for(int i=0;i<100000;i++){
		if(cnt[i]>0 && cnt[i]%2==1){
			r1++;
		}
		if(cnt[i]>0 && cnt[i]%2==0){
			r2++;
		}
	}
	printf("%d\n",r1+(r2/2)*2);
	return 0;
}


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

int main()
{
  long long n,m;
  cin>>n>>m;
  long long  down=0;
  if(n>=2 && m>=2)down+=(n-2)*(m-2);
  if(n==1 && m>=2)down+=m-2;
  if(m==1 && n>=2)down+=n-2;
  if((n*m)==1)down=1;
  cout<<down<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

class UnionFind{
  public:
    vector<int> par;
    vector<int> rank;
    vector<int> cnt;
    UnionFind(int N): par(N), rank(N), cnt(N){
      for(int i = 0; i < N; i++){
        par[i] = i;
        rank[i] = 0;
        cnt[i] = 1;
      }
    }
    void init(int N){
      par.resize(N); rank.resize(N); cnt.resize(N);
      for(int i = 0; i < N; i++){
        par[i] = i;
        rank[i] = 0;
        cnt[i] = 1;
      }
    }
    int Findroot(int x){
      if(par[x] == x)return x;
      return par[x] = Findroot(par[x]);
    }
    void merge(int x, int y){
      x = Findroot(x);
      y = Findroot(y);
      if(x == y) return;
      if(rank[x] < rank[y]){
        par[x] = y;
        cnt[y] += cnt[x];
      }
      else{
        par[y] = x;
        cnt[x] += cnt[y];
        if(rank[x] == rank[y]) rank[x]++;
      }
    }
    bool is_same(int x, int y){
      return Findroot(x) == Findroot(y);
    }
    int size(int x){
      return cnt[Findroot(x)];
    }
};
int main()
{
  int n, m, ans = 0; cin >> n >> m;
  vector<pair<int, int>> v(m);
  UnionFind uf(n);
  rep(i, m){
    int a, b; cin >> a >> b;
    v[i] = make_pair(a, b);
  }
  for(int i = 0; i < m; i++){
    uf.init(n);
    for(int j = 0; j < m; j++){
      if(i == j)continue;
      uf.merge(v[j].first-1, v[j].second-1);
    }
    if(uf.size(0) < n)ans++;
  }
  cout << ans << endl;
  system("pause");
}



Measured memory_bytes: 504
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int main()
{
	int n=gi();
	string a,b;cin>>a>>b;
	if (a+b>b+a) swap(a,b);
	int A=a.size(),B=b.size(),lcm=A*B/__gcd(A,B);
	//for (int i=n/lcm*(lcm/A);i;i--) cout<<a;n%=lcm;
	//while (n%B) cout<<a,n-=A;
	//for (n/=B;n--;) cout<<b;
	string out;
	while (n%A) out+=b,n-=B;
	for (n/=A;n--;) cout<<a;
	cout<<out;
	return 0;
}


Measured memory_bytes: 1544
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  if(N%2 != 0){
    cout << "No" << endl;
    return 0;
  }
  string s;
  cin >> s;
  if(s.substr(0,N/2) == s.substr(N/2,N/2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
char s[33],vis[333];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(n!=26)
	{
		for(register int i=1;i<=n;++i)vis[s[i]]=1;
		for(register int i='a';i<='z';++i)
			if(!vis[i]){s[n+1]=i;break;}
		puts(s+1);
		return 0;
	}
	else
	{
		int pl=0;
		for(register int i=25;i>=1;--i)
			if(s[i]<s[i+1]){pl=i;break;}
		if(pl==0)puts("-1"),exit(0);
		for(register int i=pl+1;i<=n;++i)vis[s[i]]=1;
		for(register int i=s[pl]+1;i<='z';++i)
			if(vis[i]){s[pl]=i,s[pl+1]=0;break;}
		puts(s+1);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  char ch;
  int data[4] = {0};
  for (int i = 0; i < N; i++)
  {
    cin >> ch;
    if(ch=='P'){
      data[0]++;
    }else if(ch=='W'){
      data[1]++;
    }else if(ch=='G'){
      data[2]++;
    }else if(ch=='Y'){
      data[3]++;
    }
  }
  int flag = 0;
  for (int i = 0; i < 4; i++)
  {
    if(data[i]==0){
      cout << "Three" << endl;
      flag = 1;
      break;
    }
  }
  if(flag==0){
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	int n;
	cin >> n;
	int k;
	cin >> k;
	bitset<28> mask(0);
	Rep(i, k) {
		int b;
		cin >> b;
		mask |= 1 << b;
	}
	BitRep(i, n) {
		bitset<28> bit(i), x;
		x = bit | mask;
		if (x == mask) {
			cout << i << ":";
			Rep(j, n) {
				if (bit[j]) cout << " " << j;
			}
			cout << endl;
		}
	}
	return 0;
}


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

int main() {
  int n;
  int top, front, eside, temp, sum;
  string str;
  
  while(cin>>n, n) {
    // ティツヲツ凝」ツ?暗」ツつ凝・ツ?エテ」ツ?ョテァツ環カテヲツ?凝」ツつ津、ツソツ敕ヲツ個?」ツ?凖」ツつ凝」ツ?禿」ツ?ィテ」ツ?ァテ」ツつオテ」ツつ、テ」ツつウテ」ツδュテ」ツ?ョテ」ツ?凖」ツ?ケテ」ツ?ヲテ」ツ?ョテゥツ敖「テ」ツ?ョテァツ環カテヲツ?凝」ツ?古、ツソツ敕ヲツ個?」ツ?陛」ツつ古」ツつ?
    top = 1, front = 2, eside = 3; sum = top;
    for(int i = 0; i < n; i++) {
      cin >> str;
      if(str[0] == 'N') temp = top, top = front, front = 7-temp;
      if(str[0] == 'E') temp = eside, eside = top, top = 7-temp;
      if(str[0] == 'W') temp = top, top = eside, eside = 7-temp;
      if(str[0] == 'S') temp = front, front = top, top = 7-temp;
      if(str[0] == 'R') temp = front, front = eside, eside = 7-temp;
      if(str[0] == 'L') temp = eside, eside = front, front = 7-temp;
      sum += top;
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 1200
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, A, B = map(int, input().split())

if (A - B)%2 == 0:
    print((B-A)//2)
else:
    if A-1 < N-B:
        print(min(B-1, (B-A-1)//2+A))
    else:
        print(min(N-A, (B-A-1)//2+N-B+1))

Measured memory_bytes: 3060
N, Ma, Mb = map(int, input().split())
L = []
sum_a = 0
sum_b = 0
for _ in range(N):
    a, b, c = map(int, input().split())
    sum_a += a
    sum_b += b
    L.append((a, b, c))

inf = 10 ** 9 + 7
dp = [[[inf] * (sum_b + 1) for _ in range(sum_a + 1)] for _ in range(N + 1)]

dp[0][0][0] = 0
for i in range(N):
    for a in range(sum_a + 1):
        for b in range(sum_b + 1):
            if 0 <= a - L[i][0] and 0 <= b - L[i][1]:
                # print(a, b, L[i])
                dp[i + 1][a][b] = min(dp[i][a - L[i][0]]
                                      [b - L[i][1]] + L[i][2], dp[i][a][b])
            else:
                dp[i + 1][a][b] = dp[i][a][b]

min_cost = inf
for a in range(sum_a + 1):
    for b in range(sum_b + 1):
        if a * Mb == b * Ma and dp[N][a][b] != 0:
            # print(a, b, dp[N][a][b])
            min_cost = min(dp[N][a][b], min_cost)

print(min_cost if min_cost != inf else -1)


Measured memory_bytes: 30712
from itertools import groupby, accumulate, product, permutations, combinations
import numpy as np
N, M = map(int, input().split())
adj = np.zeros((N,N),np.int64)
for i in range(M):
  a,b = map(lambda x:int(x)-1, input().split())
  adj[a,b] = 1
  adj[b,a] = 1
ans = 0
for per in permutations(range(1,N),N-1):
  if adj[0,per[0]]==0:
    continue
  for i in range(N-2):
    if adj[per[i],per[i+1]]==0:
      break
  else:
    ans += 1
print(ans)

Measured memory_bytes: 26812
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll comb(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	unsigned long long num[60] = {0}, v, ans = 0;
	int n;
	cin >> n;
	vector<unsigned long long> a(n);
	rep(i, 0, n) {
		cin >> v;
		a[i] = v;
		rep(i2, 0, 60) {
			if(v >> i2 & 1)num[i2]++;
		}
	}
	rep(i, 0, n) {
		rep(i2, 0, 60) {
			if (a[i] >> i2 & 1)ans += (n - num[i2]) * mpower(2, i2) % mod;
			else ans += (num[i2]) * mpower(2, i2) % mod;
			ans %= mod;
		}
	}
	printf("%llu\n", (ans * mpower(2, mod - 2)) % mod);
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
typedef long double ld;
using namespace std;

vvl G = vv(1001, 0, 0, ll);
set<int> s;
std::vector<int> par(1001, -1);
vvi ans = vv(0, 0, 0, int);
void dfs(int from, int now, int prime){
  s.insert(now);
  par[now] = from;
  for(int i=0;i<G[now].size();i++)  if(G[now][i]!=prime && s.find(G[now][i])!=s.end()) return;
  for(int i=0;i<G[now].size();i++){
    if(G[now][i]==prime){
      ll tmp = now;
      ans.push_back(std::vector<int> {});
      ans[ans.size()-1].push_back(tmp);
      while(par[tmp]!=-1){
        ans[ans.size()-1].push_back(par[tmp]);
        tmp = par[tmp];
      }
      return ;
      //std::cout << ans.size() << '\n';
      //for(int i=0;i<ans[i].size();i++) std::cout << ans[ans.size()-1][i] << '\n';
    }
  }
  for(int i=0;i<G[now].size();i++) {
    dfs(now, G[now][i], prime);
  }
  s.erase(now);
}
int main(int argc, char const *argv[]) {
  ll N, M, a, b;
  std::cin >> N >> M;
  for(int i=0;i<M;i++){
    std::cin >> a >> b;
    G[a].push_back(b);
  }
  for(int i=1;i<=N;i++){
    s.clear();
    dfs(-1, i, i);
  }
  ll m = 1000000007, idx = -1;
  for(int i=0;i<ans.size();i++){
    if(ans[i].size()<m) m = ans[i].size(), idx = i;
  }
  if(idx==-1){
    std::cout << -1 << '\n';
    return 0;
  }
  std::cout << m << '\n';
  for(int i=0;i<ans[idx].size();i++) std::cout << ans[idx][i] << '\n';
  return 0;
}


Measured memory_bytes: 4480
d = gets.to_i
c = gets.split(' ').map{|s| s.to_i}
a = []
d.times do |i|
  a[i] = gets.split(' ').map{|s| s.to_i}
end
k = []
d.times do |i|
  k[i] = gets.to_i
end

l = []
26.times{|i| l[i] = 0}

total = 0
d.times do |i|
  l[k[i]-1] = i + 1
  loss = 0
  l.each_with_index{|le, li| loss += (i  - le + 1) * c[li]}
    
  puts total += a[i][k[i]-1] - loss
 
end

Measured memory_bytes: 14248
#include <iostream>
#include <cmath>
using namespace std;
#define EPS (1e-10)

// n := クリスタルの個数 
int n;
// (hx,hy) := 勇者の初期位置
// (dx,dy) := 魔王の位置
int hx, hy, dx ,dy;
// (cx[i],cy[i]) := i 番目のクリスタルの位置
int cx[21], cy[21];
// done[i] := i 番目のクリスタルを回収したかどうか
bool done[21];
// 答え
bool ans;

// 2 点間の距離
double dist(double x1, double y1, double x2, double y2){
    return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
}


// 枝刈り探索
// t := 経過時間[s], (x,y) := 勇者の位置
void solve(double t, int x, int y){
    if( ans ) return ;
    
    // cnt := 現在回収したクリスタルの個数
    int cnt=0;
    for(int i=0 ; i < n ; i++ ){
        if( done[i] ) cnt++;
    }
    // n 個のクリスタルを回収したとき
    if( cnt == n ){
        ans = true;
        return;
    }
    
    // 回収できないクリスタルがあるか調べる
    for(int i=0 ; i < n ; i++ ){
        if( done[i] ) continue;
		
        double next_time = t + dist( x , y , cx[i] , cy[i] );
        // すでに回収できないクリスタルがあったら探索打ち切り
        if ( dist( dx , dy , cx[i] , cy[i] ) < next_time + EPS ){ 
            return; 
        }
    }
    for(int i=0 ; i < n ; i++ ){
        if( done[i] ) continue;
 
        double next_time = t + dist( x , y , cx[i] , cy[i] );
        done[i] = true;
        solve( next_time , cx[i] , cy[i] );
        done[i] = false;
    }
}
 
int main(){
    while( cin >> n >> hx >> hy >> dx >> dy , (n || hx || hy || dx || dy) ){
    	// (cx[i],cy[i]) := i 番目のクリスタルの位置
        for(int i=0 ; i < n ; i++ ){
            cin >> cx[i] >> cy[i];
        }
        
        // 初期化
        for(int i=0 ; i < 21 ; i++ ){
            done[i] = false;
        }
        
        ans = false;
        solve( 0.0 , hx , hy );
        if( ans ){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 868