akhauriyash/Code-Regression huggingface dataset:
import fractions
N,X=map(int,input().split())
listX=list(map(int,input().split()))
listX+=[X]
listX.sort()
MIN=10**9
gcd=listX[1]-listX[0]
for i in range(N):
  a=listX[i+1]-listX[i]
  gcd=fractions.gcd(a,gcd)
print(gcd)  

Measured memory_bytes: 16280
let scan_int () = Scanf.scanf " %d" (fun x -> x)
let scan_string () = Scanf.scanf " %s" (fun x -> x)
let print_int n = Printf.printf "%d\n" n

let modulo = 1000000007
let modmul a b = a * b mod modulo

let () =
  let n = scan_int() in
  let s = scan_string() in
  let rec loop i curr ret =
    if i = 2 * n && curr = 0 then ret
    else if i = 2 * n || curr < 0 then 0 
    else
      if s.[i] = 'B' then
        if curr mod 2 = 1 then loop (i+1) (curr-1) (modmul ret curr)
        else loop (i+1) (curr+1) ret
      else
        if curr mod 2 = 1 then loop (i+1) (curr+1) ret
        else loop (i+1) (curr-1) (modmul ret curr) in
  let rec calc_factorial i n ret =
    if i > n then ret else calc_factorial (i+1) n (modmul ret i) in
  let a = loop 0 0 1 and b = calc_factorial 1 n 1 in
  print_int (modmul a b)



Measured memory_bytes: 3200
#include<stdio.h>

int main(void)
{
	int x;

	scanf("%d", &x);

	int h, m, s;

	h = x / 3600;
	m = (x - h*3600) / 60;
	s = x - h*3600 - m*60;

	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}

Measured memory_bytes: 592
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N,K;
    N = sc.nextLong();
    K = sc.nextLong();
    long a,b;
    a = N / K;
    long ans;
    ans = a * a * a;
    if(K % 2L == 0L){
      b = (N + K/2L) / K;
      ans += b * b * b;
    }
    System.out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main(){
	string s;
	int tmp;
	while(getline(cin, s)) {
		if(s == "0") break;
		stringstream ss(s);
		vector<int> v;
		while(!ss.eof()) {
			ss >> tmp;
			v.push_back(tmp);
		}
		int ret = 0, cnt = 0;
		bool f = 0;
		rep(i, v.size()) {
			if(v[i] > 10) ret += 10;
			else if(v[i] == 1) cnt++; 
			else ret += v[i];
		}
		ret += cnt;
		while(cnt-- && ret < 12) {
			ret += 10;
		}
		if(ret >= 22) f = 1;
		if(f) cout << 0 << endl;
		else cout << ret << endl;
	}
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int i, count = 0;
  for(i = 0; i < s.size(); i++){
    if(s.at(i) == 'x'){
      count++;
    }
  }
  
  if(count >= 8){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int c = sc.nextInt();
		int res = 0;
		int[] b = new int[m];
		for(int i = 0; i < m; i++){
			b[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++){
			int tmp = c;
			for (int j = 0; j < m; j++){
				tmp += sc.nextInt() * b[j];
			}
			if(tmp > 0){
				res ++;
			}
		}
		System.out.println(res);
 	}
}




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


int main(void){
    long n,i,a=1;
    scanf("%ld",&n);
    char s[100000];
    scanf("%s",s);
    // printf("%s",s);
    for(i=1;i<n;i++){
        if(s[i]!=s[i-1]) a++;
    }   


    printf("%ld\n",a);
    return 0;
}



Measured memory_bytes: 256
const main = (k,x) => {
    var r = []
    for(var i = x;i<x+k;i++) {
        r.push(i)
    }

    for(var i = x;i>x-k;i--) {
        r.push(i)
    }
    
    return r.filter( (elem,index,self) => {
        return self.indexOf(elem) === index

    })
}

const input = require('fs').readFileSync('/dev/stdin','utf8').split('\n')[0].split(" ")
const kx = input.map(x => parseInt(x,10))
console.log(main(kx[0],kx[1]).sort((a,b) => a - b).join(" "))


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

using namespace std;
struct pp
{
    int b;
    int c;
}d[100005];
bool comp(pp a,pp b)
{
    return a.c<b.c;
}
int main()
{
    int n,a[100005];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        d[i].b=i;
        d[i].c=a[i];
    }
    sort(d,d+n,comp);
    for(int i=0;i<n;i++)
    {
       cout<<d[i].b+1<<" ";
    }
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const double PI = 3.1415926535897932;

int main() {
  int n,m;
  cin >> n >> m;
  int food[40] = {};
  for(int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int a;
      cin >> a;
      food[a] += 1;
    }
  }
  int count = 0;
  for(int i = 0; i <= m; i++) {
    if(food[i] == n) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let s: String = read();
    let s: Vec<u8> = s.into_bytes();
    let (a, b) = find(s);
    println!("{} {}", a, b);
}

fn find(s: Vec<u8>) -> (i32, i32) {
    let n = s.len();
    for i in 0..n {
        let ii = i as i32;
        if i+1 < n && s[i] == s[i+1] {
            return (ii+1 as i32, ii+2 as i32);
        }

        if i+2 < n && (s[i] == s[i+2] || s[i] == s[i+1] || s[i+1] == s[i+2]) {
            return (ii+1 as i32, ii+3 as i32);
        }
    }

    (-1, -1)
}

Measured memory_bytes: 4352
import java.util.Scanner;

class Main{
	public static void main(String[] main) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next();
		boolean isA=false;

		char[] mjs=new char[a.length()];
		for(int i=0; i<a.length(); i++) {
			mjs[i]=a.charAt(i);
		}


		if(mjs[0]=='A') {
			isA=true;
			mjs[0]='a';
		}
		else {
			isA=false;
			mjs[0]='a';
		}


		int C_cnt=0;
		for(int i=2 ;i<=a.length()-2; i++) {
			if(mjs[i]=='C') {
				C_cnt++;
				mjs[i]='c';
			}
		}

		boolean caps=true;

		for(int i=0; i<a.length(); i++) {
			if((mjs[i]+"").equals((mjs[i]+"").toLowerCase())) {
				//
			}
			else {
				caps=false;
			}
		}

		if(C_cnt==1 && caps==true && isA==true) {
			System.out.println("AC");
		}
		else {
			System.out.println("WA");
		}
	}
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  int n;
  cin >> n >> s;
  
  long long r=0, g=0, b=0;
  rep(i, 0, n) {
    if(s[i]=='R') r++;
    if(s[i]=='G') g++;
    if(s[i]=='B') b++;
  }

  long long ans = r*g*b;
  if(ans==0) {
    cout << 0 << "\n";
    return 0;
  }
  
  rep(i, 1, n-1) {
    int r = min(n-1-i, i-0);
    rep(j, 1, r+1) {
      if(s[i-j]!=s[i] and s[i]!=s[i+j] and s[i+j]!=s[i-j]) ans--;
    }
  }
  cout << ans << "\n";  
}

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    int n;
    int tmp;
    cin >> n >> tmp;
    vector<int> x;
    x.emplace_back(tmp);
    for(int i = 0; i < n; i++) {
        cin >> tmp;
        x.emplace_back(tmp);
    }
    sort(x.begin(),x.end());
    int d[n];
    for(int i = 0; i < n; i++) {
        d[i]=x[i+1]-x[i];
    }
    int g=d[0];
    for(int i = 1; i < n; i++) {
        g=__gcd(g,d[i]);
    }
    cout << g << "\n";
    return 0;
}

