akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	int pA, pB, pC;

	pA = pow(A, 2); pB = pow(B, 2); pC = pow(C, 2);
	if(pA + pB == pC)
	{
		cout << A * B / 2 << endl;
	}
	else if (pA + pC == pB)
	{
		cout << A * C / 2 << endl;
	}
	else
	{
		cout << B * C / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

evens = Counter(A[::2])
odds = Counter(A[1::2])
evens[0] = 0 # 番兵
odds[0] = 0

e1, e2 = evens.most_common(2)
o1, o2 = odds.most_common(2)

if e1[0] != o1[0]:
  print(N - (e1[1] + o1[1]))
else:
  print(N - max(e1[1] + o2[1], e2[1] + o1[1]))

Measured memory_bytes: 18656
def primelist(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def factorization(n):
    plist = primelist(int(n**0.5))
    factor = []
    for p in plist:
        k = 0
        while n%p==0:
            k+=1
            n//=p
        if k>0:
            factor.append((p,k))
        if n==1:
            break
    if n!=1:
        factor.append((n,1))

    return factor

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
  
n = int(input())

divs = divisors(n)
t = len(divs)
if t==2:
  print(divs[-1]-1)
elif t%2==0:
  print(divs[t//2-1]+divs[t//2]-2)
else:
  print(divs[t//2]*2-2)

Measured memory_bytes: 3292
n = int(input())
H = [0] + list(map(int, input().split())) + [0]
def f(b):
    global H
    H[b] -= 1
    a = b - 1
    c = b + 1
    while 0 < a and H[a] != 0:
        H[a] -= 1
        a -= 1
    while c <= n and H[c] != 0:
        H[c] -= 1
        c += 1
ans = 0
for i in range(1, n + 1):
    while H[i] != 0:
        f(i)
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
const int MAXN = 2e3 + 10;
int N; ll X;
ll A[MAXN];
ll B[MAXN][MAXN];
ll ans = 1ll << 60;

int main() {
	register int i, j;
	scanf("%d%lld", &N, &X);
	for(i = 1; i <= N; ++i)
		scanf("%lld", A + i);
	for(i = 1; i <= N; ++i) {
		B[i][0] = A[i];
		for(j = 1; j < N; ++j) {
			int pos = i - j;
			if(pos <= 0) pos = N - abs(pos);
			B[i][j] = min(B[i][j - 1], A[pos]);
		}
	}
	for(j = 0; j < N; ++j) {
		ll res = 0;
		for(i = 1; i <= N; ++i)
			res += B[i][j];
		ans = min(ans, res + X * j);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if((a==5||a==7)&&(b==5||b==7)&&(c==5||c==7)&&(a+b+c==17)){
		cout << "YES" << endl;	
	}
	else{
		cout << "NO" << endl;
	}	
	return 0;
}

Measured memory_bytes: 256
n = input()
k = int(input())
dp = [[[0,0,0,0],[0,0,0,0]] for i in range(len(n))] #dp[p][0][count]は、p桁目まではnより小さいことが確定している
#countは「0以外の桁」の登場回数、あくまで各桁に登場したt「以下」の数字かどうかを判定する。dp[p][1]は「〜と同じ」
dp[0][0][0] = 0
dp[0][0][1] = 1
dp[0][1][0] = 1
dp[0][1][1] = int(n[0])-1
for i in range(1,len(str(n))):
    if n[i] != '0':
        dp[i][0][0] = 0 #遷移前に同じで、遷移後に0でないものが0個かつ遷移前と同じ遷移はありえない
        dp[i][0][1] = dp[i-1][0][0] #ぴったりの数字(0でない)が入ればOK 下二つも同じ
        dp[i][0][2] = dp[i-1][0][1]
        dp[i][0][3] = dp[i-1][0][2]
        dp[i][1][0] = dp[i-1][1][0] #0を入れればOK
        dp[i][1][1] = dp[i-1][0][0]*(max(0,int(n[i])-1))+dp[i-1][0][1]+dp[i-1][1][1]+dp[i-1][1][0]*9
        dp[i][1][2] = dp[i-1][0][1]*(max(0,int(n[i])-1))+dp[i-1][0][2]+dp[i-1][1][2]+dp[i-1][1][1]*9
        dp[i][1][3] = dp[i-1][0][2]*(max(0,int(n[i])-1))+dp[i-1][0][3]+dp[i-1][1][3]+dp[i-1][1][2]*9
    else:
        dp[i][0][0] = dp[i-1][0][0]
        dp[i][0][1] = dp[i-1][0][1]
        dp[i][0][2] = dp[i-1][0][2]
        dp[i][0][3] = dp[i-1][0][3]
        dp[i][1][0] = dp[i-1][1][0] #0を入れればOK
        dp[i][1][1] = dp[i-1][1][0]*9+dp[i-1][1][1]
        dp[i][1][2] = dp[i-1][1][1]*9+dp[i-1][1][2]
        dp[i][1][3] = dp[i-1][1][2]*9+dp[i-1][1][3]
print(dp[len(n)-1][0][k]+dp[len(n)-1][1][k])

Measured memory_bytes: 3192
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
# print(len(make_divisors(N)))
answer = 0
for i in range(1, N+1):
    # print(len(make_divisors(i)))
    if len(make_divisors(i)) == 8 and i % 2 != 0:
        answer += 1

print(answer)

Measured memory_bytes: 3064
#include <cstdio>
int main (){
	int W, H, N, col[100] = {0}, row[100] = {0}, cnt_col = 0, cnt_row = 0;
	int x, y, a;
	scanf("%d %d %d", &W, &H, &N);
	for (int i = 0; i < N; i++){
		scanf("%d %d %d", &x, &y, &a);
		if (a == 1){
			for (int j = 0; j < x; j++)
				col[j] = true;
		} else if (a == 2){
			for (int j = x; j < W; j++)
				col[j] = true;
		} else if (a == 3){
			for (int j = 0; j < y; j++)
				row[j] = true;
		} else if (a == 4){
			for (int j = y; j < H; j++)
				row[j] = true;
		}
	}
	for (int i = 0; i < W; i++)
		cnt_col += col[i];
	for (int i = 0; i < H; i++)
		cnt_row += row[i];
	printf("%d\n", W * H - cnt_col * H - cnt_row * W + cnt_col * cnt_row);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll N,M;
  cin>>N>>M;
  cout<<N*(N-1)/2+M*(M-1)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  string s;
  cin>>N>>s;
  int ans=0;
  for(int i=0;i<1000;i++){
    string t;
    int x=i;
    for(int j=0;j<3;j++){
      t+=(x%10+'0');
      x/=10;
    }
    int v=0;
    for(int j=0;j<N;j++){
      if(s[j]==t[v]){
        v++;
      if(v==3){break;}
      }
    }
    if(v==3){ans++;}
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3696
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn sum(mut n: usize) -> usize {
    let mut res = 0;
    while n > 0 {
        res += n % 10;
        n /= 10;
    }
    res
}

fn main() {
    let n: usize;
    input!(n);
    if n % sum(n) == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
class P{
	P(String n,int t){
		this.n=n;
		this.t=t;
	}
	public String n;
	public int t,e;
}
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String l[];
		l=br.readLine().split(" ");
		int n=Integer.parseInt(l[0]);
		int q=Integer.parseInt(l[1]);
		LinkedList<P> p=new LinkedList<P>();
		P[] e=new P[n];
		int c=0;
		for(int i=0;i<n;i++){
			l=br.readLine().split(" ");
			p.offer(new P(l[0],Integer.parseInt(l[1])));
		}
		int s=0;
		for(;;){
			P t=p.poll();
			if(t==null)break;
			int d=Math.min(t.t,q);
			s+=d;
			t.t-=d;
			if(t.t==0){
				t.e=s;
				e[c++]=t;
			}else{
				p.add(t);
			}
		}
		for(int i=0;i<n;i++)System.out.println(e[i].n+' '+e[i].e);
	}
}

Measured memory_bytes: 67696
#include <stdio.h>

int main(void)
{
	int n;	//?????±?????¶??°
	scanf("%d", &n);
	
	int b, f, r, v;	//?£???????????????°?????¨?±????????????\?±??????°
	int room[4][3][10];//4?£????3?????????1????????¢10??¨?±??????¨?±???????????????¨?????????
	
	for(int i = 0; i < 4; i++){	//????¬??????????????????????
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 10; k++){
				room[i][j][k] = 0;
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		room[b-1][f-1][r-1] += v;
	}
	
	for(int i = 0; i < 4; i++){
		if(i > 0){
			printf("####################\n");
		}
		
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 10; k++){
				printf(" %d", room[i][j][k]);
			}
			printf("\n");
		}
	}	
}

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

int main(void){
    #define N 100
    // Your code here!
    char w[11] = {};
    char buf[1001];
    int cnt = 0;
    char ew[] = "END_OF_TEXT";
    int i;
    
    scanf( "%s" , w );
    
    
    while(1){
        scanf( "%s" , buf );
        if( strcmp(buf,ew) == 0 ){
            break;
        }      
        
        for( i = 0 ; buf[i] != '\0' ; i++ ){
            if( 65 <= buf[i] && buf[i] <= 90 ){
                buf[i] += 32;
            }
        }
        
        if( strcmp(buf,w) == 0 ){
            cnt++;
        }
    }
    
    printf( "%d\n" , cnt );
}



Measured memory_bytes: 2144
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int n;
vector<ll> a;

ll dp[200005][2][3];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    a.resize(n);
    for(auto &it : a) {
        cin >> it;
    }
    for(int i = 0; i < n + 1; i++) {
        for(int j = 0; j < 2; j++) {
            for(int k = 0; k < 3; k++) {
                dp[i][j][k] = -LLINF;
            }
        }
    }
    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 2; j++) {
            for(int k = 0; k < 3; k++) {
                // えらぶ
                if(j == 0) {
                    chmax(dp[i + 1][1][k], dp[i][j][k] + a[i]);
                }
                // えらばない
                if(j == 0 && k < 2) {
                    chmax(dp[i + 1][0][k + 1], dp[i][j][k]);
                } else if(j == 1) {
                    chmax(dp[i + 1][0][k], dp[i][j][k]);
                }
            }
        }
    }
    if(n % 2) {
        cout << max(dp[n][1][2], dp[n][0][1]) << endl;
    } else {
        cout << max(dp[n][0][0], dp[n][1][1]) << endl;
    }
}


Measured memory_bytes: 14260
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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() {
  string S; cin >> S;
  if (S[0]=='R' && S[1]=='R' && S[2]=='R') cout << 3 << endl;
  if (S[0]=='R' && S[1]=='R' && S[2]=='S') cout << 2 << endl;
  if (S[0]=='R' && S[1]=='S' && S[2]=='R') cout << 1 << endl;
  if (S[0]=='R' && S[1]=='S' && S[2]=='S') cout << 1 << endl;
  if (S[0]=='S' && S[1]=='R' && S[2]=='R') cout << 2 << endl;
  if (S[0]=='S' && S[1]=='R' && S[2]=='S') cout << 1 << endl;
  if (S[0]=='S' && S[1]=='S' && S[2]=='R') cout << 1 << endl;
  if (S[0]=='S' && S[1]=='S' && S[2]=='S') cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 3196
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;

int main(){
    ll N,K;cin>>N>>K;
    vector<ll> max_d(N,0);//種類iごとのおいしさdの最大
    vector<p> sushi;
    REP(i,N){
        ll t,d;cin>>t>>d;//dは美味しさ,tはネタ
        t--;//0 origin
        sushi.push_back(p(d,t));
        max_d[t] = max(max_d[t],d);
    }
    sort(sushi.begin(),sushi.end(),greater<p>());
    priority_queue <p,vector<p>,greater<p>> prq_s;//昇順にする popするときに最小のものとなる
    vector<ll> type_cnt(N,0);//type iの数
    ll types = 0;
    ll sum = 0;

    //初期集合の作成
    REP(i,K){
        if(type_cnt[sushi[i].second]==0 and  max_d[sushi[i].second]==sushi[i].first){
            //こいつらはpopされない
            //二個目ほんとに必要？
            types++;
            type_cnt[sushi[i].second]++;
        }else{
            prq_s.push(sushi[i]);
        }
        sum += sushi[i].first;
    }
    ll ans = types * types + sum;

    //dの最大値が大きい順に種類を追加していく
    vector<p> waiting;
    REP(i,N){
        if(max_d[i]!=0){
            waiting.push_back(p(max_d[i],i));
        }
    }
    sort(waiting.begin(),waiting.end(),greater<p>());

    for(p tmp : waiting){
       if (type_cnt[tmp.second]) continue;
       if (prq_s.empty()) break; 
       sum -= prq_s.top().first;
       sum += tmp.first;
       types++;
       prq_s.pop();
       ans = max(ans,types*types+sum);
    }
    cout<<ans<<endl;
}

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

int main() {
  int n, i, c=0;
  int a[200] = { 0 };
  int result = 100;

  cin >> n;

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

  for(i = 0; i < n; i++)
  {
    c = 0;
    while(a[i] % 2 == 0)
    {
      a[i] /= 2;
      c++;
    }

    if(result > c)
      result = c;
  }

  cout << result << endl;
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  int k=0;
  int count=1;
  rep(i,n){
    int a; cin>>a;
    if(a==count){
      k++;
      count++;
    }
  }
  (k==0)?cout<<-1<<endl:cout<<n-k<<endl;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k,a=0; cin>>n>>k;
  vector<int> p(n); for(int i=0; i<n; i++) cin>>p[i];
  sort(p.begin(),p.end());
  for(int i=0; i<k; i++) a+=p[i];
  cout<<a;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>

using namespace std;

#define A_MAX 10000
#define N_MAX 2000000
int A[N_MAX];
int B[N_MAX];

void countingSort(int A[],int B[],int k,int n) {

	int *C = new int[k+1];

	for (int i = 0; i <= k; i++) {
		C[i] = 0;
	}

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

	for (int i = 1; i <= k; i++) {
		C[i] += C[i - 1];
	}

	for (int i = n; i >= 1; i--){
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}

	delete[] C;

}

int main(void)
{
	int n;

	
	cin >> n;

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

	countingSort(A, B, A_MAX, n);

	for (int i = 1; i <= n; i++) {
		if (i>1)putchar(' ');
		cout << B[i];
	}

	putchar('\n');

}

Measured memory_bytes: 18756
ss = input()
n = len(ss)
ans = [0] * n
st = 0
flag = False
for i, s in enumerate(ss):
    if s == "L" and not flag:
        mi = i
        flag = True
    elif s == "R" and flag:
        ans[mi] = (mi - st) // 2 + (i - mi - 1) // 2 + 1
        ans[mi - 1] = (mi - 1 - st) // 2 + (i - mi) // 2 + 1
        st = i
        flag = False
i = n
ans[mi] = (mi - st) // 2 + (i - mi - 1) // 2 + 1
ans[mi - 1] = (mi - 1 - st) // 2 + (i - mi) // 2 + 1

print(*ans)


Measured memory_bytes: 7668
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int N,C; cin >> N >> C;
  vvi D(C,vi(C));
  rep(i, C) rep(j, C) cin >> D[i][j];

  vvi c(N, vi(N));
  rep(i,N) rep(j,N){
    cin >> c[i][j];
    c[i][j]--;
  }

  ll ans = INF;
  map<int,int> G1;
  map<int,int> G2;
  map<int,int> G3;
  rep(i,N) rep(j,N) {
    if((i+j)%3 == 0) G1[c[i][j]]++;
    if((i+j)%3 == 1) G2[c[i][j]]++;
    if((i+j)%3 == 2) G3[c[i][j]]++;
  }


  rep(i,C) rep(j,C) {
    if(i == j) continue;
    rep(k,C) {
      if(i == k || j == k) continue;
      // 色をi,j,kの三色で統一した場合
      ll sum = 0;
      for(auto g : G1){
        sum += D[g.first][i] * g.second;
      }
      for(auto g : G2){
        sum += D[g.first][j] * g.second;
      }
      for(auto g : G3){
        sum += D[g.first][k] * g.second;
      }
      chmin(ans,sum);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
#define double long double
const int INF = 1e18, MOD = 1e9 + 7;

signed main() {
    int n;
    cin>>n;
    int a[222222];
    for (int i = 1; i <= n; i++) {
        cin>>a[i];
    }
    int ans[222222] = {};
    for (int i = n; i > 0; i--) {
        for (int j = i * 2; j <= n; j += i) {
            a[i] += ans[j];
        }
        if (a[i] % 2) {
            ans[i] = 1;
        }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (ans[i]) cnt++;
    }
    cout<<cnt<<endl;
    for (int i = 1; i <= n; i++) {
        if (ans[i]) cout<<i<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 4480
A, B = list(map(int, input().split()))

def calc_num(N):
  if N==0:
    return 0
  if N % 4 == 1:
    return 1
  if N % 4 == 2:
    return N ^ 1
  if N % 4 == 3:
    return 0
  return N ^ 0

A = calc_num(A-1)
B = calc_num(B)

print(A^B)


Measured memory_bytes: 2940
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)
    
    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac


X, Y = map(int, input().split())
# 後の、n, mの大小を一定にするため
if X > Y:
    X, Y = Y, X
dist = X + Y
   
if dist % 3 != 0:
    print(0)
else:
    # (+1,+2) の移動の回数を n、(+2,+1) の移動の回数を m とする)
    # total = n + m
    # 以下の式は、2n + m = X, n + 2m = Y の連立方程式を解いた結果
    total = int((X+Y) / 3)
    n = X - total
    
    # n < 0 もしくは m < 0 の場合、たどり着けない
    # Y > X なので、m > n
    # n < 0 → 2X - Y < 0
    if Y > 2*X:
        print(0)
    else:
        MOD = 10**9 + 7

        fac, ifac = make_tables(MOD, total)
        ans = cmb(total, n, MOD, fac, ifac)
        print(ans)

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

const int maxn = 1e5+5;
int N, d[maxn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(d,d+N);
    int ans = d[N/2] - d[N/2-1];
    cout << ans << '\n';
}



Measured memory_bytes: 640
#include <iostream>
#include <complex>
#include <cstdio>

using namespace std;

#define X real()
#define Y imag()

const double EPS = 1e-8;

typedef complex<double> Point;

bool operator< (const Point& p1, const Point& p2) {
  return p1.X != p2.X ? p1.X < p2.X : p1.Y < p2.Y;
}

double dot(const Point& p1, const Point& p2) {
  return (conj(p1)*p2).X;
}

typedef Point Vector;

int main() {
  Point p0, p1;
  double x, y;
  
  cin >> x >> y; p0 = Point(x, y);
  cin >> x >> y; p1 = Point(x, y);
  
  Vector v0 = p1 - p0;
  
  int q;
  cin >> q;
  while(q--) {
	cin >> x >> y;
	Vector v1 = Point(x, y) - p0;
	Point ans = p0 + dot(v0, v1) * v0 / norm(v0);
	printf("%.9lf %.9lf\n", ans.X, ans.Y);
  }
  
  return 0;
}

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

int main(){
    int x, y ;

    while(1){
        cin >> x >> y;
        if (x == 0 && y == 0 )break;

        if (x < y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
}


Measured memory_bytes: 2996
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 2e5 + 5;
const size_t L = 60;

int n, mp[N];
LL k, a[N], g[L][N];
bool cnt[N];

int main() {
    n = read();
    k = read();
    generate_n(a, n, read);

    for (int i = n - 1; ~i; --i) {
        mp[a[i]] = i + n;
    }
    for (int i = n - 1; ~i; --i) {
        g[0][i] = mp[a[i]] - i + 1;
        mp[a[i]] = i;
    }
    for (int i = 1; i < L; ++i) {
        for (int j = 0; j < n; ++j) {
            g[i][j] = g[i - 1][(j + g[i - 1][j]) % n] + g[i - 1][j];
            if (g[i][j] > 1e18) g[i][j] = 1e18;
        }
    }
    LL pos = 0;
    for (int i = L - 1; i >= 0; --i) {
        if ((pos + g[i][pos % n]) <= n * k) {
            pos += g[i][pos % n];
        }
    }

    static int que[N];
    int tp = 0;
    for (; pos < n * k; ++pos) {
        int val = a[pos % n];
        if (cnt[val]) {
            int t;
            do {
                t = que[tp--];
                cnt[t] = false;
            } while (t != val);
        } else {
            cnt[val] = true;
            que[++tp] = val;
        }
    }

    for (int i = 1; i <= tp; ++i) {
        printf("%d ", que[i]);
    }
    return 0;
}

Measured memory_bytes: 99072
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 510000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
lli lcm(lli num1, lli num2){
    return num1 / gcd(num1, num2) * num2;
}
lli repow(lli n,lli k,lli m){
  if(k==0)return 1;
  else if(k%2==1)return repow(n,k-1,m)*n%m;
  else{
    lli temp=repow(n,k/2,m);
    return temp*temp%m;
  }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  Vec(P,lli,N,0);
  rep(i,0,N)cin >> P[i];
  rep(i,1,N){
    if(P[i-1]<P[i])P[i]--;
    else if(P[i-1]>P[i]) flag=1;
  }
  if(flag)Out("No");
  else Out("Yes");
}

Measured memory_bytes: 1024
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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

int main()
{

  int a, b, c;
  cin >> a >> b >> c;

  if(b/a>c)cout << c << endl;
  else cout<< b / a << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] strArraySub = str.split(" ");
        int suu = strArraySub.length;
        //System.out.println(strArraySub[0]);
        int num[] = new int[suu];
        for(int i=0;i<strArraySub.length;i++){
            num[i]=Integer.parseInt(strArraySub[i]);
        }
        int k = num[1]-num[0];
        int m = num[1];
        
        for(int j=k;j>0;j--){
            m = m-j;
            //System.out.println(m);
        }
        m = -m;
        System.out.println(m);
    }
}

Measured memory_bytes: 21972
var
  s:string;
  i,l,sc,sf:longint; 
 begin
  read(s);
  l:=length(s);sc:=maxlongint div 2;
  for i:=1 to l do if s[i]='F'then sf:=i;
  for i:=l downto 1 do if s[i]='C'then sc:=i;
  if sc<sf then writeln('Yes')
           else writeln('No');  
 end.

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

#define en '\n'
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vec<vec<T>>;
#define REP(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(hoge) hoge.begin(), hoge.end()
constexpr ll MOD = 1000000007;

class Combination {
  public:
    vec<ll> fact, finv;
    ll mod;
    Combination(ll n, ll _mod) {
        mod = _mod;
        fact.resize(n + 1);
        fact[0] = 1;
        REP(i, n) {
            fact[i + 1] = (fact[i] * (i + 1LL)) % mod;
        }
        finv.resize(n + 1);
        finv[n] = mod_inv(fact[n]);
        for(int i = n; i > 0; i--) {
            finv[i - 1] = finv[i] * i % mod;
        }
    }
    ll mod_inv(ll x) {
        ll n = mod - 2;
        ll res = 1LL;
        while(n > 0) {
            if(n & 1)
                res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        return res;
    }
    ll nCr(ll n, ll r) {
        if(n < r or n < 0 or r < 0)
            return 0;
        return fact[n] * finv[r] % mod * finv[n - r] % mod;
    }
};

Combination com(101010, MOD);
ll pow2[101010];

void solve(int n) {
    vec<int> a(n), in(n);
    REP(i, n) {
        cin >> a[i];
        a[i]--;
        in[a[i]]++;
    }

    vec<int> used(n, -1);
    int con = 0;
    int con2 = 0;
    int con3 = 0;
    REP(i, n) {
        if(in[i] >= 3) {
            cout << 0 << en;
            return;
        } else if(in[i] == 2 and a[a[i]] != i) {
            cout << 0 << en;
            return;
        }
    }
    REP(i, n) {
        if(used[i] != -1)
            continue;
        used[i] = i;
        if(in[i] == 1 and a[a[i]] == i and in[a[i]] == 1) {
            con++;
            con2++;
            used[a[i]] = i;
            continue;
        }

        int v = i;
        while(true) {
            v = a[v];
            if(used[v] == i) {
                if(a[a[v]] == v) {
                    con++;
                    con3++;
                    used[v] = i;
                    break;
                }
                cout << 0 << en;
                return;
            }
            if(used[v] != -1)
                break;
            used[v] = i;
        }
    }
    //cout << con2 << " " << con3 << en;

    ll ans = 0;
    REP(k, con2 / 2 + 1) {
        int l = con2 - 2 * k;
        if(l > con3 + 1)
            continue;
        //cout << k << " " << l << " " << com.nCr(k + con3, con3) << " " << com.nCr(con3 + 1, l) % MOD * (k + con3 + 1) << en;
        ans += com.nCr(k + con3, con3) * com.nCr(con3 + 1, l) % MOD * (k + con3 + 1) % MOD;
        ans %= MOD;
    }
    ans = ans * pow2[con] % MOD * com.fact[con3] % MOD * com.fact[con2] % MOD;
    cout << ans << en;
}

int main(void) {
    pow2[0] = 1;
    REP(i, 101000) {
        pow2[i + 1] = pow2[i] * 2 % MOD;
    }

    int n;
    while(cin >> n) {
        if(n == 0)
            break;
        solve(n);
    }
    return 0;
}



Measured memory_bytes: 6520
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

string s, t;

bool match(int k) {
	for (int i = 0; i < t.size(); i++) {
		if (t[i] != s[i + k] && s[i + k] != '?') {
			return false;
		}
	}
	return true;
}

string constructor(int k) {
	string ans = s;
	for (int i = 0; i < t.size(); i++) {
		ans[i + k] = t[i];
	}
	for (int i = 0; i < s.size(); i++) {
		if (ans[i] == '?') ans[i] = 'a';
	}
	return ans;
}

int main()
{
	cin >> s >> t;
	for (int i = s.size() - t.size(); i >= 0; i--) {
		if (match(i)) {
			cout << constructor(i) << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

a = input()
b = input()
c = input()

tmp = 'a'

for i in range(len(a+b+c)):
    if tmp == 'a':
        if len(a) >= 1:
            tmp = a[0]
            a = a[1:]
        else:
            print('A')
            break
    elif tmp == 'b':
        if len(b) >= 1:
            tmp = b[0]
            b = b[1:]
        else:
            print('B')
            break
    elif tmp == 'c':
        if len(c) >= 1:
            tmp = c[0]
            c = c[1:]
        else:
            print('C')
            break




Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 10, inf = 1e18 + 10, mod = 1e9 + 7;
ll a[3010], d[3010][3010][2];
ll f(int l, int r, int t)
{
    if(d[l][r][1] != -inf)
    {
        if(t)return d[l][r][1];
        else return d[l][r][0];
    }
    if(l == r)
    {
        if(t)return a[l];
        else return -a[l];
    }
    d[l][r][1] = max(f(l + 1, r, !t) + a[l], f(l, r - 1, !t) + a[r]);
    d[l][r][0] = min(f(l + 1, r, !t) - a[l], f(l, r - 1, !t) - a[r]);
    if(t)return d[l][r][1];
    else return d[l][r][0];
}
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("prices.in", "r", stdin);
    //freopen("prices.out", "w", stdout);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            d[i][j][1] = -inf;
            d[i][j][0] = -inf;
        }
    }
    for(int i = 1; i <= n; i++)cin >> a[i];
    cout << f(1, n, 1);
}


Measured memory_bytes: 141696
n,m=map(int,input().split())
a=[]
c=[0]*n
cnt=0
b=[0]*n
for _ in range(m):
  p,s=input().split()
  p=int(p)
  p-=1
  if s=="AC":
    a.append(p)
    if c[p]==0:
          c[p]=1
  else:
        if c[p]==0:    
          b[p]+=1
a=list(set(a))
for i in a:
  cnt+=b[i]
print(len(set(a)),cnt)


Measured memory_bytes: 59352
#include <iostream>
#define MAX 100000
using namespace std;
int n,A[MAX],L[MAX];
int lis()
{
    L[0]=A[0];
    int length=1;
    for(int i=1;i<n;i++)
    {
        if(L[length-1]<A[i])
        {
            L[length++]=A[i];
        }else{
        *lower_bound(L,L+length,A[i])=A[i];
        }
    }
    return length;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    cout<<lis()<<endl;
    return 0;
}

Measured memory_bytes: 3864
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int d = values[a];
			values[a] = values[b];
			values[b] = d;
			a = 0;
			b = 0;

		}
		for (int i = 0; i < values.length; i++) {
			System.out.println(values[i]);
		}
		sc.close();
	}
}

Measured memory_bytes: 26152
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;

char s[8001];
int x, y;
int cntX[4000] = { 0 }, cntY[4000] = { 0 };
int X = 0, Y = 0;
int idxX = -1, idxY = -1;
int cntT = 0;
int len;
int flag = 1;
int dpx[8000][16001] = { 0 };
int dpy[8000][16001] = { 0 };

int searchx(int i, int dis, int* cnt) {
	if (dpx[i][dis + 8000] != 0)return dpx[i][dis + 8000];
	if (i == 0) {
		//PRINTS("s");
		if (dpx[i][dis+8000])return 1;
		return 0;
	}
	dpx[i][dis + 8000] = (searchx(i - 1, dis + cnt[i-1], cnt))==1 || (searchx(i - 1, dis - cnt[i-1], cnt)==1);
	//printf("dis=%d, cnt[%d]=%d, %d\n", dis, i - 1, cnt[i - 1], dpx[i][dis + 8000]);
	if (!dpx[i][dis + 8000])dpx[i][dis + 8000] = -1;
	//printf("i=%d,dis+8000=%d\n", i, dis + 8000); PRINTD(dpx[i][dis + 8000]);
	return dpx[i][dis + 8000];
}
int searchy(int i, int dis, int* cnt) {
	if (dpy[i][dis + 8000] != 0)return dpy[i][dis + 8000];
	if (i == 0) {
		if (dpy[i][dis+8000])return 1;
		return 0;
	}
	dpy[i][dis + 8000] = (searchy(i - 1, dis + cnt[i-1], cnt)==1) || (searchy(i - 1, dis - cnt[i-1], cnt)==1);
	//printf("cnt[%d]=%d, %d\n", i, cnt[i], dpy[i][dis + 8000]);
	if (!dpy[i][dis + 8000])dpy[i][dis + 8000] = -1;
	return dpy[i][dis + 8000];
}

int main() {
	scanf("%s", s);
	scanf("%d %d", &x, &y);
	len = strlen(s);
	int cnt = 0;
	REP(i, len) {
		if (s[i] == 'T') {
			x -= cnt;
			break;
		}
		cnt++;
		if (i == len - 1) {
			X = len;
			if (X != x || y != 0)flag = 0;
		}
	}
	if (X != len) {
		for (int i = cnt; i < len; i++) {
			if (s[i] == 'T') {
				if (cntT) {
					idxX++;
				}
				else {
					idxY++;
				}
				cntT = 1 - cntT;
			}
			else {
				if (cntT) {
					cntY[idxY]++;
				}
				else {
					cntX[idxX]++;
				}
			}
		}
		//printf("%d %d\n", x, idxX);
		//printf("%d %d\n", y, idxY);
		dpx[0][8000] = 1;
		dpy[0][8000] = 1;
		if(idxX==-1){
			flag = (x == 0);
		}
		else if (searchx(idxX+1, x, cntX)!=1)flag = 0;
		if(idxY == -1) {
			flag = (y == 0);
		}else if (searchy(idxY+1, y, cntY)!=1)flag = 0;
	}
	//printf("x=%d,y=%d,X=%d,Y=%d\n", x, y, X, Y);
	//printf("%d<%d || %d!=%d\n", abs(X), abs(x), X%2, x%2);
	//printf("%d<%d || %d!=%d\n", abs(Y), abs(y), Y % 2, y % 2);
	//PRINTD(flag);
	if (flag) {
		PRINTS("Yes");
	}
	else {
		PRINTS("No");
	}
}

Measured memory_bytes: 498304
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int mn[100010];

template <typename monoid_trait> struct segment_tree {
	using M = monoid_trait;
	using T = typename M::value_type;

	// monoid m;
	std::size_t sz;
	std::vector<T> x;

	segment_tree(std::size_t n = 0) {
		sz = 1;
		while (sz < n)
			sz *= 2;
		x.assign(sz * 2, M::id());
		initialize();
	}

	template <typename iterator>
	segment_tree(iterator first, iterator last) {
		sz = 1;
		std::size_t n = std::distance(first, last);
		while (sz < n)
			sz *= 2;
		x.assign(sz * 2, M::id());
		std::copy(first, last, x.begin() + sz);
		initialize();
	}

	void initialize() {
		for (int i = (int)sz - 1; i >= 1; --i) {
			x[i] = M::op(x[i * 2 + 0], x[i * 2 + 1]);
		}
	}

	T query(std::size_t l, std::size_t r) const {
		T res = M::id();
		for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
			if (l & 1)
				res = M::op(res, x[l++]);
			if (r & 1)
				res = M::op(res, x[--r]);
		}
		return res;
	}

	void update(std::size_t i, const T &val) {
		x[i += sz] = val;
		while (i > 1) {
			x[i / 2] = M::op(x[i], x[i ^ 1]);
			i /= 2;
		}
	}

	T operator[](std::size_t i) const { return x[sz + i]; }
};

template <typename T> struct zero_sum_monoid {
	using value_type = T;
	static constexpr T id() { return 0; }
	static T op(const T &a, const T &b) { return a + b; }
};

template <typename T> struct inf_min_monoid {
	using value_type = T;
	static constexpr T id() { return std::numeric_limits<T>::max(); }
	static T op(const T &a, const T &b) { return std::min(a, b); }
};

template <typename T> using rmq = segment_tree<inf_min_monoid<T>>;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, S, T;
	
	cin >> N >> M >> S >> T;
	segment_tree<inf_min_monoid<int>> st(N);
	//st.update(N - 1, 0);
	//cerr << st.query(0, N) << endl;
	S--;
	T--;
	vector<int> D(N);
	int res = 0;
	for (int i = 0; i <= N; i++) {
		mn[i] = -1;
	}
	for (int i = 0; i < N; i++) {
		cin >> D[i];
	}
	int a, b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		a--;
		b--;
		if ((mn[b] == -1) || (mn[b] > a)) {
			mn[b] = a;
		}
	}
	for (int i = 0; i < N; i++) {
		if (i <= S) {
			st.update(i, 0);
		}
		else {
			if (mn[i] != -1) {
				int t;
				t = st.query(mn[i], i + 1);
				if (t < 10000000000) {
					st.update(i, t + D[i]);
				}
			}
		}
	}
	
	cout << st.query(T, N) << endl;
}

Measured memory_bytes: 6492
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin >> n;
	int u=n%10;
	if(u==2 || u==4 || u==5 || u==7	|| u==9)cout << "hon";
	else if(u==0 || u==1 || u==6 || u==8)cout << "pon";
	else cout << "bon";
}

Measured memory_bytes: 3636
import string
import itertools


def main(n: int, s: str):
    # print(n, s)
    # letters_cycle = itertools.cycle(string.ascii_uppercase)
    letters_cycle = string.ascii_uppercase + string.ascii_uppercase

    print(''.join([
        letters_cycle[ord(ch) - 65 + n]
        for ch in s
    ]))


if __name__ == '__main__':
    a = [input() for i in range(2)]

    main(int(a[0]), a[1])


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
int dp[100001][3];
int a[100001],b[100001],c[100001];
int n;
int dpf(int num,int two,char x)
{
  if (x=='D') { return max(a[num]+dpf(num+1,0,'A'),max(b[num]+dpf(num+1,1,'B'),c[num]+dpf(num+1,2,'C')));}
  else if (dp[num][two]!=-1   ) { return dp[num][two]; }
  else if (num==n) { if(x=='A'){return dp[num][0]=max(b[num],c[num]);} if(x=='B'){return dp[num][1]=max(a[num],c[num]);} if(x=='C'){return dp[num][2]=max(b[num],a[num]);} }
  else if (x=='A') { return dp[num][0]=max(b[num]+dpf(num+1,1,'B'),c[num]+dpf(num+1,2,'C'));}
  else if (x=='B') { return dp[num][1]=max(a[num]+dpf(num+1,0,'A'),c[num]+dpf(num+1,2,'C'));}
  else if (x=='C') { return dp[num][2]=max(a[num]+dpf(num+1,0,'A'),b[num]+dpf(num+1,1,'B'));}
  return 0;
}
int main()
{  ios_base::sync_with_stdio(false); cin.tie(NULL);
   memset(dp,-1,sizeof(dp));
   cin>>n;
   for(int i=1;i<=n;i++)
   {
    cin>>a[i]>>b[i]>>c[i];
   }
   int ans=dpf(1,3,'D');
   cout<<ans;
   return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (2 * b - a) << endl;

    return 0;
}

Measured memory_bytes: 888
import math
num = int(input())
townList = [list(map(int, input().split())) for i in range(num)]
drTown_2 = 0
for i in range(num):
	for j in range(num - i - 1):
		tmp = (townList[i][0] - townList[i + j + 1][0]) ** 2 + (townList[i][1] - townList[i + j + 1][1]) ** 2
		drTown_2 += tmp ** 0.5

print(drTown_2 * (num-1) * 2 / (num*(num-1)))

Measured memory_bytes: 3188
#include <iostream>

int main()
{
	int a, b, c, d;
	
	std::cin >> a >> b >> c;

	if (a > b)
	{
		d = a;
		a = b;
		b = d;
	}

	if (b > c)
	{
		d = b;
		b = c;
		c = d;
	}

	if (a > b)
	{
		d = a;
		a = b;
		b = d;
	}

	std::cout << a << " " << b << " " << c << std::endl;

	return 0;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

int main( void ){
	// initialize();
	ll N; double K;
	cin >>N>>K;
	ll M = K*100+0.5;
	cout << (N*M)/100 << endl;
}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


Measured memory_bytes: 3700