akhauriyash/Code-Regression huggingface dataset:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
ans=0
for i in range(n):
  ans+=(i+1)*(i+2)//2
for _ in range(n-1):
  a,b=map(int,input().split())
  if a>b:
    a,b=b,a
  ans-=a*(n-b+1)
print(ans)

Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,k,x,y,d;
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
   cin>>n>>k;
   for(int i=1;i<=k;i++)
   {
      cin>>d;
      for(int j=1;j<=d;j++)
      {
         cin>>x;
         st.insert(x);
      }
   }
   cout<<n-st.size();
   return 0;
}


Measured memory_bytes: 3624
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val ans = mutableListOf<Char>()
    var charge = 0

    for (c in s) {
        if (charge == 0 && c == ')') {
            ans.add(0, '(')
            ans.add(')')
        }else if(c==')'){
            charge--
            ans.add(')')
        }else{
            charge++
            ans.add('(')
        }
    }
    while(charge-- > 0)ans.add(')')
    println(ans.joinToString(""))
}


Measured memory_bytes: 33724
s = input()
r_cnt = 0
l_cnt = 0
lst = [0 for _ in range(len(s))]
s += 'R'
for i in range(len(s)):
  if s[i] == 'R' and l_cnt == 0:
    r_cnt += 1
  elif s[i] == 'L' and r_cnt > 0:
    l_cnt += 1
    if r_cnt % 2 == 0:
      lst[i] += r_cnt // 2
      lst[i-1] += r_cnt // 2
    else:
      lst[i] += r_cnt // 2
      lst[i-1] += r_cnt // 2 + 1
    r_cnt = 0
    ind = i
  elif s[i] == 'L' and r_cnt == 0:
    l_cnt += 1
  elif s[i] == 'R' and l_cnt > 0:
    r_cnt += 1
    if l_cnt % 2 == 0:
      lst[ind] += l_cnt // 2
      lst[ind-1] += l_cnt // 2
    else:
      lst[ind] += l_cnt // 2 + 1
      lst[ind-1] += l_cnt // 2
    l_cnt = 0
print(*lst)


Measured memory_bytes: 6408
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
AA = [inp() for _ in range(N)]
x = sorted(AA)
M1 = x[-1]
M2 = x[-2]

for a in AA:
    if a == M1:
        print(M2)
    else:
        print(M1)


Measured memory_bytes: 72532
N = int(input().strip())

c = 0
for n in range(1, N+1, 2):
  d = 0
  for i in range(1, n+1):
    if i * i > n:
      break
    if n % i == 0:
      d += 2
      if d >= 9:
        break
  if d == 8:
    c += 1

print(c)


Measured memory_bytes: 2940
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,K,*H = map(int,read().split())
dp = [0] *(N+K)
H = [H[0]]*K+H

for n in range(K,N+K):
  h = H[n]
  dp[n] = min(x+abs(y-h) for y,x in zip(H[n-K:n],dp[n-K:n]))
print(dp[-1])

Measured memory_bytes: 13320
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
struct data{
    int a,b,c;
};

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
#define MAXSIZE 200000
int list[MAXSIZE];
int tail;

void Init(void){
    tail=0;
}
int Top(void){
    return 0;
}

int Next(int pos){
    if(pos<tail-1){
        return pos+1;
    }else{
        return -1;
    }
}
int Count(void){
    return tail;
}

int Item(int pos){
    if((pos>=0)&&(pos<tail)){
        return list[pos];
    }else{
        return 0;
    }
}
void Add(int value){
    if(tail<MAXSIZE){
        list[tail]=value;
        tail++;
    }
}
void Delete(int pos){
    if((pos>=0)&&(pos<tail)){
        int i;
        for(i=pos;i<tail-1;i++){
            list[i]=list[i+1];
        }
        tail--;
    }
}

int main(){
    int N;
    scanf("%d",&N);
    int st[N];
    for(int i=0;i<N;i++){
        scanf("%d",&st[i]);
    }
    qsort(st,N,sizeof(int),compare_int);
    double vl=(double)st[0];
    for(int i=0;i<N-1;i++){
        vl=(vl+st[i+1])/2;
    }
    printf("%lf",vl);
}


Measured memory_bytes: 1724
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 15 22:46:42 2019