Measured memory_bytes: 1144
#include <stdlib.h>
#include <stdio.h>
void merge(int *,int,int,int);
void mergesort(int *,int,int);
int cnt=0,n;
int main(){
  int a[500000],i;
  scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&a[i]);
  mergesort(a,0,n);
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1)printf(" ");
    else printf("\n");
  }
  printf("%d\n",cnt);
  return 0;
}
void mergesort(int *a,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(a,left,mid);
    mergesort(a,mid,right);
    merge(a,left,mid,right);
  }
}
void merge(int *a,int left,int mid,int right){
  int l,i,k,j,n1=mid-left,n2=right-mid;
  int *L,*R;
  L=malloc(sizeof(int)*(n1+2));
  R=malloc(sizeof(int)*(n2+2));
  for(i=0;i<n1;i++){
    L[i]=a[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=a[mid+i];
  }
  L[n1]=2147483647;
  R[n2]=2147483647;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j])a[k]=L[i++];
    else a[k]=R[j++];
  }
  free(L);
  free(R);
}



Measured memory_bytes: 5468
a,b,c=map(int,input().split())
if a>b:
    temp=a
    a=b
    b=temp
if b>c:
    temp=b
    b=c
    c=temp
if a>b:
    temp=a
    a=b
    b=temp
print(a,b,c)
1 <=a,b,c <= 10000


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

enum:char{
	WALL='#',ME='@',PANEL='w',CONTAINER='c',EMPTY='.',ESCAPE='E'
};
constexpr int di[]={-1,1,0,0},dj[]={0,0,-1,1};

string encode(const vs& grid,int i,int j)
{
	int h=grid.size(),w=grid[0].size();
	string res;
	repi(k,1,h-1) res+=grid[k].substr(1,w-2);
	res[(i-1)*(w-2)+j-1]=ME;
	return res;
}