@author: Yamazaki Kenichi
"""
import math
N = int(input())
A = [int(input()) for i in range(N)]

A.sort()

temp1,temp2 = 0,0
if N%2 != 55:
    temp1 += A[-1]+A[-2]-2*A[0]
#    print(temp1,A[-1],A[-2],A[0])
    for i in range(N//2-1):
        temp1 += A[-1-(math.ceil(i/2)*2)] - A[(i//2*2)+1]
        temp1 += A[-2-(math.ceil(i/2)*2)] - A[(i//2*2)+2]
#        print(temp1,-1-(math.ceil(i/2)*2),-2-(math.ceil(i/2)*2),(i//2*2)+1,(i//2*2)+2)
    temp2 += 2*A[-1]-A[0]-A[1]
#    print(temp2,A[-1],A[0],A[1])
    for i in range(N//2-1):
        temp2 += A[-2-(i//2*2)] - A[(math.ceil(i/2)*2)]
        temp2 += A[-3-(i//2*2)] - A[(math.ceil(i/2)*2)+1]
#        print(temp2,-2-(i//2*2),-3-(i//2*2),(math.ceil(i/2)*2),(math.ceil(i/2)*2))
print(max(temp1,temp2))

Measured memory_bytes: 7552
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

// #define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int a; cin >> a;
  string s; cin >> s;
  if (a < 3200) cout << "red";
  else cout << s;
  cout << endl;
  
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    string s;
    cin >> s;
    
    int ans = INF;
    rep(i,s.size()-2)
    {
        int tmp = 0;
        tmp += (s[i]-'0')*100;
        tmp += (s[i+1]-'0')*10;
        tmp += (s[i+2]-'0');
        chmin(ans, abs(753-tmp));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri register int
const int N=505;
int a[N][N],f[N][N],l[N][N],r[N][N];
char s[N];
/* 
f[i][j] (i,j) 能走到的位置的权值和
l[i][j][k]/r[i][j][k] 表示 (i,j) 可以到达的第 k 行最左/右的位置 ，第一维省略
不能走到的点贡献相当于已经清零，因为 (i+1,j) (i,j+1) 共同能走到的点的递增序列里面不会出现这些位置，
且没有被计算到其左上的点的贡献中去 
*/
int main(){
//	freopen("cell.in","r",stdin);
//	freopen("cell.out","w",stdout);
	ri n,i,j,k,now;
	register long long ans;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%s",s+1);
		for(j=1;j<=n;++j)
			a[i][j]=s[j]=='#'?0:s[j]-'0';
	}
	ans=0;
	for(i=n;i;--i)
		for(j=n;j;--j){
			if(a[i][j]==0){
				memset(l[j]+i,127,sizeof(int)*(n-i+1));
				memset(r[j]+i,128,sizeof(int)*(n-i+1));
				continue;
			}
			if(a[i+1][j]==0&&a[i][j+1]==0)
				l[j][i]=r[j][i]=j;
			else if(a[i+1][j]==0)
				memcpy(l[j]+i,l[j+1]+i,sizeof(int)*(n-i+1)),
				memcpy(r[j]+i,r[j+1]+i,sizeof(int)*(n-i+1)),
				l[j][i]=j,
				f[i][j]=f[i][j+1];
			else if(a[i][j+1]==0)
				l[j][i]=r[j][i]=j,
				f[i][j]=f[i+1][j];
			else{
				f[i][j]=f[i][j+1]+f[i+1][j];
				l[j][i]=j;r[j][i]=r[j+1][i];
				now=0;
				for(k=i+1;k<=n;++k){
					if(r[j][k]>=l[j+1][k]&&l[j+1][k]>now)
					//	printf("sub %d %d %d %d\n",i,j,k,l[j+1][k]),
						f[i][j]-=f[k][l[j+1][k]];
					now=max(now,r[j][k]);
					l[j][k]=min(l[j][k],l[j+1][k]);
					r[j][k]=max(r[j][k],r[j+1][k]);
				}
			}
			ans+=a[i][j]*f[i][j];
		//	printf("f %d %d %d\n",i,j,f[i][j]);
			f[i][j]+=a[i][j];
		//	printf("check (%d,%d)\n",i,j);
		//	for(k=i;k<=n;++k)
		//		printf("%d %d %d\n",k,l[j][k],r[j][k]);
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7792
import scala.io.StdIn._
import scala.math._
object Main{
    def main(args: Array[String]): Unit = {
        lazy val n = readInt
        var map = Array.ofDim[Int](n + 1, n + 1)
        for(i <- 1 to n){
              var temp = readLine.split(" ").map(_.toInt)
            for(j <- 1 to n)map(i)(j) = map(i)(j - 1) + map(i - 1)(j) -  map(i - 1)(j - 1) + temp(j - 1)
        }
        var max = map(1)(1)
        for(i <- 1 to n ;j <- 1 to n;k <- i to n;l <- j to n) max = math.max(max,map(k)(l) + map(i - 1)(j - 1) - map(i - 1)(l) - map(k)(j - 1))   
        
        
        
        println(max)
  }
}

Measured memory_bytes: 54812
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

using llint=long long;

int main(){
    llint d;
    cin>>d;
    
    llint anum=26;
    vector<llint> c(anum);
    
    REP(i,anum){
        cin>>c[i];
    }
    vector<vector<llint>> s(d,vector<llint>(anum));
    REP(i,d){
        REP(j,anum){
            cin>>s[i][j];
        }
    }
    vector<llint> result(anum);

    REP(i,d){
        cout<<1+i%26<<endl;
    }
}


Measured memory_bytes: 3284
import java.util.Scanner;

public class Main {

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		int K = in.nextInt();
		int[] s = new int[]{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		System.out.println(s[K-1]);
	}


	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 23120
a,b,c = list(map(int, input().split()))
ans = 0
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0 and ans < 100000:
    a, b, c = (b + c) >> 1, (a + c) >> 1, (a + b) >> 1
    ans += 1
if ans < 100000:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 2940
S = input()
N = len(S)
ans = [0] * N
c = 0
for i in range(N):
    if S[i] == 'R':
        c += 1
    else:
        ans[i] += c // 2
        ans[i - 1] += c // 2 + c % 2
        c = 0
for i in range(N - 1, -1, -1):
    if S[i] == 'L':
        c += 1
    else:
        ans[i] += c // 2
        ans[i + 1] += c // 2 + c % 2
        c = 0
print(*ans)


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

int main() {
  long n;
  cin >> n;
  
  vector<long> p(n+1);
  vector<long> rec(n+1);
  rec.at(0) = n;
  for(long i = 1; i<n+1; i++){
    cin >> p.at(i);
    rec.at(i) = min(rec.at(i-1),p.at(i));
  }
  
  long ans = 0;
  for(long i=1; i<n+1; i++){
    if(p.at(i) <= rec.at(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
int GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n,m;
cin>>n>>m;
V<ll> h(n);
for(int i=0;i<n;i++)cin>>h[i];
V<int> g[200005];
for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    g[--a].emplace_back(--b);
    g[b].emplace_back(a);
}
int ans=0;
for(int i=0;i<n;i++){
    ll now=h[i];
    bool ok=true;
    for(int v:g[i]){
        if(now<=h[v]){
            ok=false;
        }
    }
    if(ok)ans++;
}
cout<<ans<<"\n";
}



Measured memory_bytes: 11384
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let x:u64 = r.reads();
    let y:u64 = r.reads();
    let z:u64 = r.readl();

    println!("{} {} {}",z,x,y);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;
typedef long long ll;

ll inf = 1000000007;

int main() {
    ll N, M;    cin >> N >> M;
    ll *a = new ll[M];
    for (int i = 0; i < M; i++)
        cin >> a[i];
    
    ll *stairs = new ll[N+1];
    for (int i = 0; i < M; i++)
        stairs[a[i]] = 1;

    ll *ans = new ll[N+1];
    ans[0] = 1;
    ans[1] = (stairs[1]) ? 0 : 1;

    for (int i = 0; i <= N-2; i++) {
        if (stairs[i+2])
            ans[i+2] = 0;
        else 
            ans[i+2] = (ans[i] + ans[i+1]) % inf;
    }  

    cout << ans[N] << endl;

    return 0;
}

Measured memory_bytes: 2560
N=int(input())
a=[0]*5
for i in range(N):
    s=input()[0]
    if s=="M": a[0]+=1
    elif s=="A": a[1]+=1
    elif s=="R": a[2]+=1
    elif s=="C": a[3]+=1
    elif s=="H": a[4]+=1

ans=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=a[i]*a[j]*a[k]
print(ans)

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

int main(){
	vector<string>pl;
	map<char,int>discard;
	discard['a']=0;
	discard['b']=1;
	discard['c']=2;
	string s;
	char sl,t;
	for(int i=0;i<3;i++){
		cin>>s;
		pl.push_back(s);
	}
	sl='a';
	
	while(1){
		if(pl[discard[sl]].size()==0){
			cout<<char(t-32)<<endl;
			break;
		}
		t=pl[discard[sl]][0];
		
		pl[discard[sl]].erase(0,1);
		sl=t;
	}
	return 0;
}


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

vector<vector<int>> graph(2*1e5);
vector<bool> visited(2*1e5);
vector<long long int> num(2);

void DFS(int v){
    if(visited[v] == true) return ;

    visited[v] = true;
    if(v < 1e5) num[0] += 1;
    else        num[1] += 1;
    for(int next_v : graph[v]) DFS(next_v);
}

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

    for(int i=0; i<n; i++){
        int x, y;
        cin >> x >> y;
        x -= 1;
        y -= 1;
        y += 1e5;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    long long int ans = 0;
    for(int v=0; v<1e5; v++){
        if(visited[v] == true) continue;
        num.assign(2, 0);
        DFS(v);
        ans += num[0] * num[1];
    }
    cout << ans - n << endl;
    return 0;
}

Measured memory_bytes: 12932
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N;
    cin >> N;
    vector<long> p(N);
    for (int i = 0; i < N ; i++) {
        std::cin >> p.at(i);
    }
    int count = 0;
    for (int j = 0; j < N; j++)
    {
        if (p[j]!=j+1)
        {
            count ++;
        }       
        
    }
    if (count > 2)
    {
        cout << "NO" ;
    }else{
        cout << "YES" ;
    }
    
}




Measured memory_bytes: 256
s = gets.chomp
t = gets.chomp

hash = {}

s.chars.each_with_index do |c, i|
  hash[c] ||= []
  hash[c] << i
end

cnt = 0
p = 0
fst = true
t.chars.each do |c|
  d = hash[c]

  unless d
    puts "-1"
    exit
  end
  
  if fst
    fst = false
    next if d[0] == 0
  end
  
  if d[-1] <= p
    p = d[0]
    cnt += 1
    next
  end
 
  if d[0] > p
    p = d[0]
    next
  end

  p = d.bsearch { |v| v > p }
end

puts cnt * s.length + p + 1


Measured memory_bytes: 14972
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
#define MAX 505
 
typedef long long ll;
typedef unsigned long long ull;
typedef bitset<64> bset;

bool make(vector< vector<bool> > s, vector< vector<bool> > u, vector< vector<int> > &a, int n)
{
    rep(i,n) rep(j,n) a[i][j] = -1;
    bool err = false;
    bool is_trans = false;
    auto setb = [&](bool t, int tmp_i, int tmp_j, bool b) {
        int i, j;
        if (t) { i = tmp_j; j = tmp_i; }
        else { i = tmp_i; j = tmp_j;}

        if (a[i][j] == !b)  err = true;
        else a[i][j] = b;
    };
    auto cntbit = [&](bool t, int i, bool b) -> int {
        int ans = 0;
        if (t) {
            rep(k,n) ans += (a[k][i] == b);
        } else {
            rep(k,n) ans += (a[i][k] == b);
        }
        return ans;
    };
    vector< vector<int> > cnf(2, vector<int>(n, -1)); // 行ごとの確定判定

    rep(i,2) rep(j,n) {
        // 論理積=1は1確定 論理和=0は0確定
        if (s[i][j] == u[i][j]) {
            cnf[i][j] = u[i][j];
            rep(k,n) setb(i, j, k, u[i][j]);
        }
        if (err) return false;
    }
    vector< vector<int> > yet(2);
    rep(i,2) rep(j,n) if (cnf[i][j] == -1) yet[i].push_back(j);

    rep(i,2) {
        if (yet[i].size() == 0) {   // 全確定済みは矛盾チェックして終了
            for (int idx : yet[!i]) {
                if (cntbit(!i, idx, u[!i][idx]) == 0) return false; // 論理和1(論理積0)は最低1つ1(0)がないとダメ
            }
            return true;
        } else if (yet[i].size() == 1) {    // 未確定1は矛盾のないように値をセットして終了
            int idx = yet[i][0];
            for (int idx2 : yet[!i]) {
                if (cntbit(!i, idx2, u[!i][idx2]) == 0) setb(i, idx, idx2, u[!i][idx2]); // 論理和1(論理積0)は最低1つ1(0)がないとダメ
                else setb(i, idx, idx2, u[i][idx]);
            }
            return (cntbit(i, idx, u[i][idx]) > 0);
        }
    }
    // タテヨコ共に2列以上未確定が残っているなら交互に1,0をセットすればよい
    rep(i,yet[0].size()) rep(j,yet[1].size()) setb(false, yet[0][i], yet[1][j], (i+j)%2);
    return true;
}

int main(int, char**)
{
    int n;
    cin >> n;

    vector< vector<bool> > s(2);
    vector< vector<bset> > bset_u(2);

    ull tmp;
    rep(i,2) rep(j,n) { cin >> tmp; s[i].push_back((tmp == 0) ? true : false); }
    rep(i,2) rep(j,n) { cin >> tmp; bset_u[i].push_back(bset(tmp)); }

    vector< vector<int> > a(n, vector<int>(n));
    vector< vector<bool> > u(2, vector<bool>(n));
    vector< vector<bset> > bset_a(n, vector<bset>(n));
    // ビット毎にチェック
    rep(b,64) {
        rep(i,2) rep(j,n) u[i][j] = bset_u[i][j].test(b);
        if (!make(s, u, a, n)) {
            cout << -1 << endl;
            return 0;
        }
        rep(i,n) rep(j,n) bset_a[i][j].set(b, a[i][j]);
    }

    rep(i,n) {
        rep(j,n) {
            if (j > 0) cout << " ";
            cout << bset_a[i][j].to_ullong();
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 8516
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define P pair<int,int>
vector<P> g[100001];
int d[100001];
void dfs(int now){
    for(int i=0;i<g[now].size();i++){
        if(d[g[now][i].first]>d[now]+g[now][i].second){
            d[g[now][i].first]=d[now]+g[now][i].second;
            dfs(g[now][i].first);
        }
    }
}
signed main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        d[i]=INF;
    }
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        g[a].push_back(P(b,c));
        g[b].push_back(P(a,c));
    }
    int q,k;
    cin>>q>>k;
    d[k]=0;
    dfs(k);
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        cout<<d[a]+d[b]<<endl;
    }
    return 0;
}


Measured memory_bytes: 16128
n, q = map(int, input().split())

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    e[a].append(b)
    e[b].append(a)

qs = [0] * (n + 1)
for _ in range(q):
    p, q = map(int, input().split())
    qs[p] += q

target = [1]
visited = set()
while len(target):
    t = target.pop()
    visited.add(t)
    ct[t] += qs[t]
    for nt in e[t]:
        if nt not in visited:
            target.append(nt)
            ct[nt] += ct[t]

print(*ct[1:])


Measured memory_bytes: 70652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
// #define NMAX 1000000000
int N,K;
vi X;

int solve(){

	vector<pair<int,int>> LR; //<left,right>
	rp(e,K-1,N){
		int s = e - (K-1);
		LR.emplace_back(X[s], X[e]);
	}

	// for(auto x:LR){
	// 	cout<<x.first<<" "<<x.second<<"\n";
	// }puts("---");//

	int ans = INT_MAX;
	for(auto lr:LR){
		int l,r; tie(l,r) = lr;
		if(0 < l) ans = min(ans, abs(r));
		else if(r < 0) ans = min(ans, abs(l));
		else if(l == 0 && 0 < r) ans = min(ans, abs(r));
		else if(r == 0 && l < 0) ans = min(ans, abs(l));
		else{ // l < 0 && 0 < r
			if(abs(l) < abs(r)){
				ans = min(ans, abs(l)*2 + abs(r));
			}
			else{ // abs(l) >= abs(r)
				ans = min(ans, abs(r)*2 + abs(l));
			}
		}

	}

	return ans;
}

int main(){
	cin>>N>>K;
	X.resize(N);
	rp(i,0,N) cin>>X[i];
	cout<< solve() <<endl;
}


Measured memory_bytes: 1276
import math
num = int(input())

x = [int(a) for a in input().split()]
y = [int(a) for a in input().split()]



p1 = 0
for i in range(num):
    p1 += abs(x[i]-y[i])
print(float(p1))

p2 = 0
for i in range(num):
    p2 += (x[i] - y[i])**2
p2 = math.sqrt(p2)
print(p2)

p3 = 0
for i in range(num):
    p3 += abs((x[i]-y[i])**3)
    
p3 = math.pow(p3,(1.0/3.0))
print(p3)

m = []
for i in range(num):
    m.append(abs(x[i]-y[i]))

print(float(max(m)))
    



Measured memory_bytes: 5700
#include<cstdio>
using namespace std;
char a[101][101];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	n--; m--;
	for (int i = 0; i < 100; i++)
	{
		for (int y = 0; y < 100; y++) {
			if (i < 50)
				a[i][y] = '.';
			else
				a[i][y] = '#';
		}
	}
	for (int i = 0; i < 50; i += 2)
	{
		if (!m)break;
		for (int y = 0; y < 100; y += 2)
		{
			if (m)
			{
				a[i][y] = '#';
				m--;
			}
		}
	}
	for (int i = 51; i < 100; i += 2)
	{
		if (!n)break;
		for (int y = 0; y < 100; y += 2)
		{
			if (n)
			{
				a[i][y] = '.';
				n--;
			}
		}
	}
	printf("100 100\n");
	for (int i = 0; i < 100; i++)
	{
		for (int y = 0; y < 100; y++)
			printf("%c", a[i][y]);
		printf("\n");
	}
}

Measured memory_bytes: 128
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。

int main(){
	int n;
	cin>>n;
	vector<int> v(n);
	rep0(i,n){
		int a;
		cin>>a;
		v[i]=a;
	}
	vector<int> ans;
	int sizee=n-1;
	while(1){
		for(int j=sizee;j>=0;j--){
			if(v[j]==j+1){
			ans.push_back(v[j]);
			v.erase(v.begin()+j);
			break;
			}
		}
		sizee--;
		if(sizee<0) break;
	}
	if(v.size()) cout<<-1<<endl;
	else{
		reverse(ans.begin(),ans.end());
	for(auto a:ans){
		cout<<a<<endl;
	}
	}

	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    REP(i, B) {
        REP(j, A) cout << 0;
        FOR(j, A, W) cout << 1;
        cout << endl;
    }
    FOR(i, B, H) {
        REP(j, A) cout << 1;
        FOR(j, A, W) cout << 0;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
import numpy as np

def main():
    H, W = [int(i) for i in input().split()]
    N = int(input())
    a = [int(i) for i in input().split()]
    
    color_ar = np.zeros((H, W), dtype=np.int32)
    #print(color_ar)
    
    y = 0
    x = 0
    
    for i in range(N):
        t = a[i]
        while t > 0:
            if(np.count_nonzero(color_ar) == 0):
                color_ar[0,0] = i + 1
                if((y + 1) % 2 == 0):
                    x -= 1
                else:
                    x += 1
                
                if((x < 0) or (x >= W)):
                    y += 1
                    if(x < 0):
                        x = 0
                    else:
                        x = W - 1
                    
            else:
                color_ar[y,x] = i + 1
                if((y + 1) % 2 == 0):
                    x -= 1
                else:
                    x += 1
                
                if((x < 0) or (x >= W)):
                    y += 1
                    if(x < 0):
                        x = 0
                    else:
                        x = W - 1
            t -= 1
            
    #print(color_ar)
    for y in range(H):
        for x in range(W):
            print(color_ar[y,x], end="")
            if(x < W - 1):
                print(" ",end="")
        if(y < H - 1 ):
            print("")
            
if __name__=="__main__":
    main()

Measured memory_bytes: 13824
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {

	void solve() {
		int N = sc.nextInt();
		int[] a = sc.nextIntArray(2 * N);
		sort(a);
		int ans = 0;
		for (int i = 0; i < 2 * N; i += 2) {
			ans += Math.min(a[i], a[i+1]);
		}
		out.println(ans);
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 8020
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

ll prev1[100010];

ll findprev(ll val1)
{
    if(prev1[val1]==val1)
    {
        return val1;
    }
    return prev1[val1]=findprev(prev1[val1]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll jobs,days;
    cin>>jobs>>days;
    vpll jobstore;
    pll store;
    while(jobs--)
    {
        cin>>store.second>>store.first;
        if(store.second>days)
        {
            continue;
        }
        jobstore.push_back(store);
    }
    for(ll i=1;i<=days;i++)
    {
        prev1[i]=i;
    }
    prev1[0]=0;
    ll ans=0,store1;
    ll size=jobstore.size();
    sort(jobstore.begin(),jobstore.end());
    reverse(jobstore.begin(),jobstore.end());
    for(ll i=0;i<size;i++)
    {
        ll val=days+1-(jobstore[i].second);
        val=findprev(val);
        if(!val)
        {
            continue;
        }
        prev1[val]=prev1[val-1];
        ans+=jobstore[i].first;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2672
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!
 
/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 1000000000005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
ll r,c;
ll mat[40][40],gi[40][40];
vector<ll> v[1000];
bool issafe(ll i,ll j)
{
    if((i>=0 and i<r) and (j>=0 and j<c)) return true;
    return false;
}
ll bfs(ll so)
{
    bool vi[1000] = {false};
    vi[so] = true;
    ll level[1000] = {0} , ans=0;
    queue<ll> q;
    q.push(so);
    while(!q.empty())
    {
        ll st = q.front();
        q.pop();
        for(auto u: v[st])
        {
            if(!vi[u])
            {
                level[u] = level[st] + 1;
                vi[u] = true;
                q.push(u);
                ans = max(ans,level[u]);
            }
        }
    }
    return ans;
}
signed main()
{
    fast;
    
    ll i,j,ans=0;
    cin>>r>>c;
    for(i=0;i<r;i++)
    {
        string s;
        cin>>s;
        for(j=0;j<c;j++)
        {
            if(s[j]=='.') mat[i][j] = 1;
        }
    }
    ll num = 1;
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            if(mat[i][j]==1)
            {
                gi[i][j] = num;
                num++;
            }
        }
    }
    for(i=0;i<r;i++)
    {
        for(j=0;j<c;j++)
        {
            if(mat[i][j]==1)
            {
                if(issafe(i,j-1) and mat[i][j-1]==1) v[gi[i][j]].pb(gi[i][j-1]);
                if(issafe(i,j+1) and mat[i][j+1]==1) v[gi[i][j]].pb(gi[i][j+1]);
                if(issafe(i-1,j) and mat[i-1][j]==1) v[gi[i][j]].pb(gi[i-1][j]);
                if(issafe(i+1,j) and mat[i+1][j]==1) v[gi[i][j]].pb(gi[i+1][j]);
            }
        }
    }
    for(i=1;i<num;i++)
    {
        ll ha = bfs(i);
        ans = max(ans,ha);
    }
    cout<<ans;
}

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

const ll B = 50;

ll to[B][10][10];
ll vs[B][10][10];

void init() {
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			to[0][i][j] = (i + j) / 10 + (i + j) % 10;
			vs[0][i][j] = (i + j) / 10;
		}
	}
	for (int i = 0; i + 1 < B; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				to[i + 1][j][k] = to[i][j][to[i][j][k]];
				vs[i + 1][j][k] = vs[i][j][k] + vs[i][j][to[i][j][k]];
			}
		}
	}
}

int main()
{
	init();
	int M;
	cin >> M;
	ll res = -1, td = 0;
	for (int i = 0; i < M; i++) {
		int d;
		ll c;
		cin >> d >> c;
		res += c;
		for (ll b = 0; b < B; b++) if (c & (1LL << b)) {
			res += vs[b][d][td];
			td = to[b][d][td];
		}
	}
	cout << res << endl;
	return 0;
}


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

vector<long long> myTry(long long num, vector<long long> vec, long long target){
    vector<long long> result;
    // base case
    if(vec.size()== 3){
        if (target == num) {
            vec.push_back(num);
            return vec;
        }
        else return result;
    }
    // recursion
    long long a = num % 10;
    vec.push_back(a);
    result = myTry(num/10, vec, target-a);
    if (!result.empty()) return result;
    vec.pop_back();
    vec.push_back(-a);
    result = myTry(num/10, vec, target+a);
    return result;
}
void solve(long long ABCD){
    vector<long long> vec, result;
    result = myTry(ABCD, vec, 7);
    reverse(result.begin(), result.end());
    if (!result.empty()){
        cout << result[0];
        for (int i=1; i< result.size(); i++){
            if (result[i] >= 0) cout << '+' << result[i];
            else cout << '-' << abs(result[i]);
        }
        cout << "=7" << endl;
    }
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long ABCD;
    scanf("%lld",&ABCD);
    solve(ABCD);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, times;
    vector<int> v;
    while(cin >> n) v.push_back(n);
    sort(v.begin(), v.end());
    times = v[2] - v[1];
    times += (v[2] - (v[0] + times))/2;
    if((v[2] - (v[0] + (v[2] - v[1]))) % 2 == 1) times += 2;
    cout << times << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Kenji
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            if (s.indexOf("a") != -1
                    && s.indexOf("b") != -1
                    && s.indexOf("c") != -1) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }
}



Measured memory_bytes: 23124
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
string s;
int n;
ll counted(char a,char b,char c){
    ll ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]==b){
            int numr=0,numb=0,nump=0;
            for(int k=0;k<i;k++) 
            {
                if(s[k]==a) numr++;
                if(s[k]==a&&s[2*i-k]==c) nump++;
            }
            for(int k=i+1;k<n;k++) 
            {
                if(s[k]==c) numb++;
            }
            ans+=numr*numb-nump;
        }
    }
    return ans;
}

int main() {
    ll ans=0;
    cin>>n;
    cin>>s;
    ans+=counted('R','G','B');
    ans+=counted('R','B','G');
    ans+=counted('G','R','B');
    ans+=counted('G','B','R');
    ans+=counted('B','G','R');
    ans+=counted('B','R','G');
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace ABC
{
  public class Program
  {
    public static void Main(string[] args)
    {
      Console.SetOut(new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false});
      var sets = Console.ReadLine().Split().Select(int.Parse).Distinct().ToArray();
      Console.WriteLine(sets.Length);
      Console.Out.Flush();
    }
  }
}

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

using namespace std;
int main(){
    int a,b,x,y;
    cin>>a>>b;
    x=a+b;
    y=x-24;
    if(x>=24){
        cout<<y<<endl;
    }
    else{
        cout<<x<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main() {
   int m; char S[19];
   for (m=1;m<=19;m++){
   	cin>>S[m];}
 		S[6]=' ' ; S[14]=' ';
 		
   
   for (m=1;m<=19;m++){cout<<S[m];}
	return 0;
}

Measured memory_bytes: 256
K,A,B = [int(_) for _ in input().split()]
N = 1
Y = 0

if A+2 >= B:
    print(N+K)
else:
    n = K+1-(A+2)
    m = n//2
    if n%2 == 0:
        N = B + (B-A) * m
    else:
        N = B + (B-A) * m + 1
    print(N)

Measured memory_bytes: 3060
k=int(input())
from collections import deque
d=deque()
for i in range(1,10):d.append(i)
for i in range(k-1):
  m=d.popleft()
  if m%10!=0:d.append(10*m+m%10-1)
  d.append(10*m+m%10)
  if m%10!=9:d.append(10*m+m%10+1)
print(d.popleft())

Measured memory_bytes: 11908
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N, K;
   cin >> N >> K;
   int l[N];
   for (int i = 0; i < N; i++) cin >> l[i];
   sort(l, l + N);
   reverse(l, l + N);
   int ans = 0;
   for (int i = 0; i < K; i++) ans += l[i];
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    int mod=1000000007;
    int a,b,c;
    int l[10],v[2];
    while (scanf("%d,",&l[0])!=EOF) {
        int tmp=l[0];
        for (int i=1;i<10;++i){
            scanf("%d,",&l[i]);
            tmp+=l[i];
        }
        scanf("%d,%d",&v[0],&v[1]);
        double chk=1.0*tmp*(v[0]*1.0/(v[0]+v[1]));
        if (chk-floor(chk)>1e-10) chk=chk+1.0;
        chk=floor(chk);
        int cnt=int(chk);
        int t=0;
        for (int i=0;i<10;i++) {
            t+=l[i];
            if (t>=cnt) {
                printf("%d\n",i+1);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
#include<cctype>
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;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  string s, t; cin >> s >> t;
  int n = s.size();
  map<char,char> a,b;
  bool check = true;
  rep(i,n){
    if (a.count(s[i]) && a[s[i]]!=t[i]) check = false;
    else if (b.count(t[i]) && b[t[i]]!=s[i]) check = false;

    a[s[i]] = t[i];
    b[t[i]] = s[i];
  }
  cout << (check ? "Yes" : "No") << endl;

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3924
import sys
sys.setrecursionlimit(1000000)
s=sys.stdin.readlines()
n,q=map(int,s[0].split())
G=[[]*n for i in range(n)]
P=[0]*n
V=[0]*n
for e in s[1:n]:
    a,b=map(int,e.split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
for e in s[n:]:
    c,d=map(int,e.split())
    P[c-1]+=d
def dsf(i,p):
    V[i]=1
    P[i]+=p
    for j in G[i]:
        if V[j]!=1:
            dsf(j,P[i])
dsf(0,0)
print(' '.join(map(str,P)))

Measured memory_bytes: 263668
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

string s;
int a[2000000];
int n;
int ans[2000000];
map<int, int> F;

int main()
{
    //freopen("in.txt", "r", stdin);
    
    cin >> s;
    F[0] = 0;
    FOR (i,0,s.size())
    {
        if (!i) a[i] = 0;
        else a[i] = a[i-1];
        a[i] ^= (1<<(s[i]-'a'));
        //cout << a[i] << endl;
    }
    FOR (i,0,s.size())
    {
        int v = a[i];
            ans[i] = (int)s.size()+100;
            if (F.count(v)) ans[i] = F[v]+1;
            FOR (r,0,'z'-'a'+1)
            {
                int y = v^(1<<r);
                if (F.count(y)) ans[i] = min(ans[i],F[y]+1);
            }
            if (!F.count(v) || F[v] > ans[i])
                F[v] = ans[i];
        //cout << F.count(0)<<" "<<F[0]<<" "<<ans[i]<<endl;
    }
    cout << ans[s.size()-1];
}




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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 2010;
const ll mod = 924844033;
ll d[N][N][2];
ll m[2 * N][N];
ll fact[N];

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	int n, k;
	cin >> n >> k;
	memset(d, 0, sizeof(d));
	d[0][0][0] = 1ll;
	forn(i, n) {
		forn(j, i + 1) {
			(d[i + 1][j + 1][1] += d[i][j][0]) %= mod;
			(d[i + 1][j][0] += d[i][j][0] + d[i][j][1]) %= mod;
		}	
	}
	forn(i, n + 1)
		forn(j, i + 1)
			(d[i][j][0] += d[i][j][1]) %= mod;
	memset(m, 0, sizeof(m));
	m[0][0] = 1ll;
	int maxx = 0, kol0 = 0, kol1 = 0;
	forn(i, k) {
		int len = -1;
		for (int j = i; j < n; j += k) {
			len++;
		}
		if (len < maxx) {
			kol1++;
		} else {
			kol0++;
		}
		umx(maxx, len);
	}
	kol0 *= 2, kol1 *= 2;
	forn(i, 2 * k) {
		forn(j, n + 1) {
			forn(p, maxx + 1) {
				(m[i + 1][j + p] += 1ll * m[i][j] * d[((i < kol0)?(maxx):(maxx - 1))][p][0]) %= mod; 	
			}
		}
	}
	fact[0] = 1ll;
	forn(i, 1, n + 1) {
		(fact[i] = fact[i - 1] * i) %= mod;
	}
	ll ans = 0;
	forn(i, n + 1) {
		if (i & 1)
			(ans += mod - m[kol0 + kol1][i] * fact[n - i] % mod) %= mod;
		else 
			(ans += m[kol0 + kol1][i] * fact[n - i] % mod) %= mod;
	}	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 126464