int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		int gi=-1,gj=-1;
		deque<tuple<vs,int,int,int>> dq;
		{
			vs grid(h);
			rep(i,h) cin>>grid[i];
			rep(i,h) rep(j,w) if(grid[i][j]==ESCAPE){
				gi=i,gj=j;
				grid[i][j]=EMPTY;
			}
			rep(i,h) rep(j,w) if(grid[i][j]==ME){
				grid[i][j]=EMPTY;
				dq.emplace_back(grid,i,j,0);
			}
		}
		
		int res=-1;
		set<string> vis;
		while(dq.size()){
			vs cur; int ci,cj,ct; tie(cur,ci,cj,ct)=move(dq.front()); dq.pop_front();
			if(!vis.insert(encode(cur,ci,cj)).second) continue;
			
			if(ci==gi && cj==gj){
				res=ct;
				break;
			}
			
			rep(k,4){
				int ni=ci+di[k],nj=cj+dj[k];
				if(cur[ni][nj]==WALL || cur[ni][nj]==PANEL) continue;
				if(cur[ni][nj]==CONTAINER){
					int i=ni+di[k],j=nj+dj[k];
					for(;;i+=di[k],j+=dj[k]){
						if(cur[i][j]==EMPTY) continue;
						if(cur[i][j]==PANEL) break;
						if(cur[i][j]==WALL || cur[i][j]==CONTAINER){
							i-=di[k],j-=dj[k];
							break;
						}
					}
					if(i==ni && j==nj) continue;
					vs next=cur;
					next[ni][nj]=EMPTY;
					next[i][j]=next[i][j]==PANEL?EMPTY:CONTAINER;
					dq.emplace_front(move(next),ci,cj,ct);
				}
				else
					dq.emplace_back(cur,ni,nj,ct+1);
			}
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 9936
def resolve():
    '''
    code here
    '''
    X, Y = [int(item) for item in input().split()]

    if 0 <= (Y - 2*X) <= 2*X:
        b = (Y - 2*X) % 2
        print('Yes') if b==0 else print('No')
    else:
        print('No')


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9176
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=100005;
bool visited[N];int cnt;
int a[N];
void dfs(int u)
{
    visited[u]=1;
    if(u==2)
        return;
    cnt++;
    if(!visited[a[u]])
        dfs(a[u]);
}
void solve()
{

    int f[N];
    f[0]=1;
    for(int i=1;i<N;i++)
        f[i]=(f[i-1]*i)%hell;
    int n,m;
    cin>>n>>m;
    int mx=max(n,m),mn=min(n,m);
    if(mn<(mx-1))
    {
        cout<<0<<endl;
    }
    else
    {
        int ans=(f[n]*f[m])%hell;
        if(mn==(mx))
            ans=(ans*2)%hell;
        cout<<ans<<endl;
    }
    

}

int32_t main()
{
    IOS;
    
    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int h, a;
    cin>>h>>a;
    int ans = h/a;
    if(h%a) ans++;
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
// vim: ts=2 sw=2 sts=2
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, s = 0;
  cin >> n;

  for(int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    s += r - l + 1;
  }

  cout << s << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int a= gi();



        //System.out.print(Math.max(a*b, c*d));
        if (a<1200) {
        	System.out.print("ABC");
        }else {
        	System.out.print("ARC");
        }

	   
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35656
#include <stdio.h>
#define N 1000
int main(){
  int A[N];
  int v,b,i,j,p;
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<b-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[b-1]);
  for(i=1;i<=b-1;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(p=0;p<b-1;p++){
      printf("%d ",A[p]);
    }
    printf("%d\n",A[b-1]);
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
int main(){
ll N; cin >> N;
  vector<ll> A(N);
 for(int i = 0; i < N; i++){ cin >> A[i];}
  
  vector<ll> sum(N+1); sum[0] = 0; map<ll,ll> mp;
  mp[0]++;
  
  for(ll i = 1; i <= N; i++){
    sum[i] = sum[i-1] + A[i-1]; mp[sum[i]]++;}
  ll ans = 0;
  for(auto ne: mp){
    ll p  = ne.second;
    ans += p*(p-1) / 2;}
  
  cout << ans << endl; return 0;}

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

int main(){
  int n, m;
  cin >> n >> m;
  
  while(n != 0 && m != 0){
    vector<int> taro(n), hanako(m);
    int sumt = 0;
    int sumh = 0;
    for(int i = 0; i < n; i++){
      cin >> taro[i];
      sumt += taro[i];
    }
    for(int i = 0; i < m; i++){
      cin >> hanako[i];
      sumh += hanako[i];
    }

    sort(taro.begin(), taro.end());
    sort(hanako.begin(), hanako.end());
    
    int anst = -1;
    int ansh = -1;

    bool ok = false;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < m; j++){
        if(sumt + 2 * hanako[j] == sumh + 2 * taro[i]){
          anst = taro[i];
          ansh = hanako[j];
          ok = true;
          break;
        }
      }
      if(ok)break;
    }
    
    if(anst == -1)cout << -1 << endl;
    else cout << anst << " " << ansh << endl;
    

    cin >> n >> m;
  }      
}

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
from collections import deque

def inpl(): return tuple(map(int, input().split()))

V, E = inpl()
indeg = [0] * V
adj = {k: [] for k in range(V)}

for _ in range(E):
    s, t = inpl()
    adj[s].append(t)
    indeg[t] += 1

Q = deque([i for i, ind in enumerate(indeg) if ind == 0])
res = []

while Q:
    q = Q.popleft()
    for i in adj[q]:
        indeg[i] -= 1
        if indeg[i] == 0:
            Q.append(i)
    res.append(q)

for r in res:
    print(r)

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, a, b;
  cin >> n >> a >> b;
  vll h(n);
  rep(i, n) {
    cin >> h[i];
  }

  ll l, r;
  l = 0;
  r = mod;

  while (l < r) {
    ll c = (l + r) / 2;
    ll d = a - b;
    ll cnt = c;
    rep(i, n) {
      ll tmp = h[i] - b * c;
      if (tmp > 0) {
        cnt -= (tmp + d - 1) / d;
      }
    }
    if (cnt >= 0) {
      r = c;
    } else {
      l = c + 1;
    }
  }

  cout << l << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <time.h>
#include <math.h>
using namespace std;

int main(){
  string s, t;
  int cnt = 0;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++){
    if (!(s[i] == t[i])){
      s[i] = t[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3872
int_n = int(input())
li_t = list(map(int, input().split()))
int_m = int(input())
li_p = list()
li_x = list()

for i in range(int_m):
    p, x = map(int, input().split())
    li_p.append(p)
    li_x.append(x)


for x, p in zip(li_p, li_x):
    w_li_t = li_t[:]
    w_li_t[x-1] = p

    print(sum(w_li_t))


Measured memory_bytes: 3060
s = gets.chop
ans = -1
c = 0
(0..(s.length-1)).each{ |i|
    if ['A', 'T', 'G', 'C'].include?(s[i])
        c += 1
    else
        ans = [ans, c].max
        c = 0
    end
}
ans = [ans, c].max
puts ans

Measured memory_bytes: 3836
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>


int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);
    int n; std::cin >> n;
    long long int D; std::cin >> D; D = D * D;
    int res = 0;
    for(int i = 0; i < n; ++i){
        long long int x, y; std::cin >> x >> y;
        long long int d = x * x + y * y;
        if(d <= D) ++res;
    }
    std::cout << res << '\n';
    
    return 0;
}

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

int main(void)
{
  int a,b;
  string ans;
  cin >> a >> b;
  if(a*b %2 == 0)
  {
    ans =  "Even";
  }
  else
  {
    ans = "Odd";
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    res = 1
    for i in range(n):
        res *= i + 1
        res %= mod

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
#include<stdio.h>
int main(void){
    int x,y,t;
    
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0){
            break;
        }
if(x>y){
t=x;
x=y;
y=t;
}
        printf("%d %d\n",x,y);
            }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    int left = (100*n + 108 -1) / 108;
    int right = (100*(n+1) + 108 - 1) / 108 - 1;
    if (left == right)
    {
        cout << left << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
}


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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  
  for (int i = 0; i < 4; i++) {
    if (S.at(i) == '+') ans++;
    else if (S.at(i) == '-') ans--;
  }
  
  cout << ans << endl;
}


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

int main(void){
   string s,p;
   cin >> s >> p;
      
   string ans = "No";
   for(int i = 0; i < (int)s.length(); i++){
       bool flag=true;
       for(int j = 0; j < (int)p.length(); j++){
           if(s[(i+j)%(int)s.length()] != p[j]){
               flag = false;
               break;
           }
       }
       if(flag){
           ans = "Yes";
           break;
       }
   }
   cout << ans << endl;
}


Measured memory_bytes: 3208
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int[] path = new int[6];
    for (int i = 0; i < 6; i++) {
      path[i] = scanner.nextInt();
    }
    int[] count = new int[4];
    for (int i = 0; i < 4; i++) {
      count[i] = 0;
    }
    int odd = 0;
    for (int i = 0; i < 6; i++) {
      count[path[i] - 1]++;
    }
    for (int i = 0; i < 4; i++) {
      if (count[i] % 2 != 0)
        odd++;
    }
    String ans = odd == 0 || odd == 2 ? "YES" : "NO";
    System.out.println(ans);
  }

}


Measured memory_bytes: 21716
#include <iostream>

using namespace::std;

int main(void){
  char S[200010];

  cin >> S;

 long long n = 0;
  int b_num = 0;
  int i=0;

  while(S[i+1] == 'W' || S[i+1] == 'B'){
    if(S[i] == 'B'){
      b_num++;
      if(S[i+1] == 'W'){
        S[i+1] = 'B';
        n += b_num;
        b_num--;
      }
    }else b_num = 0;
    i++;
  }

  cout << n << endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back
#define FILE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);


using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;
const int NAX = 100001;

int main(){
    inp_out_work
    //FILE
    int n;
    cin>>n;
    ll a[n][n];
    fr(i,n)fr(j,n)cin>>a[i][j];
    int LIM = 1<<n;
    ll dp[LIM]; // maximum value we can obtain from subset i (bit-masked)
    dp[0] = 0;

    for(int mask = 1; mask < LIM; mask++){
        int bits = __builtin_popcount(mask);
        if(bits == 1)dp[mask] = 0;
        else {
            vector<int> inc;
            for(int i = 0; i < n; i++)if(mask&(1<<i))inc.pb(i);
            dp[mask] = 0;
            for(int i = 0; i < inc.size(); i++){
                for(int j = i+1; j < inc.size(); j++) dp[mask] += a[inc[i]][inc[j]];
            }

            for(int tmask = mask & (mask-1); tmask > 0; tmask = mask & (tmask-1)){
                dp[mask] = max(dp[mask], dp[tmask] + dp[mask^tmask]);
            }
        }
    }

    cout<< dp[LIM-1] << endl;

}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main()
{

   string s; cin >> s;
    long long int k,coun=1,sum=0,s1=1,s2=1,o=0; cin >> k;
    if(s.length()==1) { cout << k/2 << endl; return 0; }
    for(int i=0;i<s.length()-1;i++)
    {
        if(s[i]==s[i+1])
        {
            if(o==0) { s1++; }
            coun++;
        }
        else{
                o=1;
            sum+=coun/2;
            coun=1;
        }
    } sum+=coun/2;
    for(int j=s.length()-1;j>=0;j--)
    {
        if(s[j]==s[j-1]) s2++;
        else break;

    }
    sum*=k;
    if(coun==s.length())
    { cout << k*s.length()/2; return 0; } //sum--;
    //if(s[0]==s[s.length()-1]&&s[1]!=s[0]&&s[0]!=s[s.length()-2])
     if(s[0]==s[s.length()-1]&&s1&1&&s2&1)
     cout << sum+ k-1  << endl;
     else cout << sum  << endl;
     //cout << s1 << " " << s2 << " " << coun << endl;

    return 0;
}


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

int h,n;
int A[10101],B[101010];
ll dp[20100];

void solve()
{
	int i,j,k,l,r,x,y; 
	cin>>h>>n;
	
	for(i=0; i<20001; ++i) 
	   dp[i]=1LL<<60;
	
	dp[0]=0;
	
	for(i=0; i<n; i++)
	{
		cin>>x>>y;
		for(j=0; j<h; j++) 
		   dp[j+x]=min(dp[j+x],dp[j]+y);
	}
	
	ll mi=1LL<<60;
	
	for(i=h; i<=20000; i++)
	   mi=min(mi,dp[i]);
	
	cout<<mi<<endl;
}

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

Measured memory_bytes: 384
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 1e5;
typedef long long LL;

int sum;
int n, V;
int w[105], v[105];
int a[105];
int dp[105][105][405];
//表示前i个物品中选j个容量为k
int main()
{
	while(scanf("%d %d", &n, &V) != EOF)
	{
		sum = 0;
		memset(dp, 0, sizeof(dp));
		for(int i = 1; i <= n; i++)
		{
			scanf("%d %d", &w[i], &v[i]);
			a[i] = w[i] - w[1];
			sum = sum + a[i];
		}
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= i; j++)
			{
				for(int k = 0; k < a[i]; k++)
					dp[i][j][k] = dp[i - 1][j][k];
			}
			for(int j = 1; j <= i; j++)
			{
				for(int k = a[i]; k <= sum; k++)
					dp[i][j][k] = max(dp[i - 1][j][k], dp[i - 1][j - 1][k - a[i]] + v[i]);
			}
		}
		int ans = 0;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= i; j++) {
				if(w[1] * j > V) break;
				for(int k = 0; k <= min(sum, V - w[1] * j); k++) ans = max(ans, dp[i][j][k]);
			}
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 17664
from collections import deque
q = deque()

n = int(input())
h = list(map(int, input().split()))
for i in h:
    q.append(i)
q.append(0)

ans = 1
if sum(q) == 0:
    ans = 0
c = 0
while sum(q) != 0:
    p = q.popleft()
    if p != 0:
        q.append(p - 1)
        c = 1
    else:
        q.append(0)
        if c == 1:
            ans += 1
            c = 0
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, long long K) { cout << N - K + 1 << endl; }

int main() {
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict


N,K = map(int, input().split())
A = list(map(int, input().split()))

d = defaultdict(int)
# 先頭からiビット目に1が立っている個数を数え上げる
for a in A:
    for i in range(50):
        if a & (1 << i):
            d[i] += 1
dp = [[-1 for _ in range(2)] for _ in range(51)]
dp[0][0] = 0

# 頭からi桁
for i in range(50):


    # 先頭からi番目の位置の数字
    if K & (1 << (50-i-1)):
        digit = 1
    else:
        digit = 0

    # i桁目に1を選んだ時
    use_1 = (N-d[50-i-1]) * (1 << (50-i-1))
    # i桁目に0を選んだ時
    use_0 = d[50-i-1] * (1 << (50-i-1))

    if K < (1 << (50-i-1)):
        use_1 = 0

    """
    i-1桁までがKより小さい場合、0,1どちらも選択可能
    dp[i][1] == -1 だとそれは起こりえない
    """
    if dp[i][1] != -1:
        dp[i+1][1] =  dp[i][1] + max(use_0, use_1)

    """
    i-1桁まで同じで、i桁目でKより小さくなる場合（Kのi桁目が1で0を選択）
    """
    if dp[i][0] != -1:
        if digit == 1:
            dp[i+1][1] = max(dp[i+1][1], dp[i][0] + use_0)

    """
    i-1桁まで同じで、i桁目でKとまた一致する場合
    """
    if dp[i][0] != -1:
        if digit == 1:
            dp[i+1][0] = max(dp[i+1][0], dp[i][0] + use_1)
        else:
            dp[i+1][0] = max(dp[i+1][0], dp[i][0] + use_0)

print(max(dp[-1]))


Measured memory_bytes: 68696
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 10000;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
void solve()
{
     ll n;
     cin >> n;
     string s;
     ll open = 0,close = 0;
     vector<pll> pos,neg;
     for(ll i=0;i<n;i++)   
     {
          string s;
          cin >> s;
          stack<ll> t;
          for(ll j=0;j<s.size();j++)
          {
               if(s[j]=='(')      t.push(1);
               else
               {
                    if(t.size())  
                    {
                         ll t1 = t.top();
                         if(t1==1)   t.pop();
                         else        t.push(-1);    
                    }
                    else           t.push(-1);
               }
          } 
          vector<ll> v;
          while(t.size())     v.pb(t.top()),t.pop();
          reverse(all(v));
          ll sz = v.size();
          if(sz==0)   continue;
          else
          {
               if(v[0]==v[sz-1] && v[0]==1)     open += sz;
               else if(v[0]==v[sz-1] && v[0]==-1)   close += sz;
               else
               {
                    ll cnt = 0;
                    ll j = 0;
                    while(v[j++]==-1)    cnt++;
                    ll c = cnt,o = sz - cnt;
                    if(o>=c)    pos.pb({c,o});
                    else        neg.pb({c,o});
               }      
          }
     }
     sort(all(pos));
     sort(all(neg));
     reverse(all(neg));
     for(ll i=0;i<pos.size();i++)
     {
          if(open>=pos[i].ff)
          {
               open -= pos[i].ff;
               open += pos[i].ss;
          }
          else 
          {
               cout<<"No";
               return;
               
          }
     }     
     for(ll i=0;i<neg.size();i++)
     {
          if(open>=neg[i].ff)
          {
               open -= neg[i].ff;
               open += neg[i].ss;
          }
          else 
          {
               cout<<"No";
               return;
          }
     }
     open -= close;
     if(open==0)   cout<<"Yes\n";
     else          cout<<"No\n";
}

int main()
{
     FAST;
     ll t = 1;
  //   cin >> t;
     while(t--)
     {
          solve();
     }
}

Measured memory_bytes: 7356
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
const int MOD=998244353;
int n,s,ans;
int a[3010];
int dp[4010];
int main(){
	cin>>n>>s;
	for(int i=1;i<=n;i++){
		cin>>a[i];
        for(int j=s-a[i];j>0;j--)
			dp[j+a[i]]=(dp[j+a[i]]+dp[j])%MOD;
		dp[a[i]]=(dp[a[i]]+i)%MOD;
		ans=(ans+dp[s])%MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
S=io.read()
a=tonumber(string.sub(S,1,4))
b=tonumber(string.sub(S,6,7))
c=tonumber(string.sub(S,9,10))

if a<=2019 and b<=4 and c<=30 then
  print("Heisei")
else 
  print("TBD")
end


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 200005
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

int a[N], last[N], ne[N], s[N << 1], f[N], to[N];
int main(){
    int ca=0,k,i,j,K = 0, m, n;
    ll L;
    scanf("%d%lld", &n, &L);
    memset(last, -1, sizeof(last));
    memset(ne, -1, sizeof(ne));
    rep(i, 0, n){
        scanf("%d", &a[i]);
        if(last[a[i]] != -1){
            k = last[a[i]];
            ne[k] = i;
        }
        else f[a[i]] = i;
        last[a[i]] = i;
    }
    to[n] = n;
    per(i, 0, n){
        if(ne[i] == -1)to[i] = i;
        else to[i] = to[ne[i]+1];
    }
    int x = 0;
    while(x < n){
        if(ne[x] == -1)break;
        x = to[x];
    }
    if(x >= n){
        return 0;
    }
    int sz = 0;
    int cnt = 1;
    rep(it, 1, n * 2){
        //cerr << x << " " << a[x] << "\n";
        s[sz++] = x;
        k = a[x];
        x = f[k] + 1;
        if(x >= n){
            cnt = it + 1;break;
        }
        if(ne[x] != -1)x = to[x];
        if(x >= n){
            cnt = it + 1;break;
        }
    }
    //DBG(sz)DBG(cnt)
    L--;
    L %= cnt;
    vi ans;
    if(L == 0){
        x = 0;
    }
    else{
        x = s[L-1];
        x = f[a[x]] + 1;
    }
    while(x < n){
        if(ne[x] == -1)ans.pb(x), x++;
        x = to[x];
    }
    for(auto &x : ans)printf("%d ", a[x]);puts("");
}


Measured memory_bytes: 7924
N = int(input())
NameList = []
CharCnt = [0] * 5
CharList = ["M","A","R","C","H"]
for _ in range(N):
    S = input()
    for i in range(5):
        if S[0] == CharList[i]:
            CharCnt[i] += 1
ans = 0
#print(CharCnt)
for i in range(3):
    for j in range(i + 1, 4):
        for k in range(j + 1, 5):
            tmp_ans = CharCnt[i] * CharCnt[j] * CharCnt[k]
            if tmp_ans != 0:
                ans += tmp_ans
if sum(CharCnt) < 3:
    print("0")
else:
    print(ans)

Measured memory_bytes: 3064
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

N,K = map(int,input().split())

P = tuple(map(lambda x: int(x)-1,input().split()))
C = tuple(map(int,input().split()))

acc = [0]*N
visited = [-1]*N
last = [0]*N

res = -10**9

for p in range(N):
    c = 0
    v = p
    for j in range(min2(N+1,K)):
        if visited[v] == p:
            break
        visited[v] = p
        acc[v] = c
        last[v] = j
        c += C[v]
        v = P[v]
        res = max2(c,res)
    else:
        continue

    i = last[v]

    delta = c - acc[v]
    remaining = K - i
    cycle = j-i
    if delta > 0 and remaining >= cycle:
        cnt = remaining//cycle - 1
        c = acc[v]+cnt*delta
        remaining -= cnt*cycle
        for _ in range(remaining):
            c += C[v]
            res = max2(res, c)
            v = P[v]

print(res)

Measured memory_bytes: 69144
//#include "stdc++.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0) return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p; }
#define flush fflush(stdout)
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
#define int long long
int dp[3005][3005];
int32_t main()
{
    IOS;//ifstream fin("input.txt");ofstream fout("output.txt");/*
    int n;
    cin>>n;
    string s;
    cin>>s;
    dp[0][0]=1;
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(s[i-1]=='<')
            {
                if(j>0)
                {
                    dp[i][j]=dp[i-1][j-1];
                }
                    
            }
            else
            {
                dp[i][j]=(dp[i-1][i-1]%MOD-(j>=1?dp[i-1][j-1]:0)+MOD)%MOD;
            }
        }
        for(int j=1;j<=i;j++)
            dp[i][j]=(dp[i][j]%MOD+dp[i][j-1]%MOD)%MOD;
    }
    cout<<dp[n-1][n-1]<<endl;
    return 0;
}



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

int main(){
  int x1,y1,x2,y2,x3,y3,x4,y4;
  cin>>x1>>y1>>x2>>y2;
  x3=x2+y1-y2;
  y3=y2+x2-x1;
  x4=x3+x1-x2;
  y4=y3+y1-y2;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
}

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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var t = int.Parse(_[1]);

            var ary = new Tuple<int,int>[n];
            for(var i = 0; i < n; i++){
                var __ = Console.ReadLine().Split();
                var ci = int.Parse(__[0]);
                var ti = int.Parse(__[1]);
                ary[i] = Tuple.Create(ci,ti);
            }
            var minv = ary.Where(x => x.Item2 <= t);

            if(minv.Any()){
                var m = minv.OrderBy(x => x.Item1).First();
                Console.WriteLine(m.Item1);
            }else{
                Console.WriteLine("TLE");
            }
        }
    }
}


Measured memory_bytes: 13524
import sys


def divisor_gen(n):
    ret = set()
    for i in range(1, int(n ** (1 / 2) + 1)):
        if n % i == 0:
            ret.add(i)
            ret.add(int(n/i))
    return sorted(list(ret), reverse=True)


# print(divisor_gen(1000))


N, M = [int(x) for x in input().split()]

for d in divisor_gen(M):
    if N <= (M / d):
        print(d)
        sys.exit(0)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define sf1(x)      scanf("%d",&x)
#define pf1(x)      printf("%d\n",x)
#define pf1s(x)     printf("%d ",x)
#define FOR(i,x)    for(int i=0;i<x;i++)
using namespace std;
int main()
{
    int n;
    while(sf1(n)==1){
       int a[n];
       FOR(i,n)  sf1(a[i]);
       int cnt=0;
       FOR(i,n-1){
          for(int j=n-1; j>=i+1; j--){
               if(a[j]<a[j-1]) {
                swap(a[j],a[j-1]);
               cnt++;}
          }
      }
      FOR(i,n-1)  pf1s(a[i]);
      pf1(a[n-1]);
      pf1(cnt);
    }
    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s; int n=s.size();
	int ans=0, l=0, r=n-1;
	while(l<r){
		if(s[l]==s[r]) l++,r--;
		else if(s[l]!='x'&&s[r]=='x') ans++,r--;
		else if(s[r]!='x'&&s[l]=='x') ans++,l++;
		else ans=-1, l=n+1;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int x;
  cin >> x;
  
  int th = x / 1000;
  int hu = x % 1000 / 100;
  int te = x % 100 / 10;
  int on = x % 10;

  if ((th == hu && hu == te) || (hu == te && te == on)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a%3==0)
        printf("Possible");
    else if(b%3==0)
        printf("Possible");
    else if((a+b)%3==0)
        printf("Possible");
    else
        printf("Impossible");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 	int main(){
 		int S,h,m,s,f;
 		cin >> S;
 		h= S/3600;
 		f= S-(h*3600);
 		m= f/60;
 		s=f-(m*60);
 		cout << h << ":" << m << ":" << s << endl;
 	}

Measured memory_bytes: 1164
#include <stdio.h>
#define MAX_H 101
#define MAX_W 101
int main(void){
  int height,width;
  int local_flag;
  int flag_h[MAX_H] = {0};//skip print if 0
  int flag_w[MAX_W] = {0};//skip print if 0
  char matrix[MAX_H][MAX_W] = {0};
  scanf("%d%d",&height,&width);
  for (int i=0;i<height;i++){
    scanf(" %s",matrix[i]);
  }
  //search for height
  for (int i=0;i<height;i++){
    local_flag = 0;
    for (int j=0;j<width;j++){
      if (matrix[i][j] == '#'){
        local_flag = 1;
        break;
      }
    }
    if (local_flag == 1){
      flag_h[i] = 1;
    }
  }
  //search for width
  for (int i=0;i<width;i++){
    local_flag = 0;
    for (int j=0;j<height;j++){
      if (matrix[j][i] == '#'){
        local_flag = 1;
        break;
      }
    }
    if (local_flag == 1){
      flag_w[i] = 1;
    }
  }
  //print
  for (int i=0;i<height;i++){
    if (flag_h[i] == 1){
      for (int j=0;j<width;j++){
        if (flag_w[j] == 1){
          printf("%c",matrix[i][j]);
        }
      }
      printf("\n");
    }
  }
  return 0;
}


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

double max( double a, double b )
{
    if( a > b )
        return a;
    else
        return b;
}

int main()
{
    int n;
    double a, b;
    string s;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> s;
        a = ( s[0] - '0' ) * 10 + ( s[1] - '0' );
        b = ( s[3] - '0' ) * 10 + ( s[4] - '0' );
        a = a * 30 + b * 0.5;
        b *= 6;
        double diff = max( a - b, b - a );
        
         if( diff > 180 )
             diff = 360 - diff;

        if( 0 <= diff && diff < 30 )
            cout << "alert" << endl;
        else if( 90 <= diff && diff <= 180 )
            cout << "safe" << endl;
        else
            cout << "warning" << endl;
    }

    return 0;
}


Measured memory_bytes: 3208